Skip to content

Commit ed7ba48

Browse files
MAGETWO-59789: Image Swatch size change not working
- Fix code style
1 parent 70d6120 commit ed7ba48

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ class Configurable extends \Magento\ConfigurableProduct\Block\Product\View\Type\
4747
*/
4848
const MEDIA_CALLBACK_ACTION = 'swatches/ajax/media';
4949

50+
/**
51+
* Name of swatch image for json config
52+
*/
53+
const SWATCH_IMAGE_NAME = 'swatchImage';
54+
55+
/**
56+
* Name of swatch thumbnail for json config
57+
*/
58+
const SWATCH_THUMBNAIL_NAME = 'swatchThumb';
59+
5060
/**
5161
* @var Product
5262
*/
@@ -484,10 +494,10 @@ public function getJsonSwatchSizeConfig()
484494
$imageConfig = $this->swatchMediaHelper->getImageConfig();
485495
$sizeConfig = [];
486496

487-
$sizeConfig[Swatch::SWATCH_IMAGE_NAME]['width'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['width'];
488-
$sizeConfig[Swatch::SWATCH_IMAGE_NAME]['height'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['height'];
489-
$sizeConfig[Swatch::SWATCH_THUMBNAIL_NAME]['height'] = $imageConfig[Swatch::SWATCH_THUMBNAIL_NAME]['height'];
490-
$sizeConfig[Swatch::SWATCH_THUMBNAIL_NAME]['width'] = $imageConfig[Swatch::SWATCH_THUMBNAIL_NAME]['width'];
497+
$sizeConfig[self::SWATCH_IMAGE_NAME]['width'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['width'];
498+
$sizeConfig[self::SWATCH_IMAGE_NAME]['height'] = $imageConfig[Swatch::SWATCH_IMAGE_NAME]['height'];
499+
$sizeConfig[self::SWATCH_THUMBNAIL_NAME]['height'] = $imageConfig[Swatch::SWATCH_THUMBNAIL_NAME]['height'];
500+
$sizeConfig[self::SWATCH_THUMBNAIL_NAME]['width'] = $imageConfig[Swatch::SWATCH_THUMBNAIL_NAME]['width'];
491501

492502
return $this->jsonEncoder->encode($sizeConfig);
493503
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ define([
121121
'background': 'url("' + thumb + '") no-repeat center', //Background case
122122
'background-size': 'initial',
123123
'width': width + 'px',
124-
'height': height +'px'
124+
'height': height + 'px'
125125
});
126126
$image.show();
127127
} else if (type === 1) {
@@ -516,8 +516,8 @@ define([
516516
type = parseInt(optionConfig[id].type, 10);
517517
value = optionConfig[id].hasOwnProperty('value') ? optionConfig[id].value : '';
518518
thumb = optionConfig[id].hasOwnProperty('thumb') ? optionConfig[id].thumb : '';
519-
width = sizeConfig.swatch_thumb.width;
520-
height = sizeConfig.swatch_thumb.height;
519+
width = _.has(sizeConfig, 'swatchThumb') ? sizeConfig.swatchThumb.width : 110;
520+
height = _.has(sizeConfig, 'swatchThumb') ? sizeConfig.swatchThumb.height : 90;
521521
label = this.label ? this.label : '';
522522
attr =
523523
' id="' + controlId + '-item-' + id + '"' +
@@ -551,8 +551,8 @@ define([
551551
} else if (type === 2) {
552552
// Image
553553
html += '<div class="' + optionClass + ' image" ' + attr +
554-
' style="background: url(' + value + ') no-repeat center; background-size: initial;width:'
555-
+ sizeConfig.swatch_image.width + 'px; height:'+ sizeConfig.swatch_image.height + 'px">' + '' +
554+
' style="background: url(' + value + ') no-repeat center; background-size: initial;width:' +
555+
sizeConfig.swatchImage.width + 'px; height:' + sizeConfig.swatchImage.height + 'px">' + '' +
556556
'</div>';
557557
} else if (type === 3) {
558558
// Clear

0 commit comments

Comments
 (0)