Skip to content

Commit 282711e

Browse files
ENGCOM-4825: Fixed magento text swatch switches product image even if attribute feature is disabled #16446 #19184
- Merge Pull Request #19184 from ravi-chandra3197/magento2:patch-16446 - Merged commits: 1. dfaee8e 2. 6ce2026 3. 01e8ff1 4. 73ef119
2 parents 93a8162 + 73ef119 commit 282711e

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

app/code/Magento/Catalog/Test/Mftf/Section/AdminCreateProductAttributeSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<element name="DefaultLabel" type="input" selector="#attribute_label"/>
1414
<element name="InputType" type="select" selector="#frontend_input"/>
1515
<element name="ValueRequired" type="select" selector="#is_required"/>
16+
<element name="UpdateProductPreviewImage" type="select" selector="[name='update_product_preview_image']"/>
1617
<element name="AdvancedProperties" type="button" selector="#advanced_fieldset-wrapper"/>
1718
<element name="DefaultValue" type="input" selector="#default_value_text"/>
1819
<element name="Scope" type="select" selector="#is_global"/>

app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,17 @@ public function getJsonSwatchConfig()
182182
$attributeDataArray
183183
);
184184
}
185+
if (isset($attributeDataArray['additional_data'])) {
186+
$config[$attributeId]['additional_data'] = $attributeDataArray['additional_data'];
187+
}
185188
}
186189

187190
return $this->jsonEncoder->encode($config);
188191
}
189192

190193
/**
191194
* Get number of swatches from config to show on product listing.
195+
*
192196
* Other swatches can be shown after click button 'Show more'
193197
*
194198
* @return string
@@ -228,6 +232,8 @@ public function getProduct()
228232
}
229233

230234
/**
235+
* Get swatch attributes data.
236+
*
231237
* @return array
232238
*/
233239
protected function getSwatchAttributesData()
@@ -236,6 +242,8 @@ protected function getSwatchAttributesData()
236242
}
237243

238244
/**
245+
* Init isProductHasSwatchAttribute.
246+
*
239247
* @deprecated 100.1.5 Method isProductHasSwatchAttribute() is used instead of this.
240248
*
241249
* @codeCoverageIgnore
@@ -364,6 +372,8 @@ protected function getVariationMedia($attributeCode, $optionId)
364372
}
365373

366374
/**
375+
* Get swatch product image.
376+
*
367377
* @param Product $childProduct
368378
* @param string $imageType
369379
* @return string
@@ -384,6 +394,8 @@ protected function getSwatchProductImage(Product $childProduct, $imageType)
384394
}
385395

386396
/**
397+
* Check if product have image.
398+
*
387399
* @param Product $product
388400
* @param string $imageType
389401
* @return bool
@@ -394,6 +406,8 @@ protected function isProductHasImage(Product $product, $imageType)
394406
}
395407

396408
/**
409+
* Get configurable options ids.
410+
*
397411
* @param array $attributeData
398412
* @return array
399413
* @since 100.0.3
@@ -453,15 +467,17 @@ protected function getRendererTemplate()
453467
}
454468

455469
/**
470+
* @inheritDoc
456471
* @deprecated 100.1.5 Now is used _toHtml() directly
457-
* @return string
458472
*/
459473
protected function getHtmlOutput()
460474
{
461475
return parent::_toHtml();
462476
}
463477

464478
/**
479+
* Get media callback url.
480+
*
465481
* @return string
466482
*/
467483
public function getMediaCallback()

app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
<!-- Select visual swatch -->
4242
<selectOption selector="{{AttributePropertiesSection.InputType}}" userInput="swatch_visual" stepKey="selectInputType"/>
4343

44+
<!-- Set Update Product Preview Image to Yes-->
45+
<selectOption selector="{{AttributePropertiesSection.UpdateProductPreviewImage}}" userInput="Yes" stepKey="setUpdateProductPreviewImage"/>
46+
4447
<!-- This hack is because the same <input type="file"> is re-purposed used for all uploads. -->
4548
<executeJS function="HTMLInputElement.prototype.click = function() { if(this.type !== 'file') HTMLElement.prototype.click.call(this); };" stepKey="disableClick"/>
4649

app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ define([
713713
$wrapper = $this.parents('.' + $widget.options.classes.attributeOptionsWrapper),
714714
$label = $parent.find('.' + $widget.options.classes.attributeSelectedOptionLabelClass),
715715
attributeId = $parent.attr('attribute-id'),
716-
$input = $parent.find('.' + $widget.options.classes.attributeInput);
716+
$input = $parent.find('.' + $widget.options.classes.attributeInput),
717+
checkAdditionalData = JSON.parse(this.options.jsonSwatchConfig[attributeId]['additional_data']);
717718

718719
if ($widget.inProductList) {
719720
$input = $widget.productForm.find(
@@ -753,7 +754,10 @@ define([
753754
$widget.options.jsonConfig.optionPrices
754755
]);
755756

756-
$widget._loadMedia();
757+
if (checkAdditionalData['update_product_preview_image'] === '1') {
758+
$widget._loadMedia();
759+
}
760+
757761
$input.trigger('change');
758762
},
759763

0 commit comments

Comments
 (0)