Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hi,
We have some metafields listed on our products.
For some of those we have associated customer metafields that mirror them.
For example, against the product we may have a department metafield that includes values like:
There is a mirror metafield for customers.
So that we can have a record of the dept the customer has purchased from we would like to be able to use flow to move the product metafield value into the customer metafield.
This is what I tried:
The liquid I have used there is:
{% for mf in product.metafields %}
{% if mf.namespace == "product" and mf.key == "department" %}
{{ mf.value }}
{% endif %}
{% endfor %}
Sadly I get a load of errors that say 'product' is invalid.
Does anyone know if it is possible to move the MF value used on the product to the customer. Ideally I wouldn't have to do this with a messy workaround like taking it from tags because that would be a much, much messier flow to set up and upkeep.
Thanks
Hi Jake_mitchell,
Your loop is constructed without knowing what `product` you're operating on because this is an `Order Created` trigger. You'll need to loop through the `order.lineItems.products` to get all the products for the Order. Keep in mind, this may result in multiple products matching the metafield criteria.
Hope that helps!
Thank you @DaveMcV
I've gotten the flow working using:
{% for mf in order.lineItems.product.metafields %}
{% if mf.namespace == "product" and mf.key == "department" %}
{{ mf.value }}
{% endif %}
{% endfor %}
But when it runs I get the error message of "Got error updating metafield: "Value can't be blank." For value: " "'
Do you know why this might be? From the wording it sounds like we can't use the action to update a metafield where the value is currently blank. Is that correct?
If so, that would be a blocker to this whole thing.
Sorry to bug you @DaveMcV but do you have any further thoughts on the above?
The error message isn't that helpful (or maybe I just don't understand it)
Got it working with
{% for lineItems_item in order.lineItems %}
{% for metafields_item in lineItems_item.product.metafields %}
{% if metafields_item.namespace == "namespace" and metafields_item.key == "key" %}{{ metafields_item.value }}
{% endif %}
{% endfor %}
{% endfor %}
The thing I now want to check out is whether it is possible to set these up in such a way that for customers who come back multiple times it doesn't overwrite the metafields, but instead adds to them.
@DaveMcV is that possible?
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024