magento2 icon indicating copy to clipboard operation
magento2 copied to clipboard

Rest API create product attribute options - unable to set option value

Open salgua opened this issue 3 years ago • 10 comments

Preconditions and environment

  • Magento 2.4.5
  • Having a custom product attribute, type multiple select

Steps to reproduce

  1. Create an attribute option using this REST API enpoint: POST products/attributes/{attributeCode}/options
  2. Use this payload:
     "option": {
     "label": "aaaaaaa",
     "value": "bbbbb",
     }
    

Expected result

When I call this REST API endpoint: GET products/attributes/{attributeCode}/options in the result array I expect to obtain an option like this:

{
"label": "aaaaaaa",
"value": "bbbbb"
}

Actual result

when the POST enpoint create the new option, it ignores the value. This is the created option:

{
"label": "aaaaaaa",
"value": "123"
}

where '123' is the progressive option ID.

Additional information

Here is the official enpoint documentation:

https://adobe-commerce.redoc.ly/2.4.5-admin/tag/productsattributesattributeCodeoptions#operation/PostV1ProductsAttributesAttributeCodeOptions

as you can see label and value are mandatory, but value is totally ignored.

Release note

No response

Triage and priority

  • [ ] Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • [ ] Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • [X] Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • [ ] Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • [ ] Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

salgua avatar Mar 01 '23 11:03 salgua

Hi @salgua. Thank you for your report. To speed up processing of this issue, make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, Add a comment to the issue:


Join Magento Community Engineering Slack and ask your questions in #github channel. :warning: According to the Magento Contribution requirements, all issues must go through the Community Contributions Triage process. Community Contributions Triage is a public meeting. :clock10: You can find the schedule on the Magento Community Calendar page. :telephone_receiver: The triage of issues happens in the queue order. If you want to speed up the delivery of your contribution, join the Community Contributions Triage session to discuss the appropriate ticket.

m2-assistant[bot] avatar Mar 01 '23 11:03 m2-assistant[bot]

Hi @engcom-Bravo. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Mar 01 '23 11:03 m2-assistant[bot]

Hi @engcom-Lima. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Mar 01 '23 11:03 m2-assistant[bot]

Hi @salgua ,

Thanks for your contribution and collaboration.

I have tried to reproduce the issue in fresh **2.4-develop ** instance and this issue is the expected behaviour of Magento. Whenever options is created for custom attribute multi-select, Magento generate unique increment id for the options created. Below is the screenshot for your reference: Screenshot 2023-03-01 at 6 28 03 PM

Screenshot 2023-03-01 at 5 52 10 PM Screenshot 2023-03-01 at 5 46 54 PM

Let us know if your facing any issue.

Thanks

engcom-Lima avatar Mar 01 '23 13:03 engcom-Lima

Hi @engcom-Lima, I suspected it was the default behavior, but at this point I'm wondering: what's the point of passing it the "value" parameter? In your request you passed "value": "m3_value_shu", where does Magento save this data and how do I get it? Thanks

salgua avatar Mar 01 '23 13:03 salgua

This ticket needs further Dev triage . Hence, labelling as "Dev Experience"

engcom-Lima avatar Mar 02 '23 08:03 engcom-Lima

Hi @engcom-November. Thank you for working on this issue. In order to make sure that issue has enough information and ready for development, please read and check the following instruction: :point_down:

  • [ ] 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).
  • [ ] 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue.
  • [ ] 3. Add Area: XXXXX label to the ticket, indicating the functional areas it may be related to.
  • [ ] 4. Verify that the issue is reproducible on 2.4-develop branch
    Details- Add the comment @magento give me 2.4-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.4-develop branch, please, add the label Reproduced on 2.4.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!
  • [ ] 5. Add label Issue: Confirmed once verification is complete.
  • [ ] 6. Make sure that automatic system confirms that report has been added to the backlog.

m2-assistant[bot] avatar Mar 02 '23 09:03 m2-assistant[bot]

Hi @salgua , Thank you for the response. Verified the behavior on Magento 2.4-develop instance and is reproducible. Value passed in the payload POST /products/attributes/{attribute-code}/options is being saved / used nowhere in DB tables as well: eav_attribute_option_value, eav_attribute_option, eav_attribute, catalog_product_entity_varchar and catalog_product_entity_int The options are stored in eav_attribute_option_value DB table. Here option_idis the response retrieved from the POST request and value is the label passed in payload and the actual value passed in the payload request is being ignored but as per Magento docs, value parameter can be passed in the request which is existing behavior of Magento but however this is not a mandatory field to be passed in the payload. No behavior change is observed even if value parameter is not passed in the payload request. Hence we can consider this as an enhancement to remove the value parameter in the payload and label as feature request. image image image

engcom-November avatar Mar 08 '23 05:03 engcom-November

Any updates on this?

I am having the same issue and it is quite vital to synchronize product options from an external system to Magento. Unfortunately, as everything on Adobe/Magento takes years :(

Maxi-07 avatar Jul 09 '24 15:07 Maxi-07

@engcom-November @engcom-Hotel

In fact, this value required by this endpoint, is being used for swatch attribute, as swatch attribute option value: eav_attribute_option_swatch.value in database

    private function setSwatchAttributeOption(
        AttributeInterface $attribute,
        AttributeOptionInterface $option,
        string $optionId
    ): void {
        $optionsValue = trim($option->getValue() ?: '');
        if ($this->swatchHelper->isVisualSwatch($attribute)) {
            $attribute->setData('swatchvisual', ['value' => [$optionId => $optionsValue]]);
        } else {
            $options = [];
            $options['value'][$optionId][Store::DEFAULT_STORE_ID] = $optionsValue;
            if (is_array($option->getStoreLabels())) {
                foreach ($option->getStoreLabels() as $label) {
                    if (!isset($options['value'][$optionId][$label->getStoreId()])) {
                        $options['value'][$optionId][$label->getStoreId()] = null;
                    }
                }
            }
            $attribute->setData('swatchtext', $options);
        }
    }

It means it sets this value as swatch text, displayed as on the picture: Shoei-NXR2-MC-Hjälm-Röd

agata-maksymiuk avatar Sep 10 '24 14:09 agata-maksymiuk