Magento2: value_index in configurable product API
-
25-12-2020 - |
Question
In official REST API guide Step 4. Define configurable product options, there are payload like below.
{
"option": {
"attribute_id": "141",
"label": "Size",
"position": 0,
"is_use_default": true,
"values": [
{
"value_index": 9
}
]
}
}
Other parameters I can understand, but what is the function of value_index?
The guide just said
The value assigned to the
value_index
must be unique within the system.
I have huge configurable products to create by the API, how can I make sure the value_index
different in each creation?
Solution
"Value_index" is the configurable attribute option Id, which you want to use for this product . Simply it is configurable attribute's option id.
OTHER TIPS
After a research, I found in Magento 1.9, the configurable product value_index
is the configurable attribute option value, which could get by
$configurableAttributes = $product->getTypeInstance(true)->getConfigurableAttributesAsArray($product);
print_r($configurableAttributes);
In Magento 2, the configurable product value_index
is the configurable
attribute option value too.
But, when use the Magento2 API, after my test, we could give the value_index
some unique integer, like child product id, it will work too. We do not necessarily need the configurable attribute option value
in the value_index
.