disable product variations on any single variation's stock hitting zero
I have Commerce Kickstart2. and I have installed/enabled the commerce_stock module.
I got a nice rule to disable the product SKU (i.e. one product variation) when the stock hits zero:
{ "rules_out_of_stock_disable_active_product" : {
"LABEL" : "Out of Stock Disable Active Product",
"PLUGIN" : "reaction rule",
"ACTIVE" : false,
"OWNER" : "rules",
"REQUIRES" : [ "rules", "entity" ],
"ON" : { "commerce_product_presave" : [] },
"IF" : [
{ "entity_is_of_type" : { "entity" : [ "commerce-product" ], "type" : "commerce_product" } },
{ "data_is" : { "data" : [ "commerce-product:commerce-stock" ], "value" : "0" } }
],
"DO" : [
{ "data_set" : { "data" : [ "commerce-product:status" ], "value" : 0 } }
]
}
}
but my issue is this: I have to disable all variations with the same commerce_product:title when any one of the variations hits zero stock.
For instance, I may have a product "mythingy" with two variations having SKU's "mythingyblue" "mythingygreen". If someone buys all the "mythingyblue" items, I need to set the "mythingygreen" and "mythingblue" variations to disabled...
So, what I think I am saying is I want a rule to disable an SKU, based on a calculation.
The calculation will have to loop on the full list of commerce_products (I don't have many),
-select only those for which the title matches the current product (e.g. all products with title "mythingy"),
-determine if **any** of the products with title "mythingy" have hit stock=zero
-supply that information back as the result of the calculation
The rule will then use this result to potentially disable the SKU.
Any ideas would be greatly appreciated since I have been bashing my head against a brick wall for 3 days. I have gone between rules, components, loops conditional components, ugh.. I am stuck!! (help!)