Skip to content

Commit 1c2e761

Browse files
Merge pull request #703 from magento-tsg/2.0-develop-pr5
Bug fixes: - MAGETWO-61112: [Backport] [github #6195, #4101] Gallery doesn't show all images added to configurable options - MAGETWO-61326: [Backport] State/Province dropdown is broken in frontend customer gift registry
2 parents 4f6b1f1 + 4b51fe3 commit 1c2e761

File tree

6 files changed

+57
-13
lines changed

6 files changed

+57
-13
lines changed

app/code/Magento/Checkout/view/frontend/web/js/region-updater.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
define([
88
'jquery',
99
'mage/template',
10+
'underscore',
1011
'jquery/ui',
1112
'mage/validation'
12-
], function ($, mageTemplate) {
13+
], function ($, mageTemplate, _) {
1314
'use strict';
1415

1516
$.widget('mage.regionUpdater', {
@@ -124,6 +125,8 @@ define([
124125
* @private
125126
*/
126127
_clearError: function () {
128+
var args = ['clearError', this.options.regionListId, this.options.regionInputId, this.options.postcodeId];
129+
127130
if (this.options.clearError && typeof this.options.clearError === 'function') {
128131
this.options.clearError.call(this);
129132
} else {
@@ -133,8 +136,8 @@ define([
133136

134137
this.options.form = $(this.options.form);
135138

136-
this.options.form && this.options.form.data('validator') && this.options.form.validation('clearError',
137-
this.options.regionListId, this.options.regionInputId, this.options.postcodeId);
139+
this.options.form && this.options.form.data('validator') &&
140+
this.options.form.validation.apply(this.options.form, _.compact(args));
138141

139142
// Clean up errors on region & zip fix
140143
$(this.options.regionInputId).removeClass('mage-error').parent().find('[generated]').remove();

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ $_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+
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
38+
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
3739
}
3840
}
3941
}

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

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,17 @@ define([
2828
'<% } %>',
2929
mediaGallerySelector: '[data-gallery-role=gallery-placeholder]',
3030
mediaGalleryInitial: null,
31-
slyOldPriceSelector: '.sly-old-price'
31+
slyOldPriceSelector: '.sly-old-price',
32+
33+
/**
34+
* Defines the mechanism of how images of a gallery should be
35+
* updated when user switches between configurations of a product.
36+
*
37+
* As for now value of this option can be either 'replace' or 'prepend'.
38+
*
39+
* @type {String}
40+
*/
41+
gallerySwitchStrategy: 'replace'
3242
},
3343

3444
/**
@@ -84,10 +94,9 @@ define([
8494

8595
this.inputSimpleProduct = this.element.find(options.selectSimpleProduct);
8696

87-
gallery.on('gallery:loaded', function () {
88-
var galleryObject = gallery.data('gallery');
89-
options.mediaGalleryInitial = galleryObject.returnCurrentImages();
90-
});
97+
gallery.data('gallery') ?
98+
this._onGalleryLoaded(gallery) :
99+
gallery.on('gallery:loaded', this._onGalleryLoaded.bind(this, gallery));
91100
},
92101

93102
/**
@@ -258,15 +267,29 @@ define([
258267
*/
259268
_changeProductImage: function () {
260269
var images = this.options.spConfig.images[this.simpleProduct],
270+
initialImages = this.options.mediaGalleryInitial,
261271
galleryObject = $(this.options.mediaGallerySelector).data('gallery');
262272

263273
if (galleryObject) {
264274
if (images) {
275+
if (this.options.gallerySwitchStrategy === 'prepend') {
276+
images = images.concat(initialImages);
277+
}
278+
279+
images = $.extend(true, [], images);
280+
281+
images.forEach(function (img) {
282+
img.type = 'image';
283+
});
284+
265285
galleryObject.updateData(images);
266286
} else {
267-
galleryObject.updateData(this.options.mediaGalleryInitial);
287+
galleryObject.updateData(initialImages);
288+
$(this.options.mediaGallerySelector).AddFotoramaVideoEvents();
268289
}
269290
}
291+
292+
galleryObject.first();
270293
},
271294

272295
/**
@@ -474,8 +497,18 @@ define([
474497
} else {
475498
$(this.options.slyOldPriceSelector).hide();
476499
}
477-
}
500+
},
501+
502+
/**
503+
* Callback which fired after gallery gets initialized.
504+
*
505+
* @param {HTMLElement} element - DOM element associated with gallery.
506+
*/
507+
_onGalleryLoaded: function (element) {
508+
var galleryObject = element.data('gallery');
478509

510+
this.options.mediaGalleryInitial = galleryObject.returnCurrentImages();
511+
}
479512
});
480513

481514
return $.mage.configurable;

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"Magento_Swatches/js/SwatchRenderer": {
1414
"jsonConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
1515
"jsonSwatchConfig": <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
16-
"mediaCallback": "<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>"
16+
"mediaCallback": "<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>",
17+
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
18+
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
1719
}
1820
}
1921
}

app/design/frontend/Magento/luma/etc/view.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@
254254
<vars module="Magento_Bundle">
255255
<var name="product_summary_image_size">58</var> <!-- New Product image size used for summary block-->
256256
</vars>
257+
258+
<vars module="Magento_ConfigurableProduct">
259+
<var name="gallery_switch_strategy">prepend</var>
260+
</vars>
261+
257262
<vars module="Js_Bundle">
258263
<var name="bundle_size">1MB</var>
259264
</vars>

lib/web/mage/gallery/gallery.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ define([
407407
*/
408408
updateData: function (data) {
409409
if (_.isArray(data)) {
410-
pushMainFirst(data);
411410
settings.fotoramaApi.load(data);
412411

413412
$.extend(false, settings, {

0 commit comments

Comments
 (0)