Closed
Description
Preconditions
- Magento 2.1.11 (and 2.2.2 I suppose)
Steps to reproduce
- Create a product attribute of 'dropdown' type via admin page with one option (Admin value: 0, Default Store View value: 0)
- Programmatically delete the option using OptionManagement.delete method
/**
* @var \Magento\Eav\Api\AttributeOptionManagementInterface
*/
private $optionManagement;
...
$this->optionManagement->delete(\Magento\Catalog\Model\Product::ENTITY, $attributeCode, $optionId);
Expected result
- The option should be delete w/o any errors
Actual result
NoSuchEntityException
with messageAttribute <somecode> does not contain option with Id <someId>
is thrown
Root cause
There is validateOption
method in OptionManagement.php
that checks if option exists:
getOptionText
returns "0" string as it is supposed to:
So the root cause is in validateOption
method (see the first screenshot). In line 135 it does logical NOT operator, so "0" is casted to FALSE, thus the condition is TRUE. To fix the issue the comparison should be exact: === FALSE
.
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 release