Skip to content

Commit ea7e66c

Browse files
committed
fix #8846: avoid duplicated attribute option values
1 parent 619ac30 commit ea7e66c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/OptionManagement.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ public function getItems($attributeCode)
4040
*/
4141
public function add($attributeCode, $option)
4242
{
43+
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $currentOptions */
44+
$currentOptions = $this->getItems($attributeCode);
45+
if (is_array($currentOptions)) {
46+
array_walk($currentOptions, function (&$attributeOption) {
47+
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface $attributeOption */
48+
$attributeOption = $attributeOption->getLabel();
49+
});
50+
if (in_array($option->getLabel(), $currentOptions)) {
51+
return false;
52+
}
53+
}
4354
return $this->eavOptionManagement->add(
4455
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
4556
$attributeCode,

0 commit comments

Comments
 (0)