Shopify Flow is an ecommerce automation platform that enables you to automate tasks and processes within your store and across your apps.
How is it possible to use a variant metafield value, as the value for a "Variant quantity" condition, that will trigger a action in shopify flows.
See other thread. You can use Run code to do the comparison, which makes the condition easy. Or you can reverse the condition, putting metafields in first and then comparing that with the inventory quantity
Now i did this, but somehow it can not handle negative inventory values.
Metafield is type: "Integer"
What to change here, to make it work?
Make sure you are also checking the key and namespace for that same metafield or it will match ANY metafield value.
Regarding negative, I'm not sure what you are asking.
I know, i want it to check ANY metafield value, but it seems like it does not work anyways.
Regarding negative, it seems to not work or understand this ("inventoryQuantity"= -5, equal to "Metafield Integer value"= -5)
And it cant match that condition.
The quantity in available is not necessarily the quantity in inventoryQuantity. That said, what type of metafield is that? A text or number? It's possible that it's trying to compare a string with a number and not casting it because of the negative sign
Which condition should i then use for the available quantity, to match the meta field value?
it seems like it is correct setup with "metafields_item.value equal to (productvariant.inventoryquantity", it is just the fact that it dont match to the metafield value when a negative value.
The metafield is a "Integer", so if we cant use the negative sign for it, then how do we put in negative values correctly, so it matches the condition correctly?
Also it proves that the actuall: productVariant.inventoryQuantity is getting the negative inventory value of example: -5
I'm pretty sure I just confirmed through some testing that it's treating that negative metafield as a string and therefor it doesn't match the number. I'll have to check with engineering if it's possible to fix that.
In the meantime, 2 options. you could get the metafield value in a run code step and output it as an integer. That makes your condition simpler. We also have a metafield improvement coming soon that allows access single metafields and preserves their types (right now they are all strings). I also confirmed this second option works as expected.
Great if you are able to fix that, as it does not make sense that this would not work, as it is now.
Please give me eta if you know when this would be fixed.
can show me how you build "option 2", as i am not really sure how to proceed with this?
I really need something that actually works asap 🙂
Code...make sure you change the namespace and key
export default function main(input) {
// Make sure that the data you return matches the
// shape & types defined in the output schema.
const metafield = input.productVariant.metafields.find((metafield) => metafield.namespace === "custom" && metafield.key === "variant_quantity");
//convert to int if exists, otherwise 0
const inventory = metafield ? parseInt(metafield.value) : 0;
return {
inventory: inventory,
}
}
Input:
query{
productVariant {
metafields {
namespace
key
value
}
}
}
Output:
query{
productVariant {
metafields {
namespace
key
value
}
}
}
Alright i set this up now, and do i then just keep this condition for it to check the metafield value should match the variant.inventoryQuantity etc?
I put it up like this, but i am not sure if it is correct:
The code looks fine. The condition doesn't need to check the metafield any more. Replace that with the output from your run code step and then check that against the productVariant inventory
Is this correctly setup?
Why did you put that in Log output? That will just return a string
The only variables that work in log output are liquid variables (like the output from your run code action)
Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024