Skip to content

Commit a96fced

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-52974-3' into QwertyPR20171107
2 parents e71416c + 97390b3 commit a96fced

File tree

8 files changed

+108
-34
lines changed

8 files changed

+108
-34
lines changed

app/code/Magento/ProductVideo/view/frontend/web/js/fotorama-add-video-events.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ define([
134134
*/
135135
_create: function () {
136136
$(this.element).on('gallery:loaded', $.proxy(function () {
137-
this.fotoramaItem = $(this.element).find('.fotorama-item');
138137
this._initialize();
139138
}, this));
140139
},
@@ -154,6 +153,7 @@ define([
154153
this.defaultVideoData = this.options.videoData = this.videoDataPlaceholder;
155154
}
156155

156+
this.fotoramaItem = $(this.element).find('.fotorama-item');
157157
this.clearEvents();
158158

159159
if (this._checkForVideoExist()) {
@@ -164,6 +164,8 @@ define([
164164
this._initFotoramaVideo();
165165
this._attachFotoramaEvents();
166166
}
167+
168+
this.element.trigger('AddFotoramaVideoEvents:loaded');
167169
},
168170

169171
/**

app/code/Magento/Swatches/Block/Product/Renderer/Configurable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ public function __construct(
119119
$configurableAttributeData,
120120
$data
121121
);
122+
123+
$this->addData(
124+
[
125+
'cache_lifetime' => isset($data['cache_lifetime']) ? $data['cache_lifetime'] : 3600
126+
]
127+
);
122128
}
123129

124130
/**

app/code/Magento/Swatches/view/frontend/layout/checkout_cart_configure_type_configurable.xml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
*/
77
-->
88
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9-
<head>
10-
<link src="Magento_Swatches::js/configurable-customer-data.js"/>
11-
</head>
9+
<body>
10+
<referenceBlock name="product.info.options.wrapper">
11+
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-">
12+
<arguments>
13+
<argument name="cache_lifetime" xsi:type="boolean">false</argument>
14+
</arguments>
15+
</block>
16+
</referenceBlock>
17+
</body>
1218
</page>

app/code/Magento/Swatches/view/frontend/layout/wishlist_index_configure_type_configurable.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
<body>
1313
<referenceBlock name="product.info.options.configurable" remove="true"/>
1414
<referenceBlock name="product.info.options.wrapper">
15-
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-" />
15+
<block class="Magento\Swatches\Block\Product\Renderer\Configurable" name="product.info.options.swatches" as="swatch_options" before="-">
16+
<arguments>
17+
<argument name="cache_lifetime" xsi:type="boolean">false</argument>
18+
</arguments>
19+
</block>
1620
</referenceBlock>
1721
</body>
1822
</page>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
?>
7-
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */ ?>
7+
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Listing\Configurable */ ?>
88
<div class="swatch-opt-<?= /* @escapeNotVerified */ $block->getProduct()->getId() ?>"></div>
99
<script>
1010
require([

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
"[data-role=swatch-options]": {
1515
"Magento_Swatches/js/swatch-renderer": {
1616
"jsonConfig": <?= /* @escapeNotVerified */ $swatchOptions = $block->getJsonConfig() ?>,
17-
"jsonSwatchConfig": <?php /* @escapeNotVerified */
18-
echo $swatchOptions = $block->getJsonSwatchConfig(); ?>,
17+
"jsonSwatchConfig": <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
1918
"mediaCallback": "<?= /* @escapeNotVerified */ $block->getMediaCallback() ?>",
2019
"gallerySwitchStrategy": "<?php /* @escapeNotVerified */ echo $block->getVar('gallery_switch_strategy',
2120
'Magento_ConfigurableProduct') ?: 'replace'; ?>"
21+
},
22+
"Magento_Swatches/js/configurable-customer-data": {
23+
"swatchOptions": <?php /* @escapeNotVerified */ echo $swatchOptions ?>
2224
}
2325
}
2426
}
Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,51 @@
1-
require([
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
26
'jquery',
3-
'Magento_ConfigurableProduct/js/options-updater'
7+
'Magento_ConfigurableProduct/js/options-updater',
8+
'jquery/ui'
49
], function ($, Updater) {
510
'use strict';
611

7-
var selectors = {
8-
formSelector: '#product_addtocart_form',
9-
swatchSelector: '.swatch-opt'
12+
$.widget('mage.selectSwatch', {
13+
options: {
14+
swatchOptions: null,
15+
selectors: {
16+
formSelector: '#product_addtocart_form',
17+
swatchSelector: '.swatch-opt'
18+
},
19+
swatchWidgetName: 'mageSwatchRenderer',
20+
widgetInitEvent: 'swatch.initialized',
21+
clickEventName: 'emulateClick'
1022
},
11-
swatchWidgetName = 'mageSwatchRenderer',
12-
widgetInitEvent = 'swatch.initialized',
1323

14-
/**
15-
* Sets all configurable swatch attribute's selected values
16-
*/
17-
updateSwatchOptions = function () {
18-
var swatchWidget = $(selectors.swatchSelector).data(swatchWidgetName);
24+
/**
25+
* Widget initialisation.
26+
* Configurable product options updater listens to selected swatch options
27+
*/
28+
_init: function () {
29+
var updater;
1930

20-
if (!swatchWidget || !swatchWidget._EmulateSelectedByAttributeId) {
21-
return;
31+
updater = new Updater(this.options.widgetInitEvent, this.selectDefaultSwatchOptions.bind(this));
32+
updater.listen();
33+
},
34+
35+
/**
36+
* Sets default configurable swatch attribute's selected
37+
*/
38+
selectDefaultSwatchOptions: function () {
39+
var swatchWidget = $(this.options.selectors.swatchSelector).data(this.options.swatchWidgetName);
40+
41+
if (!swatchWidget || !swatchWidget._EmulateSelectedByAttributeId) {
42+
return;
43+
}
44+
swatchWidget._EmulateSelectedByAttributeId(
45+
this.options.swatchOptions.defaultValues, this.options.clickEventName
46+
);
2247
}
23-
swatchWidget._EmulateSelectedByAttributeId(this.productOptions);
24-
},
25-
updater = new Updater(widgetInitEvent, updateSwatchOptions);
48+
});
2649

27-
updater.listen();
50+
return $.mage.selectSwatch;
2851
});

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

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,10 @@ define([
616616
return $widget._OnClick($(this), $widget);
617617
});
618618

619+
$widget.element.on('emulateClick', '.' + options.optionClass, function () {
620+
return $widget._OnClick($(this), $widget, 'emulateClick');
621+
});
622+
619623
$widget.element.on('change', '.' + options.selectClass, function () {
620624
return $widget._OnChange($(this), $widget);
621625
});
@@ -646,9 +650,10 @@ define([
646650
/**
647651
* Load media gallery using ajax or json config.
648652
*
653+
* @param {String|undefined} eventName
649654
* @private
650655
*/
651-
_loadMedia: function () {
656+
_loadMedia: function (eventName) {
652657
var $main = this.inProductList ?
653658
this.element.parents('.product-item-info') :
654659
this.element.parents('.column.main'),
@@ -663,7 +668,7 @@ define([
663668
images = this.options.mediaGalleryInitial;
664669
}
665670

666-
this.updateBaseImage(images, $main, !this.inProductList);
671+
this.updateBaseImage(images, $main, !this.inProductList, eventName);
667672
}
668673
},
669674

@@ -672,9 +677,10 @@ define([
672677
*
673678
* @param {Object} $this
674679
* @param {Object} $widget
680+
* @param {String|undefined} eventName
675681
* @private
676682
*/
677-
_OnClick: function ($this, $widget) {
683+
_OnClick: function ($this, $widget, eventName) {
678684
var $parent = $this.parents('.' + $widget.options.classes.attributeClass),
679685
$wrapper = $this.parents('.' + $widget.options.classes.attributeOptionsWrapper),
680686
$label = $parent.find('.' + $widget.options.classes.attributeSelectedOptionLabelClass),
@@ -713,7 +719,7 @@ define([
713719
$widget._UpdatePrice();
714720
}
715721

716-
$widget._loadMedia();
722+
$widget._loadMedia(eventName);
717723
$input.trigger('change');
718724
},
719725

@@ -1117,16 +1123,36 @@ define([
11171123
return images;
11181124
},
11191125

1126+
/**
1127+
* Start update base image process based on event name
1128+
* @param {Array} images
1129+
* @param {jQuery} context
1130+
* @param {Boolean} isInProductView
1131+
* @param {String|undefined} eventName
1132+
*/
1133+
updateBaseImage: function (images, context, isInProductView, eventName) {
1134+
var gallery = context.find(this.options.mediaGallerySelector).data('gallery');
1135+
1136+
if (eventName === undefined) {
1137+
this.processUpdateBaseImage(images, context, isInProductView, gallery);
1138+
} else {
1139+
context.find(this.options.mediaGallerySelector).on('gallery:loaded', function (loadedGallery) {
1140+
loadedGallery = context.find(this.options.mediaGallerySelector).data('gallery');
1141+
this.processUpdateBaseImage(images, context, isInProductView, loadedGallery);
1142+
}.bind(this));
1143+
}
1144+
},
1145+
11201146
/**
11211147
* Update [gallery-placeholder] or [product-image-photo]
11221148
* @param {Array} images
11231149
* @param {jQuery} context
11241150
* @param {Boolean} isInProductView
1151+
* @param {Object} gallery
11251152
*/
1126-
updateBaseImage: function (images, context, isInProductView) {
1153+
processUpdateBaseImage: function (images, context, isInProductView, gallery) {
11271154
var justAnImage = images[0],
11281155
initialImages = this.options.mediaGalleryInitial,
1129-
gallery = context.find(this.options.mediaGallerySelector).data('gallery'),
11301156
imagesToUpdate,
11311157
isInitial;
11321158

@@ -1203,14 +1229,19 @@ define([
12031229
/**
12041230
* Emulate mouse click or selection change on all swatches that should be selected
12051231
* @param {Object} [selectedAttributes]
1232+
* @param {String} triggerClick
12061233
* @private
12071234
*/
1208-
_EmulateSelectedByAttributeId: function (selectedAttributes) {
1235+
_EmulateSelectedByAttributeId: function (selectedAttributes, triggerClick) {
12091236
$.each(selectedAttributes, $.proxy(function (attributeId, optionId) {
12101237
var elem = this.element.find('.' + this.options.classes.attributeClass +
12111238
'[attribute-id="' + attributeId + '"] [option-id="' + optionId + '"]'),
12121239
parentInput = elem.parent();
12131240

1241+
if (triggerClick === null || triggerClick === '') {
1242+
triggerClick = 'click';
1243+
}
1244+
12141245
if (elem.hasClass('selected')) {
12151246
return;
12161247
}
@@ -1219,7 +1250,7 @@ define([
12191250
parentInput.val(optionId);
12201251
parentInput.trigger('change');
12211252
} else {
1222-
elem.trigger('click');
1253+
elem.trigger(triggerClick);
12231254
}
12241255
}, this));
12251256
},

0 commit comments

Comments
 (0)