Why isn't the 'For each' step adding multiple packaging items to my order?

lextui
Excursionist
25 0 7

I have a flow set up so that for each item with the corresponding title, packaging products (such as hang tags, stickers, etc.) are added to the product. It doesn't seem to work and only 1 of each packaging item is added to the order. Is there a way to fix this?

 

Screenshot 2023-04-03 at 15.08.35.png

Replies 9 (9)

Jeff-Armstrong
Shopify Staff
33 2 1

It looks like you've put the logic you want to occur on each item after the Then port of the For each step, but you actually want them after the Do this for each item port. Any steps after Then only happen AFTER all actions are performed in the For Each loop.

See the documentation for further details.

To learn more visit the Shopify Help Center or the Community Blog.

lextui
Excursionist
25 0 7

Hi @Jeff-Armstrong ! Thanks for responding. To clarify, where would I have to move the arrows for the flow to work properly?

Screenshot 2023-04-04 at 10.59.57.png

Screenshot 2023-04-04 at 11.00.04.png

Screenshot 2023-04-04 at 11.00.09.png

Jeff-Armstrong
Shopify Staff
33 2 1

It depends what you're trying to accomplish.

If you want to add a line item for each line item in the order that matches a condition, then you need to put that condition and action after the Do this for each item port.

If you only want to add a single line item to the order if any of the line items match a condition, then you'd want to do that after the Then port (since you only want to do it once at most).

To learn more visit the Shopify Help Center or the Community Blog.

oeban31
New Member
7 0 0

Hi Jeff,

 

We want to add a line item for each line item in the order that matches a condition. We tried putting the condition and action after the "do this for each item" port, but it didn't work. Instead of adding a line item for each line item that matches the condition, it added a line item for EVERY line item. 

 

Objective: For every unit of sku X on an order, add a unit of sku Y.

Test flow: 3 line items on order, 1 matched the conditions.

Desired outcome: 1 unit of sku Y added to order

Actual outcome: 3 units of sku Y added to order (1 for each line item)

Example flow below (ignore the email condition - that was just for testing purposes)

 

What are we doing wrong here?

 

oeban31_0-1689194735749.png

 

paul_n
Shopify Staff
1064 137 252

If your workflow is adding the item for all of the lineItems, I think it means your condition isn't working as you expect. Can you show an image of your condition panel so we can see the full details?

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.
oeban31
New Member
7 0 0

I figured it out - kind of. I previously had the generic lineItems value in my condition for "sku". I replaced this with "lineItemsForeachitem.sku" in order to tie it back to the "for each.." condition and it worked (see screenshot).

 

My challenge now is that the flow is adding 1 unit for every line item that meets the defined conditions. What I'm trying to do is add 1 unit for every UNIT purchased on line items that meet the conditions. In other words, if someone buys 3 units on a line item that qualifies, we want to add 3 units of  different sku to their order. Current flow would only add 1. Any suggestions?

 

Thank you for your help!

 

oeban31_0-1689257890415.png

 

paul_n
Shopify Staff
1064 137 252

I don't think that's possible with that action, because you cannot dynamically set the number of items to add. We have that in our backlog but it would take some time. The only workaround I can think of would be to use Send HTTP Request to call the API directly. 

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.
oeban31
New Member
7 0 0

Is there an app you recommend that can support this Send HTTP Request?

paul_n
Shopify Staff
1064 137 252

Flow provides that action...no app required. But you need to be able to write an API call. 

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.