Skip to content

Commit 6d7eb5e

Browse files
committed
Merge remote-tracking branch 'github-magento/MAGETWO-59789' into EPAM-PR-5
2 parents 599fc99 + ed7ba48 commit 6d7eb5e

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

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

Lines changed: 28 additions & 0 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
*/
@@ -473,4 +483,22 @@ public function getIdentities()
473483
return [];
474484
}
475485
}
486+
487+
/**
488+
* Get Swatch image size config data.
489+
*
490+
* @return string
491+
*/
492+
public function getJsonSwatchSizeConfig()
493+
{
494+
$imageConfig = $this->swatchMediaHelper->getImageConfig();
495+
$sizeConfig = [];
496+
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'];
501+
502+
return $this->jsonEncoder->encode($sizeConfig);
503+
}
476504
}

app/code/Magento/Swatches/view/frontend/templates/product/view/renderer.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
1919
"mediaCallback": "<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>",
2020
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
21-
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
21+
'Magento_ConfigurableProduct') ?: 'replace'; ?>",
22+
"jsonSwatchImageSizeConfig": <?php /* @noEscape */ echo $block->getJsonSwatchSizeConfig() ?>
2223
}
2324
},
2425
"*" : {

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ define([
6767
* - option-label (string)
6868
* - option-tooltip-thumb
6969
* - option-tooltip-value
70+
* - thumb-width
71+
* - thumb-height
7072
*/
7173
$.widget('mage.SwatchRendererTooltip', {
7274
options: {
@@ -86,6 +88,8 @@ define([
8688
label = $this.attr('option-label'),
8789
thumb = $this.attr('option-tooltip-thumb'),
8890
value = $this.attr('option-tooltip-value'),
91+
width = $this.attr('thumb-width'),
92+
height = $this.attr('thumb-height'),
8993
$image,
9094
$title,
9195
$corner;
@@ -115,7 +119,9 @@ define([
115119
// Image
116120
$image.css({
117121
'background': 'url("' + thumb + '") no-repeat center', //Background case
118-
'background-size': 'initial'
122+
'background-size': 'initial',
123+
'width': width + 'px',
124+
'height': height + 'px'
119125
});
120126
$image.show();
121127
} else if (type === 1) {
@@ -476,6 +482,7 @@ define([
476482
_RenderSwatchOptions: function (config, controlId) {
477483
var optionConfig = this.options.jsonSwatchConfig[config.id],
478484
optionClass = this.options.classes.optionClass,
485+
sizeConfig = this.options.jsonSwatchImageSizeConfig,
479486
moreLimit = parseInt(this.options.numberToShow, 10),
480487
moreClass = this.options.classes.moreButton,
481488
moreText = this.options.moreButtonText,
@@ -492,6 +499,8 @@ define([
492499
value,
493500
thumb,
494501
label,
502+
width,
503+
height,
495504
attr;
496505

497506
if (!optionConfig.hasOwnProperty(this.id)) {
@@ -507,6 +516,8 @@ define([
507516
type = parseInt(optionConfig[id].type, 10);
508517
value = optionConfig[id].hasOwnProperty('value') ? optionConfig[id].value : '';
509518
thumb = optionConfig[id].hasOwnProperty('thumb') ? optionConfig[id].thumb : '';
519+
width = _.has(sizeConfig, 'swatchThumb') ? sizeConfig.swatchThumb.width : 110;
520+
height = _.has(sizeConfig, 'swatchThumb') ? sizeConfig.swatchThumb.height : 90;
510521
label = this.label ? this.label : '';
511522
attr =
512523
' id="' + controlId + '-item-' + id + '"' +
@@ -519,7 +530,9 @@ define([
519530
' aria-label="' + label + '"' +
520531
' option-tooltip-thumb="' + thumb + '"' +
521532
' option-tooltip-value="' + value + '"' +
522-
' role="option"';
533+
' role="option"' +
534+
' thumb-width="' + width + '"' +
535+
' thumb-height="' + height + '"';
523536

524537
if (!this.hasOwnProperty('products') || this.products.length <= 0) {
525538
attr += ' option-empty="true"';
@@ -538,7 +551,8 @@ define([
538551
} else if (type === 2) {
539552
// Image
540553
html += '<div class="' + optionClass + ' image" ' + attr +
541-
' style="background: url(' + value + ') no-repeat center; background-size: initial;">' + '' +
554+
' style="background: url(' + value + ') no-repeat center; background-size: initial;width:' +
555+
sizeConfig.swatchImage.width + 'px; height:' + sizeConfig.swatchImage.height + 'px">' + '' +
542556
'</div>';
543557
} else if (type === 3) {
544558
// Clear

0 commit comments

Comments
 (0)