-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Fixed magento text swatch switches product image even if attribute feature is disabled #16446 #19184
Conversation
Hi @ravi-chandra3197. Thank you for your contribution
For more details, please, review the Magento Contributor Assistant documentation |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
Hello @sivaschenko |
There was a problem hiding this 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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)
Hi @ravi-chandra3197 are you still working on this pull request? |
Hello @sivaschenko |
Hi @ravi-chandra3197 , will you continue progress with the PR? |
Hello @sidolov |
@ravi-chandra3197 , I am closing this PR now due to inactivity. |
Hi @ravi-chandra3197, thank you for your contribution! |
845dcfd
to
5fd11d2
Compare
Hello @sivaschenko |
There was a problem hiding this 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
app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php
Outdated
Show resolved
Hide resolved
app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js
Outdated
Show resolved
Hide resolved
Hello @sivaschenko |
There was a problem hiding this 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']; |
There was a problem hiding this comment.
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
$config[$attributeId]['additional_data'] = $attributeDataArray['additional_data']; | |
$config[$attributeId]['additional_data'] = $attributeDataArray['additional_data']; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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}
app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js
Outdated
Show resolved
Hide resolved
Hello @sivaschenko |
…ature is disabled
3e302cf
to
dfaee8e
Compare
c92bd91
to
6ce2026
Compare
✔️ QA Passed |
1fb41ac
to
73ef119
Compare
Hi @ravi-chandra3197, thank you for your contribution! |
… attribute feature is disabled magento#16446 magento#19184
Description (*)
Fixed magento text swatch switches product image even if attribute feature is disabled #16446
Fixed Issues (if relevant)
Manual testing scenarios (*)
N/A
Contribution checklist (*)