\Magento\Catalog\Api\ProductAttributeOptionManagementInterface::addThe attribute from step 1 above should have a new swatch option.
An exception is thrown: "Cannot save attribute [code of the attribute from step 1 above]"
This comes from \Magento\Eav\Model\Entity\Attribute\OptionManagement::add because, on \Magento\Swatches\Model\Plugin\EavAttribute::prepareOptionLinks, $attributeSavedOptions[$optionCounter] is never set ($attributeSavedOptions[1] fails).
\Magento\Swatches\Model\Plugin\EavAttribute::prepareOptionLinks should be like this:
protected function prepareOptionLinks(array $optionsArray, array $attributeSavedOptions)
{
$dependencyArray = [];
$optionCounter = 1;
if (is_array($optionsArray['value']) && isset($attributeSavedOptions[$optionCounter])) {
foreach (array_keys($optionsArray['value']) as $baseOptionId) {
$dependencyArray[$baseOptionId] = $attributeSavedOptions[$optionCounter]['value'];
$optionCounter++;
}
}
$this->dependencyArray = $dependencyArray;
}
Hello! Did you try this solution?
@TomashKhamlai, the solution you are linking does not answer my question. My bug report relates to Service Contracts and does not ask for a solution to actually add swatches. It's just a bug report :)
Moreover, the solution you are providing does not make use of Service Contracts.
Okay, I will answer you when internal ticket will be created. I also tried to test REST API for this functionality and I didn't get what I expected, however, I need some time to dive deeper into this problem. Thank you for reporting.
Found this issue while trying to add swatches options in an import procedure. I ended up writing direct queries on the involved tables...
Actually all the swatches module is a pile of weird things outside of Magento standards and needs to be extensively refactored.
@herveguetin, thank you for your report.
We were not able to reproduce this issue by following the steps you provided. Please provide more detailed steps to reproduce or try to reproduce this issue on a clean installation or latest release.
@herveguetin, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.
@magento-engcom-team With "can't reproduce" are you saying that you tried and Magento\Catalog\Api\ProductAttributeOptionManagementInterface::add actually added a swatch option to an attribute?
The issue has been fixed and delivered to 2.2-develop and 2.1-develop branch. Will be available with upcoming patch release
Most helpful comment
Found this issue while trying to add swatches options in an import procedure. I ended up writing direct queries on the involved tables...
Actually all the swatches module is a pile of weird things outside of Magento standards and needs to be extensively refactored.