Skip to content

Commit 94391bd

Browse files
author
Sergey Shvets
committed
MAGETWO-96594: Image Position issue with Associated Products
1 parent ae55551 commit 94391bd

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ define([
291291
images = this.options.spConfig.images[this.simpleProduct];
292292

293293
if (images) {
294+
images = this._sortImages(images);
294295
if (this.options.gallerySwitchStrategy === 'prepend') {
295296
images = images.concat(initialImages);
296297
}
@@ -309,7 +310,17 @@ define([
309310
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
310311
}
311312

312-
galleryObject.first();
313+
},
314+
315+
/**
316+
* Sorting images array
317+
*
318+
* @private
319+
*/
320+
_sortImages: function (images) {
321+
return _.sortBy(images, function (image) {
322+
return image.position;
323+
});
313324
},
314325

315326
/**

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ define([
695695
*/
696696
_sortImages: function (images) {
697697
return _.sortBy(images, function (image) {
698-
return image.isMain === true ? -1 : image.position;
698+
return image.position;
699699
});
700700
},
701701

@@ -1243,9 +1243,6 @@ define([
12431243
dataMergeStrategy: this.options.gallerySwitchStrategy
12441244
});
12451245
}
1246-
1247-
gallery.first();
1248-
12491246
} else if (justAnImage && justAnImage.img) {
12501247
context.find('.product-image-photo').attr('src', justAnImage.img);
12511248
}

lib/web/mage/gallery/gallery.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,16 @@ define([
472472
* @param {Array.<Object>} data - Set of gallery items to update.
473473
*/
474474
updateData: function (data) {
475+
var mainImageIndex;
475476
if (_.isArray(data)) {
476477
settings.fotoramaApi.load(data);
478+
mainImageIndex = getMainImageIndex(data);
479+
if (mainImageIndex) {
480+
settings.fotoramaApi.show({
481+
index: mainImageIndex,
482+
time: 0
483+
});
484+
}
477485

478486
$.extend(false, settings, {
479487
data: data,

0 commit comments

Comments
 (0)