2

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?

2 Answers 2

2

"Value_index" is the configurable attribute option Id, which you want to use for this product . Simply it is configurable attribute's option id.

1
  • Thanks for your answer. Why the id not auto generate? I have to assign it every time? I have huge configurable products to create by the API, how can I make sure the value_index different in each creation?
    – Key Shang
    Commented Jan 11, 2018 at 8:43
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.