Skip to content

Commit

Permalink
Merge pull request #76 from AnastasiaBuniakEPAM/JS-323
Browse files Browse the repository at this point in the history
JS-347: [SwatchRenderer.js] Instruct gallery to switch preview on new…
  • Loading branch information
uharbachou1 committed Dec 15, 2015
2 parents 08d4adf + 47cb1fa commit 31c2ad4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,18 @@ define([
}

function updateGallery(imagesArr) {
var mainImg = imagesArr.filter(function (img) {
var imgToUpdate,
mainImg;

mainImg = imagesArr.filter(function (img) {
return img.isMain;
});
!mainImg[0].type && (mainImg[0].type = 'image');

galleryObject.updateDataByIndex(0, mainImg[0]);
imgToUpdate = mainImg.length ? mainImg[0] : imagesArr[0];

!imgToUpdate.type && (imgToUpdate.type = 'image');

galleryObject.updateDataByIndex(0, imgToUpdate);
galleryObject.seek(1);
}

Expand Down
24 changes: 16 additions & 8 deletions app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,8 @@ define([
images.push({
full: response.large,
img: response.medium,
thumb: response.small
thumb: response.small,
isMain: true
});

if (response.hasOwnProperty('gallery')) {
Expand Down Expand Up @@ -912,22 +913,29 @@ define([
*/
updateBaseImage: function (images, context, isProductViewExist) {
var justAnImage = images[0],
imgs,
imgToUpdate,
updateImg,
imagesToUpdate,
gallery = context.find(this.options.mediaGallerySelector).data('gallery');

if (images) {
imgs = $.extend(true, [], images);
imgToUpdate = this._setImageType(imgs);
imagesToUpdate = this._setImageType($.extend(true, [], images));
}

if (isProductViewExist) {
if (this.options.onlyMainImg) {
//to be refactored - main img instead of 0;
gallery.updateDataByIndex(0, imgToUpdate[0]);
updateImg = imagesToUpdate.filter(function (img) {
return img.isMain;
});

if (updateImg.length) {
gallery.updateDataByIndex(0, updateImg[0]);
} else {
gallery.updateDataByIndex(0, imagesToUpdate[0]);
}

gallery.seek(1);
} else {
gallery.updateData(imgToUpdate);
gallery.updateData(imagesToUpdate);
}
} else if (justAnImage && justAnImage.img) {
context.find('.product-image-photo').attr('src', justAnImage.img);
Expand Down

0 comments on commit 31c2ad4

Please sign in to comment.