Closed
Description
ProductAttributeOptionManagementInterface#add()
doesn't do anything.
Preconditions
Magento 2.1.9
Create a product attribute named "color" and set its type to "Visual Swatch". Also make sure it has at least one option. Otherwise you'll run into a different issue.
Steps to reproduce
Consider the following class:
<?php declare(strict_types=1);
namespace Acme\AttributeCreator\Model;
use Magento\Catalog\Api\ProductAttributeOptionManagementInterface;
use Magento\Eav\Api\Data\AttributeOptionInterfaceFactory;
use Magento\Eav\Api\Data\AttributeOptionLabelInterfaceFactory;
use Magento\Store\Api\StoreRepositoryInterface;
class AttributeOptionCreator
{
/** @var AttributeOptionLabelInterfaceFactory */
private $optionLabelFactory;
/** @var AttributeOptionInterfaceFactory */
private $attributeOptionFactory;
/** @var ProductAttributeOptionManagementInterface */
private $attributeOptionManagement;
/** @var StoreRepositoryInterface */
private $storeRepository;
public function __construct(
AttributeOptionLabelInterfaceFactory $optionLabelFactory,
AttributeOptionInterfaceFactory $attributeOptionFactory,
ProductAttributeOptionManagementInterface $attributeOptionManagement,
StoreRepositoryInterface $storeRepository
) {
$this->optionLabelFactory = $optionLabelFactory;
$this->attributeOptionFactory = $attributeOptionFactory;
$this->attributeOptionManagement = $attributeOptionManagement;
$this->storeRepository = $storeRepository;
}
public function createAttributeOption(string $attributeCode, string $label): void
{
$labels = [];
foreach ($this->storeRepository->getList() as $store) {
$optionLabel = $this->optionLabelFactory->create();
$optionLabel->setStoreId($store->getId());
$optionLabel->setLabel($label);
$labels[] = $optionLabel;
}
$option = $this->attributeOptionFactory->create();
$option->setStoreLabels($labels);
$option->setLabel($label);
$option->setIsDefault(false);
$this->attributeOptionManagement->add($attributeCode, $option);
}
}
Expected result
$attributeOptionCreator->createAttributeOption('color', 'Blue')
adds a new option to the attribute.
Actual result
The option is not added to the attribute.
Metadata
Metadata
Assignees
Labels
The issue has been fixed in 2.1 release lineThe issue has been fixed in 2.2 release lineThe issue has been fixed in 2.3 release lineGate 2 Passed. Manual verification of the issue description passedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedGate 1 Passed. Automatic verification of issue format passedGate 4. Acknowledged. Issue is added to backlog and ready for developmentThe issue has been reproduced on latest 2.1 releaseThe issue has been reproduced on latest 2.2 releaseThe issue has been reproduced on latest 2.3 release