From 4e190effd9445fec7abca90fcda9431e577f0650 Mon Sep 17 00:00:00 2001 From: Ravi Chandra Date: Fri, 26 Apr 2019 19:43:08 +0530 Subject: [PATCH 1/2] 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 | 6 +++++- 2 files changed, 8 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 4b57849fc7a0b..eabb29b8b08ed 100644 --- a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php +++ b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php @@ -179,6 +179,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 41688dac440c7..1664f12dfc3a5 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 @@ -785,7 +785,11 @@ define([ $widget.options.jsonConfig.optionPrices ]); - $widget._loadMedia(eventName); + var checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']); + + if (1 == checkAdditionalData['update_product_preview_image']) { + $widget._loadMedia(eventName); + } $input.trigger('change'); }, From c5674e53bb77c4529e42733848acde768c338ca7 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Fri, 12 Jul 2019 14:03:37 +0300 Subject: [PATCH 2/2] magento/magento2#22510: Static test fix. --- .../Swatches/Block/Product/Renderer/Configurable.php | 1 + .../Swatches/view/frontend/web/js/swatch-renderer.js | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php index eabb29b8b08ed..90ffd7c1a1784 100644 --- a/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php +++ b/app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php @@ -462,6 +462,7 @@ protected function getHtmlOutput() /** * @return string + * @SuppressWarnings(PHPMD.RequestAwareBlockMethod) */ 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 1664f12dfc3a5..61756f0e82bd6 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 @@ -745,7 +745,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( @@ -785,9 +786,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(eventName); } $input.trigger('change');