-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Cannot add multiple options to configurable product via REST API #5580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I also notice that the associated unit test only tests the creation of a single option, so it would miss this. |
I think you are trying to add the same attribute twice to a product. edit |
I was adding "font type" and "font color." I did not try associating the children with the parent before creating the parent options, though, so I'll give that a shot and report back. |
1 thing you may run into is that you cannot add a child to a product with: |
No dice. This time I associated the children first and ran the steps above, but I still get the same error when adding the second option to the parent. Also, if I had been adding a duplicate option it would have been a different error ("product already has this option"). |
After much pain and suffering, I have pinpointed it to a single line of code in v2.0.7: Commenting this line fixes this issue, but I don't know what others it might cause. Why was this line there? |
Is there any fix for this bug yet? (Other than hacking the configurable.php) |
Same issue on Magento 2.1.2 with SOAP API, the error message 'Something went wrong while saving option' is quite non-informative. When will the fix provided or when will there be clear response? |
I'm also having the same issue in 2.1.3. I've tried changing the configurable.php as well but still getting the same issue. |
I have been able to add a second option through the api. I noticed that some of the values I have used to add the option are missing in your request. Try adding the 'code' value in the option, and the label and attribute id values in the values array - you'd need to get the actual values from the eav_attribute table. For example - |
Thanks for that, it didn't work for me. I get told that the property 'label' doesn't have a setter. |
Sorry, that's not quite right. I get the 'Something went wrong while saving option' when using the catalogProductRepositoryV1 service. When using the configurableProductOptionRepositoryV1 service the first attribute returns a 200 response but the second returns a 400 response with message '{"message":"Invalid entity_type specified: %1","parameters":[null]}'. Interestingly after this if I try to open the configurable product in the admin interface it gives the same message and doesn't show any of the attributes. |
I confess I am calling the api differently - in the same way as this example here: So once I have built the configurableAttributesData then I set them as configurableOptions extension attributes on the product as below:
I don't know how the REST api compares to the above, but thought it would be calling the same code under the hood. I'm not sure how to map what I've done with what you need to do unfortunately. |
Internal ticket created MAGETWO-70524 |
@svines, thank you for your report. |
I'd like to work on this! #distributed-cd |
The problem here is in the request body data: in the examples, you are passing the attribute code as the If you pass the attribute code, an entry in table The fix then, is to pass the attribute ID, so that you request body would be something like:
|
[TSG-CSL3] For 2.4 (pr22)
Uh oh!
There was an error while loading. Please reload this page.
Steps to reproduce
URL: http://[base url]/rest/V1/configurable-products/basecap/options
POST BODY:
{
"option" :
{
"attribute_id": "font_type",
"label": "font type",
"position": 0,
"values": [
{
"value_index": 216
}
]
}
}
URL: http://[base url]/rest/V1/configurable-products/basecap/options
POST BODY:
{
"option" :
{
"attribute_id": "font_color",
"label": "font color",
"position": 1,
"values": [
{
"value_index": 213
},
{
"value_index": 214
}
]
}
}
The second option returns error "Something went wrong while saving option."
Expected result
Actual result
{
"message": "Something went wrong while saving option.",
"trace": "#0 [internal function]: Magento\ConfigurableProduct\Model\OptionRepository->save('basecap', Object(Magento\ConfigurableProduct\Model\Product\Type\Configurable\Attribute))\n#1 /var/www/magento2-dev/vendor/magento/module-webapi/Controller/Rest.php(265): call_user_func_array(Array, Array)\n#2 /var/www/magento2-dev/vendor/magento/module-webapi/Controller/Rest.php(160): Magento\Webapi\Controller\Rest->processApiRequest()\n#3 /var/www/magento2-dev/var/generation/Magento/Webapi/Controller/Rest/Interceptor.php(24): Magento\Webapi\Controller\Rest->dispatch(Object(Magento\Framework\App\Request\Http))\n#4 /var/www/magento2-dev/vendor/magento/framework/App/Http.php(115): Magento\Webapi\Controller\Rest\Interceptor->dispatch(Object(Magento\Framework\App\Request\Http))\n#5 /var/www/magento2-dev/vendor/magento/framework/App/Bootstrap.php(258): Magento\Framework\App\Http->launch()\n#6 /var/www/magento2-dev/pub/index.php(37): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))\n#7 {main}"
}
Additional observation: when enabling mysql general logging, I see that something deletes the attribute immediately after creating it:
(mysql log entry): DELETE FROM
catalog_product_super_attribute
WHERE (product_super_attribute_id='426')This occurs immediately before the code checks to verify that the attribute created successfully on line 238 of vendor/magento/module-configurable-product/Model/OptionRepository.php in v2.0.7:
if (!$configurableAttribute->getId()) {
throw new CouldNotSaveException(__('Something went wrong while saving option.'));
}
This issue occurs in both 2.0.7 and 2.1.
The text was updated successfully, but these errors were encountered: