Skip to content

Commit

Permalink
MAGETWO-82948: fix #8846 [Backport 2.1-develop]: avoid duplicated att…
Browse files Browse the repository at this point in the history
…ribute option values #11786
  • Loading branch information
Oleksii Korshenko authored Nov 6, 2017
2 parents 79f9c76 + a8c9630 commit 0d6201f
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ public function getItems($attributeCode)
*/
public function add($attributeCode, $option)
{
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface[] $currentOptions */
$currentOptions = $this->getItems($attributeCode);
if (is_array($currentOptions)) {
array_walk($currentOptions, function (&$attributeOption) {
/** @var \Magento\Eav\Api\Data\AttributeOptionInterface $attributeOption */
$attributeOption = $attributeOption->getLabel();
});
if (in_array($option->getLabel(), $currentOptions)) {
return false;
}
}
return $this->eavOptionManagement->add(
\Magento\Catalog\Api\Data\ProductAttributeInterface::ENTITY_TYPE_CODE,
$attributeCode,
Expand Down

0 comments on commit 0d6201f

Please sign in to comment.