Trying to add SKU to out of stock email flow.

Trying to add SKU to out of stock email flow.

Vriess
Tourist
4 0 2

Hey there I am trying to get shopify flow to give the sku for the out of stock item as well as the name. (if not possible, just the SKU is fine.)

Right now it gives a list of the most recently sold 100 items out of stock but only the item title.

Here is the code I am using:

 

Items out of stock:
{% for getProductData_item in getProductData %}
- {{getProductData_item.title}}{% for getProductData_item in getProductData %}
{% for collections_item in getProductData_item.collections %}
{% for products_item in collections_item.products %}
{% for variants_item in products_item.variants %}

{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}

Replies 3 (3)

paul_n
Shopify Staff
1160 143 275

I'm glad you know to ask so I'll say - DON'T RUN THAT CODE. You are repeatedly looping over up to 100 items and all collections and all variants. You will likely hit an API rate limit and it will never complete. 

 

It's a bit unclear why you are using "Get Product Data", but assuming you want a report of multiple out of stock items that might be the way. The problem though with "Product" is that each Product has multiple variants. Inventory and SKUs are at the variant level. So you could either switch to "Get Product Variant Data" or use something like:

 

{% for getProductData_item in getProductData %}
- {{getProductData_item.title}}
{% for variant_item in getProductData_item.variants %}
- {{ variant_item.sku }} - {{ variant_item.title }} - {{ variant_item.inventoryQuantity }}
{% endfor %}
{% 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.
Vriess
Tourist
4 0 2

 

The code I am using is supposed to give me only the items that have sold out in the last 24 hours every day, so we can see the most recently sold out items. Ideally we would just want things that sold out in the last day from the POS retail location but that seems like more work than we know what to do with. Your suggestion helped except it doesn't limit to what sold in the last day.  I know some of the items that it returns we haven't had in a long while. 

The Getproductdata part of the flow has this custom code but it seems to be giving out whatever has sold out in general. 
updated_at:<='{{ scheduledAt }}' AND updated_at:>'{{ scheduledAt | date_minus: "1 day" }}'
inventory_total:<=0

 

Vriess_0-1704481882478.png

 

 

paul_n
Shopify Staff
1160 143 275

The API does not have a way to get products that recently went out of stock. Updated_at doesn't work because there are many reasons for an update (like it was sold or a tag was added). 

 

What you could do is tag products that go out of stock using a separate workflow with the date. Then you can add a "tag:sold_out_01_01_24" or something like that to your query. You'll probably need to also have a process for removing those tags, like when they go back in stock.

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.