Skip to content
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

Fixed magento text swatch switches product image even if attribute feature is disabled #16446 #19184

Merged

Conversation

ravi-chandra3197
Copy link
Contributor

@ravi-chandra3197 ravi-chandra3197 commented Nov 13, 2018

Description (*)

Fixed magento text swatch switches product image even if attribute feature is disabled #16446

Fixed Issues (if relevant)

  1. magento 2.2.2 text swatch switches product image even if attribute feature is disabled #16446: Fixed magento text swatch switches product image even if attribute feature is disabled

Manual testing scenarios (*)

N/A

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-engcom-team
Copy link
Contributor

Hi @ravi-chandra3197. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@sivaschenko sivaschenko self-assigned this Nov 13, 2018
Copy link
Member

@sivaschenko sivaschenko 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 the review comments. Also I think the attributes used to idetify "update_product_preview_image" should be retrived considering product context. Also, I believe it would be better to fix the issue in frontend implementation (See https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js)

@@ -117,7 +117,8 @@ public function __construct(
UrlBuilder $urlBuilder,
Json $serializer = null,
SwatchAttributesProvider $swatchAttributesProvider = null,
SwatchAttributeType $swatchTypeChecker = null
SwatchAttributeType $swatchTypeChecker = null,
\Magento\Catalog\Model\ResourceModel\Eav\Attribute $attributeFactory
Copy link
Member

Choose a reason for hiding this comment

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

Please add additional constructor parameters as options to keep backward compatibility

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have changed as per your suggestion

$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$attributeInfo = $this->_attributeFactory->getCollection();
if ($attributeInfo) {
$attributeInfo = $attributeInfo->join(array('catalog_eav_attribute' => $resource->getTableName('catalog_eav_attribute')), 'main_table.attribute_id = catalog_eav_attribute.attribute_id')
Copy link
Member

Choose a reason for hiding this comment

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

Please avoid using objectManager to keep dependencies explicit. Please use \Magento\Catalog\Api\ProductAttributeRepositoryInterface::getList to retrieve attributes.

->addFieldToFilter('catalog_eav_attribute.additional_data', array('like' => '%update_product_preview_image%'));

foreach ($attributeInfo as $attribute) {
$additional_data = json_decode($attribute['additional_data'], true);
Copy link
Member

Choose a reason for hiding this comment

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

Please use camel case for variable names: $additionalData

@ravi-chandra3197
Copy link
Contributor Author

Hello @sivaschenko
I have update change as per your suggestion can review it.

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

@ravi-chandra3197 thanks for your updates, please see the additional comments. Also can you please provide your feedback to my comment on the previous review

$attributeInfo = $this->attributeRepository->getList($searchCriteria);
$attributeInfo = $attributeInfo->getItems();
foreach ($attributeInfo as $attribute) {
$additionalData = json_decode($attribute['additional_data'], true);
Copy link
Member

Choose a reason for hiding this comment

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

Please use serializer to decode the additional data

@@ -39,11 +39,15 @@ public function __construct(
Context $context,
\Magento\Catalog\Model\ProductFactory $productModelFactory,
\Magento\Swatches\Helper\Data $swatchHelper,
\Magento\PageCache\Model\Config $config
\Magento\PageCache\Model\Config $config,
\Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria,
Copy link
Member

Choose a reason for hiding this comment

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

Please add additional parameters as optional (= null)

@sivaschenko
Copy link
Member

sivaschenko commented Dec 14, 2018

Hi @ravi-chandra3197 are you still working on this pull request?

@ravi-chandra3197
Copy link
Contributor Author

Hello @sivaschenko
I have try to find front-end solution.
https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js)

@sidolov
Copy link
Contributor

sidolov commented Jan 28, 2019

Hi @ravi-chandra3197 , will you continue progress with the PR?

@ravi-chandra3197
Copy link
Contributor Author

@sidolov
Copy link
Contributor

sidolov commented Mar 14, 2019

@ravi-chandra3197 , I am closing this PR now due to inactivity.
Please reopen and update if you wish to continue.
Thank you for the collaboration!

@sidolov sidolov closed this Mar 14, 2019
@ghost
Copy link

ghost commented Mar 14, 2019

Hi @ravi-chandra3197, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@ravi-chandra3197
Copy link
Contributor Author

Hello @sivaschenko
I have updated the code as per your suggestion and implement solution using swatch-renderer.js

https://github.com/magento/magento2/blob/2.3-develop/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

Hi @ravi-chandra3197 , thanks for update. Please see my review comments

@ghost ghost assigned sivaschenko Apr 23, 2019
@ravi-chandra3197
Copy link
Contributor Author

Hello @sivaschenko
I have updated the code as your suggestion.

Copy link
Member

@sivaschenko sivaschenko left a comment

Choose a reason for hiding this comment

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

@ravi-chandra3197 thanks for updates, please see my review comments

@@ -182,6 +182,9 @@ public function getJsonSwatchConfig()
$attributeDataArray
);
}
if (isset($attributeDataArray['additional_data'])) {
$config[$attributeId]['additional_data'] = $attributeDataArray['additional_data'];
Copy link
Member

Choose a reason for hiding this comment

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

Proper alignment makes code much easier to read

Suggested change
$config[$attributeId]['additional_data'] = $attributeDataArray['additional_data'];
$config[$attributeId]['additional_data'] = $attributeDataArray['additional_data'];

Copy link
Member

Choose a reason for hiding this comment

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

Also, what do you think about assigning only 'update_product_preview_image' key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @sivaschenko
in additional_data we get all data in serialize form
{swatch_input_type: "text", update_product_preview_image: "1", use_product_image_for_swatch: 0}

@ravi-chandra3197
Copy link
Contributor Author

Hello @sivaschenko
I have updated the PR code as per your suggestion can you review it.

@soleksii
Copy link

✔️ QA Passed

Before:

before

After:

after

@soleksii
Copy link

✔️ QA Passed

@m2-assistant
Copy link

m2-assistant bot commented Jun 7, 2019

Hi @ravi-chandra3197, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

magento-engcom-team pushed a commit to okorshenko/magento2 that referenced this pull request Jun 7, 2019
@magento-engcom-team magento-engcom-team added this to the Release: 2.3.3 milestone Jun 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants