From dfaee8e70d76f47e39396922d7a05287150945cb Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Thu, 25 Apr 2019 18:56:20 +0530 Subject: [PATCH 1/4] Fixed magento text swatch switches product image even if attribute feature is disabled --- .../Swatches/Block/Product/Renderer/Configurable.php | 3 +++ .../Swatches/view/frontend/web/js/swatch-renderer.js | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php index 6143b8e659059..fe9c7cdd07de2 100644 --- a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php +++ b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php @@ -182,6 +182,9 @@ public function getJsonSwatchConfig() $attributeDataArray ); } + if (isset($attributeDataArray['additional_data'])) { + $config[$attributeId]['additional_data'] = $attributeDataArray['additional_data']; + } } return $this->jsonEncoder->encode($config); diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js index 2571c0385dab7..fd383e00789be 100644 --- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js @@ -753,7 +753,12 @@ define([ $widget.options.jsonConfig.optionPrices ]); - $widget._loadMedia(); + const checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId].additional_data); + + if (checkAdditionalData.update_product_preview_image == 1) { + $widget._loadMedia(); + } + $input.trigger('change'); }, From 6ce20262a90e0f9045691f3207d9acaa2b7b3f40 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 26 Apr 2019 12:37:23 +0300 Subject: [PATCH 2/4] magento/magento2#19184: Static test fix. --- .../Block/Product/Renderer/Configurable.php | 15 ++++++++++++++- .../view/frontend/web/js/swatch-renderer.js | 4 ++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php index fe9c7cdd07de2..0848f566f67bb 100644 --- a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php +++ b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php @@ -192,6 +192,7 @@ public function getJsonSwatchConfig() /** * Get number of swatches from config to show on product listing. + * * Other swatches can be shown after click button 'Show more' * * @return string @@ -231,6 +232,8 @@ public function getProduct() } /** + * Get swatch attributes data. + * * @return array */ protected function getSwatchAttributesData() @@ -239,6 +242,8 @@ protected function getSwatchAttributesData() } /** + * Init isProductHasSwatchAttribute. + * * @deprecated 100.1.5 Method isProductHasSwatchAttribute() is used instead of this. * * @codeCoverageIgnore @@ -367,6 +372,8 @@ protected function getVariationMedia($attributeCode, $optionId) } /** + * Get swatch product image. + * * @param Product $childProduct * @param string $imageType * @return string @@ -387,6 +394,8 @@ protected function getSwatchProductImage(Product $childProduct, $imageType) } /** + * Check if product have image. + * * @param Product $product * @param string $imageType * @return bool @@ -397,6 +406,8 @@ protected function isProductHasImage(Product $product, $imageType) } /** + * Get configurable options ids. + * * @param array $attributeData * @return array * @since 100.0.3 @@ -456,8 +467,8 @@ protected function getRendererTemplate() } /** + * @inheritDoc * @deprecated 100.1.5 Now is used _toHtml() directly - * @return string */ protected function getHtmlOutput() { @@ -465,6 +476,8 @@ protected function getHtmlOutput() } /** + * Get media callback url. + * * @return string */ public function getMediaCallback() diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js index fd383e00789be..ae5014f77254d 100644 --- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js @@ -753,9 +753,9 @@ define([ $widget.options.jsonConfig.optionPrices ]); - const checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId].additional_data); + var checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']); - if (checkAdditionalData.update_product_preview_image == 1) { + if (1 == checkAdditionalData['update_product_preview_image']) { $widget._loadMedia(); } From 01e8ff1c99557f267ca5ecc5eb450218bba6fc0b Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 26 Apr 2019 16:23:23 +0300 Subject: [PATCH 3/4] magento/magento2#19184: MFTF test fix --- .../Test/Mftf/Section/AdminCreateProductAttributeSection.xml | 1 + .../Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml | 3 +++ 2 files changed, 4 insertions(+) diff --git a/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection.xml b/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection.xml index d24c501152b78..7ca2c0a56f224 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection.xml @@ -13,6 +13,7 @@ + diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml index e4c96ab3a2ba7..b82fce84a550b 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml @@ -41,6 +41,9 @@ + + + From 73ef11915ffa0ed8f8d38b785d59d3ad8ace9218 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 30 Apr 2019 13:12:43 +0300 Subject: [PATCH 4/4] magento/magento2#19184: Static test fix. --- .../Swatches/view/frontend/web/js/swatch-renderer.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js index ae5014f77254d..7e12f89738d39 100644 --- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js @@ -713,7 +713,8 @@ define([ $wrapper = $this.parents('.' + $widget.options.classes.attributeOptionsWrapper), $label = $parent.find('.' + $widget.options.classes.attributeSelectedOptionLabelClass), attributeId = $parent.attr('attribute-id'), - $input = $parent.find('.' + $widget.options.classes.attributeInput); + $input = $parent.find('.' + $widget.options.classes.attributeInput), + checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']); if ($widget.inProductList) { $input = $widget.productForm.find( @@ -753,9 +754,7 @@ define([ $widget.options.jsonConfig.optionPrices ]); - var checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']); - - if (1 == checkAdditionalData['update_product_preview_image']) { + if (checkAdditionalData['update_product_preview_image'] === '1') { $widget._loadMedia(); }