Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
I've tried to update an order metafield on order created. The information I want to use for the update is stored in a custom json metafield. It contains:
{ default: { shipping_days_min: 3, shipping_days_max: 5, }, nl: { shipping_days_min: 6, shipping_days_max: 12, } }
I get access within the flow to the metafield with this code:
{%- for mf in shop.metafields -%} {%- if mf.namespace == "countries" and mf.key == "shipping_days" -%} {%- assign shipping_days = mf.value -%} {{ shipping_days }} {%- endif -%} {%- endfor -%}
mf.value / shipping_days contains:
{"default":{"shipping_days_min":3,"shipping_days_max":5},"nl":{"shipping_days_min":1,"shipping_days_max":3}}
I've tried to pull out the value for "nl":
{{ shipping_days["nl"] }}
But then I've got an error.
"shop.metafields.value.nl" is invalid. Replace this variable.
I also tried to loop over shipping_days, but it also failed.
Does anyone have any ideas?
Kind regards, Carolin
All metafields are currently treated as strings because that's how they are passed to Flow through the API. In addition, you cannot access elements in an object (even if it was an object) using that syntax in Flow:
{{ shipping_days["nl"] }}
We are currently looking at ways to make using custom data (metafields and metaobjects) way better and more intuitive in Flow. Ideally here, you wouldn't need to loop over metafields (very large) and that JSON object would be accessible in Flow in some way like what you are trying to do there.
Until then, you'll need to assume that value is a string. In this case, it's going to be really difficult to work with and I'd probably find a different approach until this is ready.
We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024The Hydrogen Visual Editor is now available to merchants in Shopify Editions | Summer '...
By JasonH Sep 2, 2024