Skip to content

Commit 46ebd43

Browse files
author
Yaroslav Onischenko
committed
Merge remote-tracking branch 'origin/MAGETWO-52060' into develop
2 parents 069e838 + 622538a commit 46ebd43

File tree

2 files changed

+58
-45
lines changed

2 files changed

+58
-45
lines changed

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

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ define([
184184
// Callback url for media
185185
mediaCallback: '',
186186

187+
// Local media cache
188+
mediaCache: {},
189+
187190
// Cache for BaseProduct images. Needed when option unset
188191
mediaGalleryInitial: [{}],
189192

@@ -708,7 +711,15 @@ define([
708711
$this = $widget.element,
709712
attributes = {},
710713
productId = 0,
711-
additional;
714+
mediaCallData,
715+
mediaCacheKey,
716+
mediaSuccessCallback = function (data) {
717+
if (!(mediaCacheKey in $widget.options.mediaCache)) {
718+
$widget.options.mediaCache[mediaCacheKey] = data;
719+
}
720+
$widget._ProductMediaCallback($this, data);
721+
$widget._DisableProductMediaLoader($this);
722+
};
712723

713724
if (!$widget.options.mediaCallback) {
714725
return;
@@ -729,24 +740,28 @@ define([
729740
.find('.price-box.price-final_price').attr('data-product-id');
730741
}
731742

732-
additional = $.parseQuery();
733-
734-
$widget._XhrKiller();
735-
$widget._EnableProductMediaLoader($this);
736-
$widget.xhr = $.post(
737-
$widget.options.mediaCallback, {
738-
'product_id': productId,
739-
attributes: attributes,
740-
isAjax: true,
741-
additional: additional
742-
}, function (data) {
743-
$widget._ProductMediaCallback($this, data);
744-
$widget._DisableProductMediaLoader($this);
745-
},
746-
'json'
747-
).done(function () {
743+
mediaCallData = {
744+
product_id: productId,
745+
attributes: attributes,
746+
additional: $.parseQuery()
747+
};
748+
mediaCacheKey = JSON.stringify(mediaCallData);
749+
750+
if (mediaCacheKey in $widget.options.mediaCache) {
751+
mediaSuccessCallback($widget.options.mediaCache[mediaCacheKey]);
752+
} else {
753+
mediaCallData.isAjax = true;
754+
$widget._XhrKiller();
755+
$widget._EnableProductMediaLoader($this);
756+
$widget.xhr = $.post(
757+
$widget.options.mediaCallback,
758+
mediaCallData,
759+
mediaSuccessCallback,
760+
'json'
761+
).done(function () {
748762
$widget._XhrKiller();
749763
});
764+
}
750765
},
751766

752767
/**
@@ -810,32 +825,30 @@ define([
810825
return e.hasOwnProperty('large') && e.hasOwnProperty('medium') && e.hasOwnProperty('small');
811826
};
812827

813-
if (_.size($widget) < 1) {
828+
if (_.size($widget) < 1 || !support(response)) {
814829
this.updateBaseImage(this.options.mediaGalleryInitial, $main, isProductViewExist);
815830

816831
return;
817832
}
818833

819-
if (support(response)) {
820-
images.push({
821-
full: response.large,
822-
img: response.medium,
823-
thumb: response.small,
824-
isMain: true
825-
});
834+
images.push({
835+
full: response.large,
836+
img: response.medium,
837+
thumb: response.small,
838+
isMain: true
839+
});
826840

827-
if (response.hasOwnProperty('gallery')) {
828-
$.each(response.gallery, function () {
829-
if (!support(this) || response.large === this.large) {
830-
return;
831-
}
832-
images.push({
833-
full: this.large,
834-
img: this.medium,
835-
thumb: this.small
836-
});
841+
if (response.hasOwnProperty('gallery')) {
842+
$.each(response.gallery, function () {
843+
if (!support(this) || response.large === this.large) {
844+
return;
845+
}
846+
images.push({
847+
full: this.large,
848+
img: this.medium,
849+
thumb: this.small
837850
});
838-
}
851+
});
839852
}
840853

841854
this.updateBaseImage(images, $main, isProductViewExist);
@@ -872,11 +885,8 @@ define([
872885
gallery = context.find(this.options.mediaGallerySelector).data('gallery'),
873886
item;
874887

875-
if (images) {
876-
imagesToUpdate = this._setImageType($.extend(true, [], images));
877-
}
878-
879888
if (isProductViewExist) {
889+
imagesToUpdate = images.length ? this._setImageType($.extend(true, [], images)) : [];
880890
if (this.options.onlyMainImg) {
881891
updateImg = imagesToUpdate.filter(function (img) {
882892
return img.isMain;

app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ define([
2323
},
2424
_bind: function() {
2525
var options = this.options,
26+
dataUpdateFunc = '_updateWishlistData',
2627
changeCustomOption = 'change ' + options.customOptionsInfo,
2728
changeQty = 'change ' + options.qtyInfo,
2829
events = {};
@@ -35,12 +36,14 @@ define([
3536
options.productType = [];
3637
}
3738

38-
events[changeCustomOption] = '_updateWishlistData';
39-
events[changeQty] = '_updateWishlistData';
40-
options.productType.forEach(function (type) {
41-
events['change ' + options[type + 'Info']] = '_updateWishlistData';
42-
});
39+
events[changeCustomOption] = dataUpdateFunc;
40+
events[changeQty] = dataUpdateFunc;
4341

42+
for (var key in options.productType) {
43+
if (options.productType.hasOwnProperty(key) && options.productType[key] + 'Info' in options) {
44+
events['change ' + options[options.productType[key] + 'Info']] = dataUpdateFunc;
45+
}
46+
}
4447
this._on(events);
4548
},
4649
_updateWishlistData: function(event) {

0 commit comments

Comments
 (0)