Skip to content

Correctly provide list of swatch attributes for product #11703 #12237

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
wants to merge 3 commits into from

Conversation

therool
Copy link
Contributor

@therool therool commented Nov 14, 2017

Description

Correctly provide list of swatch attributes for product. This is an fix for #11703

The populateAdditionalDataEavAttribute, isSwatchAttribute, isVisualSwatch, isTextSwatch method definitions moved from Magento\Swatches\Helper\Data class to Magento\Swatches\Model\SwatchAttributesProvider class but methods are still callable from Magento\Swatches\Helper\Data which just calls the Magento\Swatches\Model\SwatchAttributesProvider methods instead so the backward compatibility is preserved. Method definitions are moved so they can be used in the Magento\Swatches\Model\SwatchAttributesProvider::provide method to correctly list of swatch attributes for product.

Fixed Issues (if relevant)

  1. Changing Swatches to Drop-down does not remove swatches from existing products #11703: Changing Swatches to Drop-down does not remove swatches from existing products

Manual testing scenarios

  1. Create swatch text attribute
  2. Create configurable product using this attribute
  3. Open product on frontend - attribute is being outputted as swatch attribute and you can select all the product configurations which is ok
  4. Change the swatch attribute back to dropdown
  5. Open product on the frontend - attribute is being still outputted as swatch attribute which is wrong but you still can select the product configurations
  6. Add additional option for the dropdown attribute and add additional configuration for this option to the configurable product
  7. Open the product on the frontend - the attribute is still being still outputted as swatch attribute and the newly added configuration can't be selected on the frontend because the added attribute does not contain necessary data for it to be rendered as swatch option as the attribute should be rendered as dropdown option instead of swatch.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Nov 14, 2017

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team magento-engcom-team added Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 14, 2017
@omiroshnichenko omiroshnichenko self-assigned this Dec 6, 2017
@omiroshnichenko
Copy link
Contributor

Hi, @therool. The main problem that after changing type of attribute from swatch to dropdown, swatch options stay in eav_attribute_option_swatch. In result of this \Magento\Swatches\Model\SwatchAttributeCodes::getSwatchAttributeCodes method returns swatch options. Correct fix will be to delete options from eav_attribute_option_swatch when we converting attribute. Will you continue working on this PR?

@therool
Copy link
Contributor Author

therool commented Dec 6, 2017

@omiroshnichenko yes the problem is with \Magento\Swatches\Model\SwatchAttributeCodes::getSwatchAttributeCodes but then if the options are deleted from eav_attribute_option_swatch and in case if the attribute is being changed back to swatch then all the previously entered swatch options data is lost but it might be good to preserve them.
So if the current changes are not good then it might be better to just add a new is_swatch column to catalog_eav_attribute so the \Magento\Swatches\Model\SwatchAttributeCodes::getSwatchAttributeCodes can use as simple sql as:

SELECT a.attribute_code
FROM catalog_eav_attribute c
JOIN eav_attribute a ON a.attribute_id = c.attribute_id
WHERE c.is_swatch = 1

@omiroshnichenko
Copy link
Contributor

@therool In case when you will change back, you will need to enter new data for swatches. I don't see any reason to keep swatch options data if it was converted to dropdown.
Your fix just masks problem, unused swatch options must be removed in convert process.

@omiroshnichenko
Copy link
Contributor

I will close this PR, because #12771 provides correct fix. @therool Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Progress: needs update Release Line: 2.2 Reproduced on 2.1.x The issue has been reproduced on latest 2.1 release Reproduced on 2.2.x The issue has been reproduced on latest 2.2 release Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants