Add products to collection based on Tag, Type, and metafield Gender

Solved

Add products to collection based on Tag, Type, and metafield Gender

n8churrr
Shopify Partner
12 1 5

Hello all.

 

I'm new to the Shopify Flow app and I'm struggling to build a flow to do the following:

 

If a product has a specific tag, and has a metafield for a specific gender, and has a product type or A or B, then add those products to a collection.

 

Why? We tried to build an automated collection, but with the limited conditional options, we can't use AND/OR. We'd also prefer to not have to manually build the collection either, so I've been tasked with seeing if I can build a flow for it.

 

This is how it looks:

 

n8churrr_0-1726705712835.png

 

And the query is:

 

tag:tag-testing AND {{shop.gender.value}}:Mens AND product_type:Shirt OR product_type:T-Shirt

 

Based on the testing I've done, the flow does not 'like' this part: {{shop.gender.value}}:Mens - I suspect I've built this part of the query incorrectly, and that I don't know how to ask it to be equal to Mens.

 

The above variable was created like this:

n8churrr_1-1726705416366.png

 

And the query without that segment works perfectly:

 

tag:tag-testing AND product_type:Shirt OR product_type:T-Shirt

 

Any assitance that could be provided to help me correctly match the metafield gender and having that equal a supplied term, would be greatly appreciated.

 

Kind regards,

Nathan

Accepted Solution (1)
n8churrr
Shopify Partner
12 1 5

This is an accepted solution.

UPDATE - it works! Made one small change (cicled in red) and it made ALL the difference:

 

n8churrr_0-1727043427360.png

 

Thanks for all your help 🙂

View solution in original post

Replies 10 (10)
n8churrr
Shopify Partner
12 1 5

Thanks for the suggestion. I tried it and it appears to have returned no results still.

 

n8churrr_0-1726708311362.png

 

My intial query of tag:tag-testing AND (product_type:Shirt OR product_type:T-Shirt) works though. It only fails when I add the query to check the gender metafield, leading me to believe I've built that segment wrong.

RPiii
Shopify Staff
46 8 20

If the initial query on the "Get product data"  action of tag:tag-testing AND (product_type:Shirt OR product_type:T-Shirt) works enough to filter down the list of products returned then it may be easier to continu into a "For each" loop and then iterates each through add a subsequent condition that evaluates the returned data for the desired metafield value (see example) before the "Add product to a collection" action. While less efficient, using the variable picker in the condition may be a more user-friendly approach to defining the metafield and value than having to figure out how to compose the query. You can then branch multiple conditions (and subsequent loops and actions) off the "Get product data" action for each metafield value and collection you care about.

n8churrr
Shopify Partner
12 1 5

Hello RPiii,

 

Firstly, thanks for your answer. I've tried that, and now have the following hurdle:

 

n8churrr_0-1726779511377.png

 

Ideally, I don't want to change the trigger as I want to dictate when the flow runs. As for the required for each loop, I'm unsure at where to insert that into the flow. Are you able to help me with that part?

 

Kindest regards,

Nathan

RPiii
Shopify Staff
46 8 20

The "For each" loop would go after the "Get product data" to cycle through each of the products returned. Then you can check for the metafield value and perform the desired action. As Kalen said, this approach is limited to 100 products at a time.

n8churrr
Shopify Partner
12 1 5

Further to my initial post, I've experimented with the trigger.

 

Setting the trigger to 'Product variant inventory quantity changed' gave me the option to build a different flow:

 

n8churrr_0-1726715029481.png

Naturally, this flow only runs when a qualifying product has an inventory change, whereas, I'd like to ability to schedule this, or dictate specifically when I want it to run.

 

When setting up the trigger, these are two of my options:

 

n8churrr_1-1726715982137.png

 

Selecting a Shopify trigger lets me 'check if' something from within the product, for eg:

 

n8churrr_2-1726716101574.png

 

Whereas, using the Flow trigger (as it has schedule), doesn't seem to have access to the Product options:

 

n8churrr_3-1726716157274.png

 

I could 'cheat' the system by adding a variant to a test/draft product, triggering my desired flow:

 

n8churrr_4-1726716535829.png

 

But if there is a 'best-practice' method, I'd prefer that.

 

Apologies if the above went on too much. I'm new to Flows 🙂

Kalen_Jordan
Shopify Partner
764 34 135

I don't think you want to be getting gender from the shop object. You should get it from Product > metafields - it will prompt you for the namespace and key of that metafield.

n8churrr
Shopify Partner
12 1 5

I agree, but when I start with the schedule trigger from Flow:

 

n8churrr_0-1726784694218.png

It doesn't give me access to the product data, only Shop:

 

n8churrr_1-1726784730064.png

 

I feel I'm missing something really simple here..

 

Thanks for your reply though!

Kalen_Jordan
Shopify Partner
764 34 135

Oh yeah you'd want to get product data and then loop over those. You're going to be limited to 100 at a time though.

n8churrr
Shopify Partner
12 1 5

Hi Kalen,

 

We're back form the weekend, thanks for your paitence. I tried adding the For each loop after the get product data call, and it really dosen't seem to like my metafield much:

 

n8churrr_0-1727038465846.png

 

Any ideas on how to resolve this? Once again, I appreciate all the help!

 

Cheers,

 

Nathan

n8churrr
Shopify Partner
12 1 5

This is an accepted solution.

UPDATE - it works! Made one small change (cicled in red) and it made ALL the difference:

 

n8churrr_0-1727043427360.png

 

Thanks for all your help 🙂