Count quantity of specific product (SKU)

Solved

Count quantity of specific product (SKU)

Cleronhigh
Shopify Partner
6 1 1

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

Accepted Solution (1)
Cleronhigh
Shopify Partner
6 1 1

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,
};
}

View solution in original post

Replies 2 (2)

paul_n
Shopify Staff
1336 151 307

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. 

 

 

 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
Cleronhigh
Shopify Partner
6 1 1

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,
};
}