Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
Hey there,
I am using Shopify's Flow to automate filling in a metafield for color to use this for a filter eventually.
In Flow I created the following automation:
So whenever a new product is added to the store, it should check whether the value assigned to the metafield custom_label_2 is black or beige and add that value to another metafield called filters.farbe.
This is how it looks inside that condition
And this is how it looks inside the action:
The idea is that products which are both colours, black & beige, get those two values assigned to the new metafield filters.farbe. However, so far I only got one of those values added to that metafield.
As you can see, in the action field above, the type is "list of single line strings". For the metafield filters.farbe, the settings are also correct, as you can see here:
The products that are assigned both colors are supposed to appear on both respective filter options (black & beige), if the color of that product includes those two colors.
How is it possible? Am I doing the conditions in the Flow wrong? Currently, I always add "otherwise" conditions if it is not one of those colors. Should it actually be always a new condition string straight from the initial trigger?
Thank you very much in advance.
EDIT:
Sorry, there was a little mistake. Please switch the last and second last screenshot.
Yeah the way you set up the logic there, it will only run one of those actions and not both. Probably I would combine the conditions into a single step.
Because you are setting a list, I would then write the logic in liquid to check again for those colors.
That said, managing lists is hard in liquid, so you could also use "Run code" to do that instead. A similar example is here:
https://github.com/Shopify/flow-code-examples/tree/main/run-code-examples/product-tags-to-metafields
See the index.js file for the main code.
thank you so much for your help paul! Will update you as soon as I have implemented your approach!
UPDATE:
I tried the following flow:
The code in "run code" is the following:
export default function main({product}) {
// Exisitng Values in Metafield filters.farbe
const filtersFarbeMetafieldObject = product.metafields.find((metafield) => metafield.namespace === "filters" && metafield.key === "farbe");
const filtersFarbe = filtersFarbeMetafieldObject ? JSON.parse(filtersFarbeMetafieldObject.value) : [];
const colorValues = ["schwarz", "beige", "braun", "weiß", "grau", "grün", "orange", "lila", "gelb", "blau", "rosa", "rot","bunt"]; // Die Farbwerte, die du überprüfen möchtest
// Check whether the product label contains the colors
colorValues.forEach((colorValue) => {
if (product.metafields.some((metafield) => metafield.namespace === "mm-google-shopping" && metafield.key === "custom_label_2" && metafield.value.includes(colorValue))) {
if (!filtersFarbe.includes(colorValue)) {
filtersFarbe.push(colorValue);
}
}
});
// Output of a string that can be directly transmitted to a metafield update action return { filtersFarbe: JSON.stringify(filtersFarbe) };
}
I ran the flow and got the following error message:
I don't know much about programming, which is why I can't understand what I did wrong.
From an other member of this forum I was told that the problem is the definition of my metafield "filters.farbe". It is currently not a JSON type metafield.
So I deleted the old filters.farbe and created a new one and now I am stuck here:
What goes into the field here now? Basically, it should contain all the possible colors (schwarz", "beige", "braun", "weiß", "grau", "grün", "orange", "lila", "gelb", "blau", "rosa", "rot","bunt") and allow a list of values in that metafield. For example, when there's a product that includes black and green color, both values should be sent to "filters.farbe" metafield for that product.
Thanks in advance.
That error is likely because your input query does not contain the product or the metafields you are checking. What is in it?
Thank you for the reply.
I am sorry, Paul. I am not sure what exactly you mean with input query. Where do I need to check what and send you a screenshot from?
There is a box labeled define inputs:
Thank you Paul. Here is the requested screenshot:
I see that I have not defined any in or outputs. What do I need to put in there?
Any field you use in the code part needs to be accessed via the input query. Something like:
{
product {
metafields {
namespace
key
value
}
}
}
Your code should return something...probably a string if you want to set a metafield with it. Message might be the wrong name so you can change that to match what it contains.
Hey Paul,
i am very sorry for the late reply, but I actually contacted the developer team of the page and they fortunately found a different way to this problem. We just created a new metafield that captured the values of an other metafield as list values and added "multicolor" additionally when the product has more than 1 color.
Still, I want to thank you for your help! I appreciate the effort and time you put into this!
Sounds good, glad you found a solution
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, 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, 2024