Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
I am new to Shopify Flow and am having difficulty implementing it on my own.
What I want to do is to use Shopify Flow to pick up a color name that is already registered as a tag on a product and register the corresponding color name in a metafield.
For example, if a product is available in ivory and gray, I would like to register ivory and gray in the meta field as well.
I have already created a workflow and succeeded in picking up the product tag "ivory" and registering "ivory" in the color meta field, but I don't know how to register multiple colors.
I also have a different pattern.
A new gray color is added to a product that is already registered as ivory.
If there is a way to add the gray color to the ivory color without changing the ivory color, please let us know.
I tried simply creating another workflow, but it overwrote the existing color.
I did my own search but could not find the answer successfully.
If you have found a similar post in the past, I would appreciate it if you could let me know.
Thank you in advance.
Attached is a successful workflow with a single color name.
Solved! Go to the solution
This is an accepted solution.
You cannot use the tag variable.size in Flow yet. Only variable | size works, but they you can't use it in a comparison. Try this...it also makes it a bit easier to add new colors but you need to watch out for if one color name contains another color name like blue vs indigo blue.
{%- assign mf_object = product.metafields | where: "namespace", "custom" | where: "key", "color" | first -%}
{%- assign mf_str = mf_object.value | replace: "[", "" | replace:"]","" | strip -%}
{%- if mf_str != blank %}{% assign new_list = mf_str | append: "," %}{% else %}{% assign new_list = "" %}{% endif -%}
{%- for tag_item in product.tags -%}
{%- if "ivory blue other_color_names" contains tag_item -%}
{%- capture new_list %}{{ new_list }}"{{ tag_item }}",{% endcapture -%}{%- endif -%}
{%- endfor -%}
[{{new_list | split:"," | join:","}}]
Remove the condition. Instead, write some liquid in the Update Product Metafield action to loop over tags looking for conditions and then use it to set the new value.
Something like below.
{%- assign mf_object = product.metafields | where: "namespace", "custom" | where: "key", "color" | first -%}
{%- assign mf_str = mf_object.value | replace: "[", "" | replace:"]","" | strip -%}
[{{mf_str }}
{% for tag_item in product.tags %}
{%- if tag_item == "ivory" -%}
,"ivory"
{%- elsif tag_item == "blue" -%}
,"blue"
{%- endif -%}{% endfor %}
]
Thank you very much.
I tried it immediately and it did not work well with an error.
I removed the condition and copied and pasted the code into the Value of the Update Product Metafield, but am I doing it wrong?
First image
Tag attached to the product (this is a test product)
Second image
Shopify Flow, workflow contents
Third image
Error text
Hi Nnaga,
It looks like the problem is related to having an empty array of existing metafields, which means the ",blue" and ",ivory" value will be malformed.
You may need to define the delimiter to be dynamic based on if there are existing entries and by reassigning it as you iterate through the tags by doing something like:
{%- assign mf_object = product.metafields | where: "namespace", "custom" | where: "key", "color" | first -%}
{%- assign mf_str = mf_object.value | replace: "[", "" | replace:"]","" | strip -%}
{%- assign existing_tag_array = mf_str | split: ", " -%}
{%- capture delimeter -%}
{%- if existing_tag_array.size > 0 -%},{%- endif -%}
{%- endcapture -%}
[{{mf_str }}
{% for tag_item in product.tags %}
{%- if tag_item == "ivory" -%}
{{delimeter}}"ivory"
{%- assign delimeter = "," -%}
{%- elsif tag_item == "blue" -%}
{{delimeter}}"blue"
{%- assign delimeter = "," -%}
{%- endif -%}{% endfor %}
]
Hi DaveMcV,
As you suggested, I registered the text in the meta-field in advance and then ran Paul_n's workflow and it worked!
Thank you.
I continued to try the code DaveMcV gave me, but I got "An internal error occured. Try again later."
Sorry for all the questions, but could you please tell me if I am doing something wrong?
I would like to register in Shopify Flow even if the meta field is blank, so I would like to know how to continue to do this if the field is blank.
This is an accepted solution.
You cannot use the tag variable.size in Flow yet. Only variable | size works, but they you can't use it in a comparison. Try this...it also makes it a bit easier to add new colors but you need to watch out for if one color name contains another color name like blue vs indigo blue.
{%- assign mf_object = product.metafields | where: "namespace", "custom" | where: "key", "color" | first -%}
{%- assign mf_str = mf_object.value | replace: "[", "" | replace:"]","" | strip -%}
{%- if mf_str != blank %}{% assign new_list = mf_str | append: "," %}{% else %}{% assign new_list = "" %}{% endif -%}
{%- for tag_item in product.tags -%}
{%- if "ivory blue other_color_names" contains tag_item -%}
{%- capture new_list %}{{ new_list }}"{{ tag_item }}",{% endcapture -%}{%- endif -%}
{%- endfor -%}
[{{new_list | split:"," | join:","}}]
Sorry for the delay in confirming.
I got what I wanted to do!
On a test product with several color tags, the color names for the ones with color tags are now registered in the meta field.
I now know how to write the code a little better, so I will study it myself from now on.
Thank you very much!
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024