Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Custom Fields] Store Json values #3102

Merged
merged 4 commits into from
Oct 1, 2024
Merged

Conversation

hichamboushaba
Copy link
Member

@hichamboushaba hichamboushaba commented Sep 25, 2024

Closes woocommerce/woocommerce-android#12696

This PR adds logic to store the JSON custom fields, this is needed because we will allow merchants to see those values in read-only mode in the app.

Testing

  1. You'll need to perform an API request to your website to add some json values:
POST {site}/wc/v3/orders/{orderId}

{
    "meta_data": [
        {
            "key": "json_object",
            "value": {
                "Key": "Value"
            }
        },
        {
            "key": "json_array",
            "value": [
                {
                    "Key": "Value"
                }
            ]
        }
    ]
}
  1. Open the example app and sign in if needed.
  2. Tap on Woo, then select the store.
  3. Tap on Orders then select the store.
  4. Tap on "View custom fields"
  5. Confirm that the json values are shown, and not editable from the app.

Having the list as part of WCMetaData itself hints that this is the list of supported keys for all kinds, but actually it was just for orders, so moving it to `StripOrderMetaData` makes following the code easier.
@@ -7,7 +7,7 @@ import javax.inject.Inject

class StripProductMetaData @Inject internal constructor() {
operator fun invoke(metaData: List<WCMetaData>): List<WCMetaData> {
return metaData.filter { !it.isJson || SUPPORTED_KEYS.contains(it.key) }
return metaData.filter { it.isDisplayable || SUPPORTED_KEYS.contains(it.key) }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another change of this is that we are not going to cache non displayable items, this is done in both platforms to avoid taking up the phone device for unused stuff.

Comment on lines -68 to -72
val SUPPORTED_KEYS: Set<String> = buildSet {
add(SubscriptionMetadataKeys.SUBSCRIPTION_RENEWAL)
add(BundleMetadataKeys.BUNDLED_ITEM_ID)
addAll(OrderAttributionInfoKeys.ALL_KEYS)
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved these to a better location below.

Copy link
Contributor

@JorgeMucientes JorgeMucientes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job @hichamboushaba changes look good and everything worked as expected in my test:

@JorgeMucientes JorgeMucientes merged commit 373bc6d into trunk Oct 1, 2024
13 checks passed
@JorgeMucientes JorgeMucientes deleted the issue/12696-keep-json-values branch October 1, 2024 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Custom Fields] Keep JSON values
2 participants