Skip to content

Impossible to add swatch options via Service Contracts if there is no existing swatch option for attribute #9410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
herveguetin opened this issue Apr 26, 2017 · 8 comments
Assignees
Labels
bug report Component: Catalog Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update

Comments

@herveguetin
Copy link

Steps to reproduce

  1. Make sure that you have an attribute that is of type "swatches"
  2. Make sure that this attribute does not have any option / swatch
  3. 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

https://github.com/herveguetin/Herve_SwatchOptionFix

@TomashKhamlai
Copy link
Contributor

Hello! Did you try this solution?

@herveguetin
Copy link
Author

@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.

@TomashKhamlai
Copy link
Contributor

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.

@magento-engcom-team magento-engcom-team added 2.1.x bug report Component: Catalog Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed labels Sep 11, 2017
@giacmir
Copy link
Member

giacmir commented Sep 22, 2017

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.

@magento-engcom-team
Copy link
Contributor

@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.

@magento-engcom-team magento-engcom-team self-assigned this Oct 4, 2017
@magento-engcom-team magento-engcom-team added Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Progress: needs update labels Oct 4, 2017
@magento-engcom-team
Copy link
Contributor

@herveguetin, we are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.

@giacmir
Copy link
Member

giacmir commented Oct 19, 2017

@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?

@okorshenko
Copy link
Contributor

okorshenko commented Nov 27, 2017

The issue has been fixed and delivered to 2.2-develop and 2.1-develop branch. Will be available with upcoming patch release

@okorshenko okorshenko added Fixed in 2.3.x The issue has been fixed in 2.3 release line Fixed in 2.1.x The issue has been fixed in 2.1 release line labels Nov 27, 2017
@okorshenko okorshenko added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Nov 27, 2017
magento-devops-reposync-svc pushed a commit that referenced this issue Jan 3, 2025
…eployment

[Bengals] Functional Tests Mainline Deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Catalog Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Cannot Reproduce Cannot reproduce the issue on the latest `2.4-develop` branch Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Progress: needs update
Projects
None yet
Development

No branches or pull requests

6 participants