Sometimes a merchant might not want to show products as being in-stock unless they have enough inventory of child products.
For example, only include variants of a family if the popular variants are in-stock. We don't want to advertise products with very few options available. If we have 300 XXXL shirts, but zero S, M, & L... the XXXL will still be live and serve ads. Shoppers will click on it and land on the site only to find that everything is out of stock except for the XXXL.
By using group by rules, you can target these child products and update fields such as availability and quantity. Here is an example of how to group your data by a field and updating a field where there are 2 or fewer variants in stock.
In this rule, we are looking for products where quantity is greater than 0; group by the field ‘custom_label_0’, and finally targeting the groups having less than or equal to 2 products. The products that meet this criteria will be labeled with the text ‘not enough variants in stock’
In the example above, the result is 3 groups of products
P160 has 12 products but only 1 product has quantity
YOGA has 5 products and 4 products have quantity
BRA has 4 products and all 4 have quantity.
So when the grouping is applied, we are looking for groups that have less than or equal to 2 products.
This results in applying the update to only the in-stock products in the P160 group:
Using this type of rule, you will be able to target products that have only a few variations in stock. You can then update fields on these products such as availability and quantity and set them to be out of stock.