woocommerce / google-listings-and-ads

Sync your store with Google to list products for free, run paid ads, and track performance straight from your store dashboard.
https://woo.com/products/google-listings-and-ads/
GNU General Public License v3.0
44 stars 21 forks source link

Fix issue with inconsistent metadata format #2437

Closed jorgemd24 closed 2 months ago

jorgemd24 commented 2 months ago

Changes proposed in this Pull Request:

Part of #2146

When filtering the private metadata, we use the unset function to remove the private metadata from the response. However, this alters the final response format, changing it from an array of objects to a single object. For example:

Incorrect:

"meta_data": {
            "1": {
                "id": 241,
                "key": "_wc_gla_visibility",
                "value": "sync-and-show"
            },
}

Correct:

"meta_data": [
          {
                "id": 241,
                "key": "_wc_gla_visibility",
                "value": "sync-and-show"
            },
]

Screenshots:

Detailed test instructions:

  1. Choose one product and set the channel visibility to "Sync & Show". Add some private metadata to the product (private metadata = metadata starting with _, for example _my_private_data).
  2. Create some WC REST API credentials and do the following request GET wp-json/wc/v3/products/YOUR_PRODUCT_ID?gla_syncable=1
  3. Without checking this PR, see how the metadata format is incorrect.
  4. Checkout this PR and see the expected response.

Additional details:

Changelog entry