Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
On an order i want to count the ordered quantity of a specific product by SKU.
I tried doing it with Sum of order.lineitems.Quantity. however in this case, its just counting the total quantity of all products which i dont want. Is there any function that can do this ? i've looked around quite a bit but didn't find anything in the app
Solved! Go to the solution
This is an accepted solution.
thanks for the input, i managed to get the correct values using custom code that looks like this :
export default function main(input) {
let Quantity = 0;
input.order.lineItems.forEach((item) => {
if (item.sku === "XX") {
Quantity += item.quantity;
}
});
return {
Quantity: Quantity,
};
}
Summing that variable would just give you the total number products ordered.
It's not clear how you need that quantity (for a condition or in an action). But you need to check if the line item has that sku. The quantity field you found already tells you how many of that lineItem is in the order.
This is an accepted solution.
thanks for the input, i managed to get the correct values using custom code that looks like this :
export default function main(input) {
let Quantity = 0;
input.order.lineItems.forEach((item) => {
if (item.sku === "XX") {
Quantity += item.quantity;
}
});
return {
Quantity: Quantity,
};
}
Can you walk us through how can we add this using the run code feature?
Im new to this, it'll be really helpful to see some steps.
Also do we have any alternative for this issue? in case there's any new Flow feature that can easily integrate this.
This repo has a few run code examples, including the inputs and outputs: https://github.com/Shopify/flow-code-examples/tree/main/run-code-examples