Closed
Description
Steps to reproduce
- Make sure that you have an attribute that is of type "swatches"
- Make sure that this attribute does not have any option / swatch
- Try to add a swatch option using
\Magento\Catalog\Api\ProductAttributeOptionManagementInterface::add
Expected result
The attribute from step 1 above should have a new swatch option.
Actual result
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).
Fix
\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;
}
Github extension while waiting for the fix to be implemented
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 lineCannot reproduce the issue on the latest `2.4-develop` branchGate 2 Passed. Manual verification of the issue description passedGate 1 Failed. Automatic verification of issue format is failed