How to automatically delete past workshop dates in product variants?

mikeschwede
Shopify Partner
13 0 6

Hi,

besides coffee we are selling barista workshops. Every workshop (like barista basic workshop) is a product (product type "workshop"). The product has different variants based on the workshop dates like 1. January 2024 08:30, 13. January 14:30 etc. each variant has a custom meta date field too.

 

I'm trying to create a flow which checks every night the all products with product_type: workshop and delete those variants which are <= today date (or the date of the schedule) so people cannot buy workshops which have already passed. 

 

I think the action of "Get product variant data" should help here, but I'm unsure about the query. Something like product_type:"Kurs" AND product_title starts with {{scheduledAt}} or something 🙂
Any ideas?

Replies 9 (9)

paul_n
Shopify Staff
1011 133 242

Definitely do not make up the syntax for the query...it will likely return all results on failure (because the API works that way).  To test if something works, I heartily recommend using the free app GraphiQL (to test queries), as documented here: https://help.shopify.com/en/manual/shopify-flow/reference/data

 

The filters available in the query are here: https://shopify.dev/docs/api/admin-graphql/2023-07/objects/QueryRoot#connection-queryroot-productvar....

 

You guessed "product_type" correctly but it's just "title". 

 

The hard part of this is the date...because it's just a string. I think you could run this every day and delete yesterday's variants pretty easily. Something like

title:{{ scheduledAt | date_minus: "1 day" | date: "%e. %B %Y" }}*

That date format needs to exactly match the beginning of your titles.

 

You could then build a workflow to handle all the existing variants. Something like:

  • Product added to store
  • For each variant
    • If variant includes that date
    • Delete variant

You could run this workflow manually in the Admin by bulk selecting products

 

 

 

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.
mikeschwede
Shopify Partner
13 0 6

thanks, but didn't work. So I made a flow:

get all product data from lessons, then check if the metafield = today for each item 

Bildschirmfoto 2023-12-01 um 12.48.13.png

but it always says the argument is false:

Bildschirmfoto 2023-12-01 um 13.00.21.png

 

I'm sending me an email where I check the same argument - if today == the metafield value

Bildschirmfoto 2023-12-01 um 12.49.36.png

when I receive the email, it looks like this: and in the first email it says that it's the same but it doesn't trigger my mail I'm sending when my flow argument is true. 

Bildschirmfoto 2023-12-01 um 12.51.37.png

so the problem must be in the checkif. I tried equals to, is at least one etc. 

Bildschirmfoto 2023-12-01 um 13.03.46.png

but it seems not to work. Any ideas?

paul_n
Shopify Staff
1011 133 242

You cannot use liquid in conditions. 

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.
mikeschwede
Shopify Partner
13 0 6

OMG, ok. I think flows would be much better if you just could code stuff. Haha. 
Hum, and I assume metafield values cannot be accessed in the get product variant data query, right?

paul_n
Shopify Staff
1011 133 242

You can't query by them yet, but you can use the values to construct your query, if that makes sense (for one of the available query filters). 

 

We are working on the ability to use code in more places, but timing on when we can release is still TBD. Keep an eye on the change log. 

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.
mikeschwede
Shopify Partner
13 0 6

Will try this. btw: the documentation of the query paramaters and syntex isn't really clear. Glad there are third party documentation which are clearer and simpler.

paul_n
Shopify Staff
1011 133 242

Which 3p docs are you using?

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.
mikeschwede
Shopify Partner
13 0 6

I'm referring to https://shopify.dev/docs/api/usage/search-syntax

 

Trying to get a product variant data without the if afterwards by using this query via sku:
sku:Kurs-BaristaBasis-{{ "today" | date: "%Y%m%d" }}*
the skus have this format Kurs-BaristaBasis-20231201-1730

but it doesn't work

paul_n
Shopify Staff
1011 133 242

We point there because the filters can change over time. 

 

FYI, "today" is not a variable in liquid. Try "now" instead.

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.