Using shopify flow to assign parent color to variant color

Solved

Using shopify flow to assign parent color to variant color

Alalani
Tourist
6 0 1

We need to set up a one-time trigger flow on Shopify Flow. We're looking for someone to create this flow for us so that the action is automated in the store. I'm attempting to establish a workflow where whenever a new product or a product variant is added, it should verify if a color is included as a variant. If a color variant like 'Haute Red' is added, I want the metafield value 'red' to be assigned to that variant. Similarly, if a variant is added with the color 'sunshine', we want the metafield value 'yellow' to be assigned to it. All we're trying to do is assigna. main parent color value to all unique color children variant names. we started to create a flow but not sure how to feed the data to flow like to let flow know what metafield color value to assign to each variant...how can we do it?

Accepted Solutions (2)

Jenny_W
Shopify Staff
12 4 3

This is an accepted solution.

 

Hi Alalani, looks like this is possible using the Run Code action to map the parent color to the variant color names. I found that the color of a variant is under `selected options` in the api.

This would be the structure:

jennywills_1-1713472339796.png

 

1. condition configuration:

jennywills_2-1713472366766.png

2. Run Code configuration:

jennywills_3-1713472396561.png

The script could be extended to handle more color options.

 

3. update product variant metafield configuration:

jennywills_4-1713472426569.png

This would need changing to the correct namespace, key and type of metafield desired.

 

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

View solution in original post

Jenny_W
Shopify Staff
12 4 3

This is an accepted solution.

Looks like the metafield definition has "list of values" selected, which makes this a list of "single_line_text_field" instead of just "single_line_text_field". That's fine, we can fix the workflow by changing the metafield action a little.

1. select "list of single line strings" as the type

2. `["{{runCode.color}}"]` is the value

 

jennywills_1-1713886990073.png

 

 

 

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

View solution in original post

Replies 7 (7)

Jenny_W
Shopify Staff
12 4 3

This is an accepted solution.

 

Hi Alalani, looks like this is possible using the Run Code action to map the parent color to the variant color names. I found that the color of a variant is under `selected options` in the api.

This would be the structure:

jennywills_1-1713472339796.png

 

1. condition configuration:

jennywills_2-1713472366766.png

2. Run Code configuration:

jennywills_3-1713472396561.png

The script could be extended to handle more color options.

 

3. update product variant metafield configuration:

jennywills_4-1713472426569.png

This would need changing to the correct namespace, key and type of metafield desired.

 

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

Alalani
Tourist
6 0 1
Hi,
Thank you for responding. Can you briefly explain how I can achieve this workflow in the FLOW App?
Should I begin with a new trigger ‘ new product variant added’?



DaveMcV
Shopify Staff
104 31 31

Hi @Alalani,

 

Have you tried implementing the suggestion @Jenny_W shared?

DaveMcV | Flow Development 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.
Alalani
Tourist
6 0 1

Thank you for your detailed explaination. Your solution has almost worked, but im encountering metafield value error. I followed your exact steps and the flow also got a trigger when I added a new variant color, but it couldnt assign the value and gave this error 

'Got error updating metafield: "Type 'single_line_text_field' must be consistent with the definition's type: 'list.single_line_text_field'." For value: "blue", Type: single_line_text_field'

Attached some screeshots, all metafield value are set to the same 'single line text field'. Not sure what this error means... can you pls take a look?Screenshot 2024-04-22 at 3.37.04 PM.pngScreenshot 2024-04-22 at 3.37.34 PM.pngScreenshot 2024-04-22 at 3.37.47 PM.png

Jenny_W
Shopify Staff
12 4 3

This is an accepted solution.

Looks like the metafield definition has "list of values" selected, which makes this a list of "single_line_text_field" instead of just "single_line_text_field". That's fine, we can fix the workflow by changing the metafield action a little.

1. select "list of single line strings" as the type

2. `["{{runCode.color}}"]` is the value

 

jennywills_1-1713886990073.png

 

 

 

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

Alalani
Tourist
6 0 1

Hi, 

The code works perfectly fine the way you set it up and provided, it identifies the color variant values that you mentioned in the code and assigns a parent color value to it. However, when I try to add a new color variant name like for eg: I added the color 'Maroon' to the red list as you can see in the picture. It does not identify this new color in shopify and assigns it color as ' default value'. Why does the code only recognize the values you added? Do i have to add this new color 'Maroon' somewhere else also in the FLOW so it can identify in product listing and assign it color Red. Please advice....Screenshot 2024-04-23 at 12.18.58 PM.png

Jenny_W
Shopify Staff
12 4 3

Did you apply the changes to the workflow before testing?

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