I’m trying to use Shopify Flow to populate inventory directly to a Variant Metafield but only display a specific Shopify location’s inventory and not the total. For reference, the Shopify location name is “Ecommerce”. I’ve already setup part of the flow which uses the following steps:
Start when = Inventory Quantity Changed
Check if = Name is equal to Ecommerce
Do this = Update product variant metafield
The issue I’m having is I’m not sure how to to populate the value field as the Ecommerce location product variant inventory quantity. The closest I’ve been able to get is using {{productVariant.inventoryQuantity}}, but that it just providing me with the total on hand quantity and not the Ecommerce location on hand quantity.
We are attempting to do this so that we can then provide the Storefront API with this locations specific invento
I tried using your formula and enter the location name, which is “Ecommerce”, but receiving an error message. First, here is the updated formula I used:
{% for inv in productVariant.inventoryItem.inventoryLevels %}
{% if inv.location.name == “Ecommerce” %}{{ inv.available }}{% endif %}
{% endfor %}
Both the flow value and variant metafield that I want to populate the value to are setup as Integer value.
The error message I’m receiving from Shopify Flow says:
Got error updating metafield: “Value must be an integer.” For value: " 192 "
Not sure what the issue might be except that the populating value isn’t being represented as a numerical value. Any additional help would be appreciated.
Well you are checking for “My Location” as the name. I doubt you have a location named that. You also have newlines as Liquid inserts that. You can remove that by putting the code on one line or by using hyphens. like {{- foo -}} {%- bar -%}
-I did wrote “My location” here above but I do have the right location written in my flow.
-I did place all the code on one line. Since then, I don’t have error anymore ! And flow task get complete!
but… no information are populated into the google custom field 1…
What can be the reason?
please see attached my screenshot.
Are you sure you have the right namespace and key and it’s a product metafield? Likely you are still outputting a blank in that field. Usually I test this kind of thing with Log Output first to make sure it’s outputting what I expect.
In this case, I would add a {{ inv.location.name }} statement before the “if” to output the exact location names.
You can’t just use {{ inv.available }} there because it’s going to be the last iteration of the loop. You would need to use {% assign %} in that loop. But I wouldn’t handle this in liquid. Put a condition before the action to check if both the location name and available quantity. And then put a different metafield action in each path with simple [“Available”] assuming your metafield is a list of singe line text strings. If it’s just text, Available should work.
Thanks for your reply and sorry for my late reply.
I spent some time today to correct my script and I succeed to properly sum the variant of a product from a specific location. and if the total is more than 0 then I’m writing in my metafield that that product is available at that location
here is the final code used in the flow to update product variant metafield:
{% assign total_quantity = 0 %}
{% for variant in product.variants %}
{% for inv in variant.inventoryItem.inventoryLevels %}
{% if inv.location.name == "Billy (Brussels)" %}
{% assign available = inv.available | default: 0 %}
{% assign total_quantity = total_quantity | plus: available %}
{% endif %}
{% endfor %}
{% endfor %}
{% if total_quantity > 0 %}
["Available"]
{% else %}
["Not available"]
{% endif %}