Flow to update a product metafield with returns reasons

Flow to update a product metafield with returns reasons

davemof
Shopify Partner
4 0 0

I'm struggling to figure out a flow to do the following:

 

1.) Detect orders with a return (if true then)

2.) Loop the line items

3.) Check if a line item has a return reason (if true then)

4.) Get the product ID of the line item

5.) Append the reason as a new value in single line text (with list of values turned on) metafield on the product

 

Hope someone can point me in the right direction

Replies 6 (6)

paul_n
Shopify Staff
1482 160 346

There currently isn't a trigger for returns.

 

You could use "Get order data" and the "return_status" variable to get orders that have returns. I think the values are return_requested, in_progress, returned, so something like "return_status:returned" might work.

You would probably need to loop over the orders using the "For Each" step. 

 

Items 3-5 could be done in the value field of a metafield using Liquid. 

 

I'd encourage you to get the first part working and come back with questions once you get further.

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.
davemof
Shopify Partner
4 0 0

Hi Paul,

 

I was using the trigger "Refund created" which works fine for my usecase. 

 

What I'm initially struggling with is how to loop the line items and pass the product ID to the product metafield update action. 

 

Any help there would be much appreciated

paul_n
Shopify Staff
1482 160 346

Assuming you want just the number part of the ID and not the GID, something like: 

{% for refundLineItems_item in refund.refundLineItems %}
{{refundLineItems_item.lineItem.product.legacyResourceId}}
{% endfor %}

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.
davemof
Shopify Partner
4 0 0

Thanks for the response Paul.

 

Here is what I have so far (I'm using order created trigger for the time being so I can test the flow without having to create new returns each time).

 

Screenshot 2023-08-25 at 15.12.08.png

Where would I put that code and/or am I going about this all wrong.

 

Many thanks

 

Dave

paul_n
Shopify Staff
1482 160 346

You can't interchange those triggers because they provide different data (like the refund object I used). To do this, I think you would need to change the liquid I suggested to start with order.refunds instead of refunds

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.

RPiii
Shopify Staff
109 18 36

Fwiw, this changelog post has more information about newly released triggers, actions, and templates for working with returns in Flow.