Skip to content

Commit a45d524

Browse files
committed
Merge pull request #62 from AnastasiaBuniakEPAM/JS-338
JS-338: [Configurable.JS] Do not reload full image set when "First by First" is enabled
2 parents c18fbae + 21f3005 commit a45d524

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

app/code/Magento/ConfigurableProduct/view/frontend/templates/product/view/type/options/configurable.phtml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ $_attributes = $block->decorateArray($block->getAllowAttributes());
3333
{
3434
"#product_addtocart_form": {
3535
"configurable": {
36-
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>
36+
"spConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig() ?>,
37+
"onlyMainImg": true
3738
}
3839
}
3940
}

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,33 @@ define([
253253
* @private
254254
*/
255255
_changeProductImage: function () {
256-
var images = this.options.spConfig.images[this.simpleProduct],
257-
galleryObject = $(this.options.mediaGallerySelector).data('gallery');
256+
var images,
257+
initialImages = $.extend(true, [], this.options.mediaGalleryInitial),
258+
galleryObject = $(this.options.mediaGallerySelector).data('gallery'),
259+
updateGallery;
260+
261+
if (this.options.spConfig.images[this.simpleProduct]) {
262+
images = $.extend(true, [], this.options.spConfig.images[this.simpleProduct]);
263+
}
264+
265+
updateGallery = function (imagesArr) {
266+
var mainImg = imagesArr.filter(function (img) {
267+
return img.isMain;
268+
});
269+
270+
galleryObject.updateDataByIndex(0, mainImg[0]);
271+
galleryObject.seek(1);
272+
};
258273

259274
if (galleryObject) {
260275
if (images) {
261-
galleryObject.updateData(images);
276+
this.options.onlyMainImg ?
277+
updateGallery(images) :
278+
galleryObject.updateData(images);
262279
} else {
263-
galleryObject.updateData(this.options.mediaGalleryInitial);
280+
this.options.onlyMainImg ?
281+
updateGallery(initialImages) :
282+
galleryObject.updateData(this.options.mediaGalleryInitial);
264283
}
265284
}
266285
},

lib/web/fotorama/fotorama.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,7 +2250,7 @@ fotoramaVersion = '4.6.4';
22502250

22512251
if (!$frame) return;
22522252

2253-
var fullFLAG = that.fullScreen && dataFrame.full && dataFrame.full !== dataFrame.img && !frameData.$full && type === 'stage';
2253+
var fullFLAG = that.fullScreen && (!frameData.$full || dataFrame.full) && type === 'stage';
22542254

22552255
if (frameData.$img && !again && !fullFLAG) return;
22562256

@@ -2262,7 +2262,7 @@ fotoramaVersion = '4.6.4';
22622262

22632263
var srcKey = type === 'stage' ? (fullFLAG ? 'full' : 'img') : 'thumb',
22642264
src = dataFrame[srcKey],
2265-
dummy = fullFLAG ? null : dataFrame[type === 'stage' ? 'thumb' : 'img'];
2265+
dummy = fullFLAG ? dataFrame['img'] : dataFrame[type === 'stage' ? 'thumb' : 'img'];
22662266

22672267
if (type === 'navThumb') $frame = frameData.$wrap;
22682268

@@ -3428,6 +3428,17 @@ fotoramaVersion = '4.6.4';
34283428
return this;
34293429
};
34303430

3431+
that.spliceByIndex = function (index, newImgObj) {
3432+
newImgObj.img && $.ajax({
3433+
url: newImgObj.img,
3434+
type: 'HEAD',
3435+
success: function() {
3436+
data.splice(index, 1, newImgObj);
3437+
reset();
3438+
}
3439+
});
3440+
};
3441+
34313442
function unloadVideo($video, unloadActiveFLAG, releaseAutoplayFLAG) {
34323443
if (unloadActiveFLAG) {
34333444
$wrap.removeClass(wrapVideoClass);

lib/web/mage/gallery/gallery.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,19 @@ define([
453453
var images = [];
454454

455455
_.each(this.fotorama.data, function (item) {
456-
images.push(_.omit(item, '$navThumbFrame', '$navDotFrame', '$stageFrame'));
456+
images.push(_.omit(item, '$navThumbFrame', '$navDotFrame', '$stageFrame', 'labelledby'));
457457
});
458458

459459
return images;
460+
},
461+
/**
462+
* Updates gallery data partially by index
463+
* @param {Number} index - Index of image in data array to be updated.
464+
* @param {Object} item - Standart gallery image object.
465+
*
466+
*/
467+
updateDataByIndex: function(index, item){
468+
settings.fotoramaApi.spliceByIndex(index, item);
460469
}
461470
};
462471

0 commit comments

Comments
 (0)