Skip to content

magento/magento2#12695: Unable to change attribute type from swatch #12771

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

Merged
merged 16 commits into from
Jun 24, 2018
Merged

Conversation

eugene-shab
Copy link
Contributor

Unable to change attribute type from swatch to dropdown

  • fixed the process of switching attribute input type

Description

Fixed Magento _Swatches module.

Fixed Issues (if relevant)

  1. Unable to change attribute type from swatch to dropdown  #12695: Unable to change attribute type from swatch to dropdown
  2. 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
  3. Color attribute taking swatch instead of Drop down option for configurable options, #9307: Color attribute taking swatch instead of Drop down option for configurable options
  4. Product Attributes Not Updating on Frontend #11403: Product Attributes Not Updating on Frontend
  5. Upgrading to 2.1.7 changed dropdown attributes to swatches #9923: Upgrading to 2.1.7 changed dropdown attributes to swatches

- fixed the process of switching attribute input type
@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Dec 15, 2017

CLA assistant check
All committers have signed the CLA.

@magento-engcom-team magento-engcom-team added bugfix Component: Catalog mageconf 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 Dec 15, 2017
Copy link
Member

@mslabko mslabko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugene-shab , Thank you for the contribution!

Please, check review comments

/**
* @var SwatchResource
*/
protected $swatchResource;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use private

@@ -68,13 +74,15 @@ class EavAttribute
public function __construct(
\Magento\Swatches\Model\ResourceModel\Swatch\CollectionFactory $collectionFactory,
\Magento\Swatches\Model\SwatchFactory $swatchFactory,
SwatchResource $swatchResource,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For make it backward compatible, set new dependency as optional and use ObjectManager to instantiating it

@@ -157,13 +165,35 @@ protected function convertSwatchToDropdown(Attribute $attribute)
if (!empty($additionalData)) {
$additionalData = $this->serializer->unserialize($additionalData);
if (is_array($additionalData) && isset($additionalData[Swatch::SWATCH_INPUT_TYPE_KEY])) {
if ($additionalData[Swatch::SWATCH_INPUT_TYPE_KEY] == Swatch::SWATCH_INPUT_TYPE_VISUAL) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This issue relevant only for visusal swatches?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Only when switching from visual to dropdown input type.

$optionsIDs = [];
if (count($attribute->getOption())) {
$options = $attribute->getOption();
foreach ($options['value'] as $id => $item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_column can be used for simplify code

if (count($attribute->getOptiontext())) {
$options = $attribute->getOptiontext();
if (count($options)) {
foreach ($options['value'] as $id => $item) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array_column can be used for simplify code

}
}

public function clearSwatchOptionTextByOptionId($optionIDs, $type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doc missed.

Can we merge both methods? It looks like "type" is redundant if we already have option id for delete

@@ -67,7 +67,7 @@ public function __construct(
*
* @return array
*/
public function getCodes()
public function getCodes()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, remove extra spaces

) {
$this->typeConfigurable = $typeConfigurable;
$this->swatchAttributeCodes = $swatchAttributeCodes;
$this->swatchHelper = $swatchHelper;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For make it backward compatible, set new dependency as optional and use ObjectManager to instantiating it

$swatchAttributes[$configurableAttribute->getAttributeId()]
= $configurableAttribute->getProductAttribute();
// Due to $this->swatchAttributeCodes->getCodes() - return swatch data for every attribute.
if ($this->swatchHelper->isSwatchAttribute($configurableAttribute->getProductAttribute())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more readability, these conditions can be moved to private method with description of intention of extra condition

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, mark this method as deprecated and add comment that this method introduced only for case when customer already has converted attribute.

@@ -36,10 +40,12 @@ class SwatchAttributesProvider
*/
public function __construct(
Configurable $typeConfigurable,
SwatchAttributeCodes $swatchAttributeCodes
SwatchAttributeCodes $swatchAttributeCodes,
\Magento\Swatches\Helper\Data\Proxy $swatchHelper
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, set proxy $swatchHelper in di.xml (remove \Proxy from construct and move it to di.xml)

Proxies and interceptors MUST NEVER be explicitly requested in constructors. See:
http://devdocs.magento.com/guides/v2.2/coding-standards/technical-guidelines.html

Copy link
Contributor

@ishakhsuvarov ishakhsuvarov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see review by @mslabko

@sidolov
Copy link
Contributor

sidolov commented Mar 11, 2018

Hi @eugene-shab , please, merge latest mainline to your branch, resolve conflicts and we continue work with PR. Thanks!

@sidolov sidolov self-assigned this Mar 11, 2018
@eugene-shab
Copy link
Contributor Author

After last changes in 2.2-develop: it seems that method hasSwatchAttribute can be removed.

Please continue.

* @return bool
* @deprecated
*/
private function hasSwatchAttribute($productAttribute)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this method left from the previous implementation and useless for now, please, revert

);

$this->swatchAttributeCodes = $this->createMock(SwatchAttributeCodes::class);

$this->productMock = $this->createPartialMock(\Magento\Catalog\Model\Product::class, ['getId', 'getTypeId']);
$this->swatchTypeChecker = $this->createMock(SwatchAttributeType::class);

// $this->swatchHelper = (new ObjectManager($this))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove commented code

@sidolov
Copy link
Contributor

sidolov commented Apr 12, 2018

Hi @eugene-shab , just a few fixes needed and please, take a look on failed tests

@magento-engcom-team
Copy link
Contributor

Hi @sidolov, thank you for the review.
ENGCOM-1443 has been created to process this Pull Request

@ishakhsuvarov
Copy link
Contributor

@magento-engcom-team give me 2.2-develop instance

@magento-engcom-team
Copy link
Contributor

Hi @ishakhsuvarov. Thank you for your request. I'm working on Magento 2.2-develop instance for you

@magento-engcom-team
Copy link
Contributor

Hi @ishakhsuvarov, here is your Magento instance.
Admin access: https://i-12771-2-2-develop.engcom.dev.magento.com/admin
Login: admin Password: 123123q
Instance will be terminated in up to 3 hours.

@ishakhsuvarov
Copy link
Contributor

@magento-engcom-team give me new test instance

@magento-engcom-team
Copy link
Contributor

Hi @ishakhsuvarov. Thank you for your request. I'm working on Magento instance for you

@magento-engcom-team
Copy link
Contributor

Hi @ishakhsuvarov, here is your new Magento instance.
Admin access: https://pr-12771.engcom.dev.magento.com/admin
Login: admin Password: 123123q
Please make sure you are PR author or assignee to access the instance.

@magento-engcom-team
Copy link
Contributor

Hi @eugene-shab. Thank you for your contribution.
Changes from your Pull Request will be available with the upcoming 2.2.6 release.

Please, consider to port this solution to 2.3 release line.
You may use Porting tool to port commits automatically.

@eugene-shab eugene-shab self-assigned this Jun 27, 2018
@eugene-shab eugene-shab deleted the 12695 branch July 5, 2018 19:40
@eugene-shab eugene-shab restored the 12695 branch July 6, 2018 12:50
@eugene-shab eugene-shab deleted the 12695 branch July 6, 2018 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Award: bug fix Award: test coverage bugfix Component: Catalog Progress: accept 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.

8 participants