Product metafields are not localized in the cart transform function input

When you translate a product metafield then the metafield entry data is not received by the cart transform function in the context of the current market or language. Shopify returns always the content of the primary market. While localized content is expected.

For example in our situation we have the Netherlands as the primary market and Swiss a secondary market. For Swiss we would like to receive localized metadata to manipulate the price in a different way then for the primary market. But we only receive the metafield data of the primary market.

We tested with the following query:

query Input {
  presentmentCurrencyRate
  localization {
    language {
      isoCode
    }
    country {
      isoCode
    }
    market {
      handle
      regions {
        name
      }
    }
  }
  cart {
    lines {
      quantity
      cost {
        amountPerQuantity {
          amount
        }
      }
      merchandise {
        ... on ProductVariant {
          id
          product {
            bulk: metafield(namespace: "bulk", key: "prices") {
              value
            }
          }
        }
      }
    }
  }
}

Result for the Netherlands:

{
  "presentmentCurrencyRate": "0.94505346",
  "localization": {
    "language": {
      "isoCode": "NL"
    },
    "country": {
      "isoCode": "NL"
    },
    "market": {
      "handle": "netherlands",
      "regions": [
        {
          "name": "Netherlands"
        }
      ]
    }
  },
  "cart": {
    "lines": [
      {
        "quantity": 25,
        "cost": {
          "amountPerQuantity": {
            "amount": "35.0"
          }
        },
        "merchandise": {
          "id": "gid://shopify/ProductVariant/49623544693052",
          "product": {
            "bulk": {
              "value": "10:32,50;25:30.50;50:28;75:26"
            }
          }
        }
      }
    ]
  }
}

Result for Swiss:

{
  "presentmentCurrencyRate": "0.94505346",
  "localization": {
    "language": {
      "isoCode": "DE"
    },
    "country": {
      "isoCode": "CH"
    },
    "market": {
      "handle": "switserland",
      "regions": [
        {
          "name": "Switzerland"
        }
      ]
    }
  },
  "cart": {
    "lines": [
      {
        "quantity": 25,
        "cost": {
          "amountPerQuantity": {
            "amount": "33.0"
          }
        },
        "merchandise": {
          "id": "gid://shopify/ProductVariant/49623544693052",
          "product": {
            "bulk": {
              "value": "10:32,50;25:30.50;50:28;75:26"
            }
          }
        }
      }
    ]
  }
}

Example of the translated metafield:

Expected output in this case: Swiss translation: 10:30;25:27,50;75:24

Note the i’ve read the Localization practices for Shopify Functions documentation and be aware that the amountPerQuantity is localized and that we can use presentmentCurrencyRate . But it would be nice to have the metafield data in the context of the current market/country so we can manipulate the price, product titles or messages in a unique way for each market.

It appears that the Translate & Adapt app is not reflecting updates to the Shopify function, and the query output is only displaying the data available in the product’s metafield.

As a solution, you could structure the metafield as a JSON object containing prices for each market. The input query includes the country and language in the localization field, so by matching these values with the appropriate keys in the metafield, you can retrieve the corresponding price for the specific market. This approach would allow the app to correctly fetch the localized price for the desired output.

{
  "us-en": 19.99,
  "ca-fr": 22.99,
  "uk-en": 17.99,
  "de-de": 21.50,
  "fr-fr": 20.00
}

1 Like

@AMaL
Nice solution to use a JSON structure. We also thought about this. Only thing is that our typescript cart transform function is quick reaching the 11m instructions when adding more items to the cart. So we would like to add as little logic as possible. Probably this extra logic already means we should move to Rust.
That’s why we would like the localization work by default in Shopify Functions.

Can cart and checkout validation be used to implement checks at the cart level to detect unusually large carts? If the cart exceeds a certain threshold, the checkout process can be blocked.

Notification Display: If a large cart is detected, a notification or message can be shown on the store cart page, informing the user that their cart is too large for processing or needs adjustments. It’s just a suggestion.

1 Like

@AMaL Yes we have a cart validation function for this. The threshold at this point is 50 line items. But this merchants has a lot of big b2b orders. So we prefer not to lower this threshold. That’s why I hope Shopify will fix this in the long term.

But I agree with you that we should use for now the json/cart validation solution and/or to Rust.

Thanks for the help.

You’re welcome! I’m glad I could assist. :slightly_smiling_face: