How to Perform Multiplication in Quantity Field

Hello, I am having a hard time figuring out how to perform actions based on variable order quantities. This is what I have so far.

This is what I’m trying to do for Quantity

{%- capture qty -%} {%- assign orderQty = lineItemsForeachitem.quantity -%} {%- assign inventoryQty = orderQty | times: 10 -%} {{ inventoryQty }} {%- endcapture %}

Thanks for any assitance!

I would start by removing that action and using Log output. Put the liquid in there…it allows you to test without adding lineItems by accident to a bunch of orders.

Are you sure you want to loop here? You could add multiple line items to the order if that condition passes.

Finally, I don’t think you need “capture” or “assign” as that would not print out anything. Something like:
{{- lineItemsForeachitem.quantity | times: 10 -}}

If you need more complex math, you might want to look at “Run code”, which was just released. It makes doing math much easier in JavaScript

Is there a way I can just loop through the quantity purchased for a single item?

I am basically trying to see if they purchased a certain item. If they did I need to remove 10 products for each 1 they purchase. So if they purchase 3 of the same item I want to look 3 times and remove 3 x 10 products from inventory.

A single item is a line item. I think you should use a Run code action to do this instead. It will allow to write whatever logic you need in JavaScript. Something like:

  • Order created
  • Run code (to calculate #, and maybe how many to remove)
  • Condition (if # > some thing)
  • If true → the action(s) you want to take

There are a few examples pieces of code here that are similar:
https://github.com/Shopify/flow-code-examples/tree/main/run-code-examples

This is a little out of my depth. Is there any easier solution?

They logic you want is pretty complicated to show in a visual diagram and Flow’s built in math tools are fairly limited. I think you want a code action. It might not actually be very complicated if you can find someone who knows JavaScript.