Using shopify flow to assign parent color to variant color

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?

1 Like

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:

  1. condition configuration:

  1. Run Code configuration:

The script could be extended to handle more color options.

  1. update product variant metafield configuration:

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

1 Like

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’?

Hi @Alalani ,

Have you tried implementing the suggestion @Jenny_W shared?

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?

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

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…

Did you apply the changes to the workflow before testing?