How we manage configurable products in Magento
What is a configurable product?
A configurable product exposes several variations of a same product according to one or more attributes. It could be a shoe with different sizes, a perfume bottle with different volumes, a pet food item with different weights or a shirt with multiple sizes and colours.
In Magento back-end, it is not much different from a simple product, set aside two main things:
- A list of variations within the Configurations section
- Greyed (disabled) attributes within the Configurable product attributes section
- For instance, if the variations have different colours, the Colour attribute will be disabled.
Here is what it looks like in concrete:
In order to link a configurable product to one or several variations, these latter merely need to share at least one attribute (i.e. Size) and have all distinct options for this or these attribute(s) (i.e. S/M/L). Below is a list of variations taken from our own Magento; these products share the same attribute Talla with different options.
Problems encountered
Many issues amidst configurable products come from how we decide to manage shared properties, such as weight, stock, images, etc.; whether it is at the “parent” level or at the “child” level. We also had troubles with some obscure options not automatically set when creating configurable products and linking them to their variations via API.
Stock management
We were having children (variations) with stock but a parent (configurable) without any stock. To solve that, we simply disabled stock management on parent product using this route:
/rest/default/V1/products/{productSku}/stockItems/{itemId} [PUT]
with your parent SKU for productSku (itemId does not seem to matter, we set it as 1) along this JSON body:
{ "stockItem": { "use_config_manage_stock": false, "manage_stock": false, } }
Linking issues
- Children have different attributes
- i.e. one child has a Colour attribute only and another a Size attribute only
- At least one of the children doesn’t have any attribute
- Some children have the same attribute option
- i.e. two children have a Colour attribute whose value is Red
Children visibility
We had all products visible in our front, whether the configurable or its variations. To solve that, we made children product “invisible” by setting their visibility field to 1 (value is extracted from here).
Creation process explained step by step
There are obviously many ways to do it, here we summarize our current manner, based on Magento API routes which full documentation you can encounter here.
- For each parent product, browse its children
- Save child attribute(s) if it is new
- Save child option(s) if it is new
- Save child as a simple product with its option(s) and make sure it is not visible
- Save parent product as a configurable product
- Set all possible options in parent product
- Link children to parent
- Disable stock management for parent product