Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Dear Shopify members,
I have a question on setting up a flow to add specific packaging item on four of my main products. Each main product has separate packaging item as well.
Below is the logic i use to set up the flow.
If customer buy Product A -> Add Packaging A
If customer buy Product B -> Add Packaging B
If customer buy Product C -> Add Packaging C
If customer buy Product D -> Add Packaging D
We can easily set up the flow for above using 4 IF conditions.
But my question is if a customer buys more than 1 quantity of a product, how can i configure the quantity field in the "add order line item" to add corresponding quantity of packaging item.
Suppose, if custome buys 3pcs of Product A and 2pcs of Product B, the flow has to add 3pcs of Packaging A and 2pcs of Packaging B.
How is this possible ? Any Idea anyone ?
Solved! Go to the solution
This is an accepted solution.
That is checking all lineItems on the order for each lineltem. You need to check the current lineitem only in that condition. When you add a condition do not select order first and instead look for the variable that has line item in the title.
Here's what it looks like:
This is an accepted solution.
Hi, i have been strugeling with this issue also and i could not manage to use your solution. But now with "write Code" it was very easy
This was the setup
Then by addin "run Code" i could take the quantity of the spesific SKU as a variable in the "add order line"
input
{
order {
lineItems {
sku
quantity
}
}
}
Output
type Output {
totalQuantity: Int!
}
Write code
export default function main(input) {
let totalQuantity = 0;
input.order.lineItems.forEach(item => {
if (item.sku === '90009') {
totalQuantity += item.quantity;
}
});
return {
totalQuantity: totalQuantity,
};
}
And here is the add order line
Worked like a charm
It might be easier to use a For Each loop on the `order / lineItems` so that each "Add order line item" is working with a single lineItem. Something like:
You could them write some liquid that would add the current quantity to that quantity field. Something like:
{{lineItemsForeachitem.currentQuantity}}
Hi @paul_n
Thankyou for your reply. I used this logic to update the flows.
Its working partially but has issues.
The packaging item is getting added for every line item in the order (since we have a for loop). I wanted to have the packaging item added only for the eligible items, not for every item in the order.
To make it clear, we have only 4 products that have corresponding packaging items, out of the total of say 50 items in our inventory.
Would you be able to help ? Thanks in advance
If you have a condition in there to check the SKU that should make it so the action is only called for some line items. If it's being called for all of them, your condition is likely not designed correctly. I'd need to see the detail instead of the overview.
This is an accepted solution.
That is checking all lineItems on the order for each lineltem. You need to check the current lineitem only in that condition. When you add a condition do not select order first and instead look for the variable that has line item in the title.
Here's what it looks like:
This is an accepted solution.
Hi, i have been strugeling with this issue also and i could not manage to use your solution. But now with "write Code" it was very easy
This was the setup
Then by addin "run Code" i could take the quantity of the spesific SKU as a variable in the "add order line"
input
{
order {
lineItems {
sku
quantity
}
}
}
Output
type Output {
totalQuantity: Int!
}
Write code
export default function main(input) {
let totalQuantity = 0;
input.order.lineItems.forEach(item => {
if (item.sku === '90009') {
totalQuantity += item.quantity;
}
});
return {
totalQuantity: totalQuantity,
};
}
And here is the add order line
Worked like a charm
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