Skip to content

Commit c70d5b8

Browse files
committed
fix magento#8846: avoid duplicated attribute option values
1 parent fef1485 commit c70d5b8

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,19 @@ public function getItems($attributeCode)
4040
*/
4141
public function add($attributeCode, $option)
4242
{
43-
return $this->eavOptionManagement->add(
44-
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
45-
$attributeCode,
46-
$option
47-
);
43+
$currentOptions = $this->getItems($attributeCode);
44+
array_walk($currentOptions, function (&$attributeOption) {
45+
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface $attributeOption */
46+
$attributeOption = $attributeOption->getLabel();
47+
});
48+
if (!in_array($option->getLabel(), $currentOptions)) {
49+
return $this->eavOptionManagement->add(
50+
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
51+
$attributeCode,
52+
$option
53+
);
54+
}
55+
return false;
4856
}
4957

5058
/**

0 commit comments

Comments
 (0)