Skip to content

Cannot add multiple options to configurable product via REST API #5580

@svines

Description

@svines

Steps to reproduce

  1. Create a new configurable product
  2. Use the REST API to add a new option to the new product (this works):
    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
    }
    ]
    }
    }
  3. Use the REST API to add a second option to the new product:
    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

  1. Additional option added to configurable product and a 200 response from REST API.

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.

Metadata

Metadata

Assignees

Labels

Event: distributed-cdDistributed Contribution DayFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is not validGate 1 Failed. Automatic verification of issue format is failedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentReproduced on 2.1.xThe issue has been reproduced on latest 2.1 releaseReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releasebug reportnon-issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions