I need to create a condition in Flow that counts all of the items on a new order that are in a specific collection and then tags that order with a tag such as x-cups (x being the number of items in the cups collection on the order).
So if there were 7 units of items in the cups collection the order tag would be “7-cups”.
Currently the only way you can count some lineItems is to use liquid. If you want to add a “7-cups” tag, then you can add the liquid in that tag field.
Roughly you would do something like:
{% assign the_count = 0 %)
{% for li in order.lineItems %}
{% for collection in li.product.collections %}
{% if collection.title == "your title %}
{% assign the_count = the_count | plus: 1 %}
{% endif %}{% endfor %}{% endfor %}
{{ the_count }}_cups
where all 3 of these items were in the “wonderful-Varnish-Cups” collection.
it returned the tag of 3-cups but I was expecting 6-cups which is the total line quantity of bags for items in the “wonderful-Varnish-Cups” colllection. Any idea why? Below is the exact script:
{% assign the_count = 0 %}
{% for li in order.lineItems %}
{% for collection in li.product.collections %}
{% if collection.title == “wonderful-Varnish-Cups” %}