File tree 1 file changed +13
-5
lines changed
app/code/Magento/Catalog/Model/Product/Attribute 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -40,11 +40,19 @@ public function getItems($attributeCode)
40
40
*/
41
41
public function add ($ attributeCode , $ option )
42
42
{
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 ;
48
56
}
49
57
50
58
/**
You can’t perform that action at this time.
0 commit comments