Skip to content

Commit 841bce8

Browse files
committed
Merge pull request #65 from AnastasiaBuniakEPAM/JS-323
JS-344: [SwatchRenderer.js] Do not reload full image set when "First by First" is enabled
2 parents 40d09ba + 945a193 commit 841bce8

File tree

2 files changed

+26
-13
lines changed

2 files changed

+26
-13
lines changed

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@
66
?>
77
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */ ?>
88
<div class="swatch-opt"></div>
9-
<script>
10-
require(["jquery", "jquery/ui", "swatchRenderer"], function ($) {
11-
$('.swatch-opt').SwatchRenderer({
12-
jsonConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
13-
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
14-
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
15-
});
16-
});
9+
10+
<script type="text/x-magento-init">
11+
{
12+
".swatch-opt": {
13+
"jquery/ui":{},
14+
"swatchRenderer": {
15+
"jsonConfig": <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonConfig(); ?>,
16+
"jsonSwatchConfig": <?php /* @escapeNotVerified */ echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
17+
"mediaCallback": "<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>",
18+
"onlyMainImg": true
19+
}
20+
}
21+
}
1722
</script>

app/code/Magento/Swatches/view/frontend/web/js/SwatchRenderer.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ define([
204204
// selector of price wrapper (need to know where set price)
205205
selectorProductPrice: '[data-role=priceBox]',
206206

207+
//selector of product images gallery wrapper
208+
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
209+
207210
// number of controls to show (false or zero = show all)
208211
numberToShow: false,
209212

@@ -865,13 +868,16 @@ define([
865868
* @param {Boolean} isProductViewExist
866869
*/
867870
updateBaseImage: function (images, context, isProductViewExist) {
868-
var justAnImage = images[0];
871+
var justAnImage = images[0],
872+
gallery = context.find(this.options.mediaGallerySelector).data('gallery');
869873

870874
if (isProductViewExist) {
871-
context
872-
.find('[data-gallery-role=gallery-placeholder]')
873-
.data('gallery')
874-
.updateData(images);
875+
if (this.options.onlyMainImg) {
876+
gallery.updateDataByIndex(0, images[0]);
877+
gallery.seek(1);
878+
} else {
879+
gallery.updateData(images);
880+
}
875881
} else if (justAnImage && justAnImage.img) {
876882
context.find('.product-image-photo').attr('src', justAnImage.img);
877883
}
@@ -907,4 +913,6 @@ define([
907913
});
908914
}
909915
});
916+
917+
return $.custom.SwatchRenderer;
910918
});

0 commit comments

Comments
 (0)