Skip to content

Commit

Permalink
fix #8846: [backport 2.2-develop] avoid duplicated attribute option v…
Browse files Browse the repository at this point in the history
…alues
  • Loading branch information
gomencal committed Oct 26, 2017
1 parent 08f0056 commit ec08353
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 ec08353

Please sign in to comment.