Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Currently I'm trying to create a flow where it loops through each item in an order and increments an integer field on the customer's profile:
When the Flow runs, it can see it successfully looping through each item in the order:
But the field isn't being incremented by 1 for each item as expected. If an order has 3 items in it, it will still just increment the field by 1 for the whole order.
If I make a new order, the field will be incremented by 1 each time, so I can see it's at least reading the existing value correctly.
Solved! Go to the solution
This is an accepted solution.
Ah, that changes a lot.
In this case I'd rather jump to "update metafield" straight from the trigger and loop over line items and count in the liquid code in metafield value.
If not -- adding logging and little sleep (using Wait action) inside your loop may help if the problem is with multiple consecutive metafield updates failing.
Why don't you calculate first and then update once?
Multiple consecutive MF updates are never good...
(my key does not match yours)
Update: the below seems to not be an issue:
Also your existing metafield reference seems odd, I'd use {{sum | plus: order.customer.metafields.custom.total_Items.value }} , but looks like they've added a new way or referencing metafields -- https://changelog.shopify.com/posts/shopify-flow-access-typed-metafields
Sum is a good lead (I didn't know it existed, I just started using Flow), but I also need to be able to count only products that are in a certain collection in the order.
This is an accepted solution.
Ah, that changes a lot.
In this case I'd rather jump to "update metafield" straight from the trigger and loop over line items and count in the liquid code in metafield value.
If not -- adding logging and little sleep (using Wait action) inside your loop may help if the problem is with multiple consecutive metafield updates failing.
Ditching the loop option in Flow and just doing it in liquid was the answer:
{%- assign counter = order.customer.stateMachinePurchases.value -%}
{%- for a in order.lineItems -%}
{%- for b in a.product.collections -%}
{%- if b.title == "State Machine" -%}
{%- assign counter = counter | plus: 1 -%}
{%- endif -%}
{%- endfor -%}
{%- endfor -%}
{{- counter -}}
It's all good now. Thanks Tim!
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