Skip to content

Commit 2595cad

Browse files
committed
Merge remote-tracking branch 'mainline/develop' into pr-develop
2 parents a5baad4 + e643a67 commit 2595cad

File tree

50 files changed

+1511
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1511
-57
lines changed

app/code/Magento/Bundle/view/base/web/js/price-bundle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ define([
295295
case 'hidden':
296296
optionHash = 'bundle-option-' + optionName + '##' + optionValue;
297297
optionQty = optionConfig[optionValue].qty || 0;
298+
canQtyCustomize = optionConfig[optionValue].customQty === '1';
299+
qtyField = element.data('qtyField');
300+
qtyField.data('option', element);
301+
toggleQtyField(qtyField, optionQty, optionId, optionValue, canQtyCustomize);
298302
tempChanges = utils.deepClone(optionConfig[optionValue].prices);
299303
tempChanges = applyTierPrice(tempChanges, optionQty, optionConfig);
300304
tempChanges = applyQty(tempChanges, optionQty);

app/code/Magento/Catalog/Block/Product/AbstractProduct.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function __construct(\Magento\Catalog\Block\Product\Context $context, arr
124124
*/
125125
public function getAddToCartUrl($product, $additional = [])
126126
{
127-
if ($product->getTypeInstance()->hasRequiredOptions($product)) {
127+
if (!$product->getTypeInstance()->isPossibleBuyFromList($product)) {
128128
if (!isset($additional['_escape'])) {
129129
$additional['_escape'] = true;
130130
}

app/code/Magento/Catalog/Model/Product/Type/AbstractType.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,4 +1092,15 @@ public function getAssociatedProducts($product)
10921092
{
10931093
return [];
10941094
}
1095+
1096+
/**
1097+
* Check if product can be potentially buyed from the category page or some other list
1098+
*
1099+
* @param \Magento\Catalog\Model\Product $product
1100+
* @return bool
1101+
*/
1102+
public function isPossibleBuyFromList($product)
1103+
{
1104+
return !$this->hasRequiredOptions($product);
1105+
}
10951106
}

app/code/Magento/Catalog/Test/Unit/Block/Product/ListProductTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,9 @@ public function testGetAddToCartPostParams()
154154
];
155155

156156
$this->typeInstanceMock->expects($this->once())
157-
->method('hasRequiredOptions')
157+
->method('isPossibleBuyFromList')
158158
->with($this->equalTo($this->productMock))
159-
->will($this->returnValue(false));
159+
->will($this->returnValue(true));
160160
$this->cartHelperMock->expects($this->any())
161161
->method('getAddUrl')
162162
->with($this->equalTo($this->productMock), $this->equalTo([]))

app/code/Magento/Catalog/view/frontend/web/js/catalog-add-to-cart.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ define([
8484
}
8585

8686
if (res.backUrl) {
87+
var eventData = {
88+
'form': form,
89+
'redirectParameters': []
90+
}
91+
// trigger global event, so other modules will be able add parameters to redirect url
92+
$('body').trigger('catalogCategoryAddToCartRedirect', eventData);
93+
if (eventData.redirectParameters.length > 0) {
94+
var parameters = res.backUrl.split('#');
95+
parameters.push(eventData.redirectParameters.join('&'));
96+
res.backUrl = parameters.join('#');
97+
}
8798
window.location = res.backUrl;
8899
return;
89100
}

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,4 +1287,19 @@ private function getCatalogConfig()
12871287
}
12881288
return $this->catalogConfig;
12891289
}
1290+
1291+
/**
1292+
* @inheritdoc
1293+
*/
1294+
public function isPossibleBuyFromList($product)
1295+
{
1296+
$isAllCustomOptionsDisplayed = true;
1297+
foreach ($this->getConfigurableAttributes($product) as $attribute) {
1298+
$eavAttribute = $attribute->getProductAttribute();
1299+
1300+
$isAllCustomOptionsDisplayed = ($isAllCustomOptionsDisplayed && $eavAttribute->getUsedInProductListing());
1301+
}
1302+
1303+
return $isAllCustomOptionsDisplayed;
1304+
}
12901305
}

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
<?php /** @var $block \Magento\Swatches\Block\Product\Renderer\Configurable */ ?>
88
<div class="swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>"></div>
99
<script>
10-
require(["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer"], function ($) {
11-
$('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({
12-
selectorProduct: '.product-item-details',
13-
onlySwatches: true,
14-
enableControlLabel: false,
15-
numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>,
16-
jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
17-
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
18-
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
19-
});
10+
require(
11+
["jquery", "jquery/ui", "Magento_Swatches/js/swatch-renderer", "Magento_Swatches/js/catalog-add-to-cart"],
12+
function ($) {
13+
$('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({
14+
selectorProduct: '.product-item-details',
15+
onlySwatches: true,
16+
enableControlLabel: false,
17+
numberToShow: <?php /* @escapeNotVerified */ echo $block->getNumberSwatchesPerProduct(); ?>,
18+
jsonConfig: <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
19+
jsonSwatchConfig: <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
20+
mediaCallback: '<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>'
21+
});
2022
});
2123
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright © 2016 Magento. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
require([
6+
'jquery'
7+
], function ($) {
8+
'use strict';
9+
10+
$('body').on('catalogCategoryAddToCartRedirect', function (event, data) {
11+
$(data.form).find('[name*="super"]').each(function (index, item) {
12+
var $item = $(item);
13+
14+
data.redirectParameters.push($item.attr('data-attr-name') + '=' + $item.val());
15+
});
16+
});
17+
});

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ define([
271271
*/
272272
_init: function () {
273273
if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
274+
// store unsorted attributes
275+
this.options.jsonConfig.mappedAttributes = _.clone(this.options.jsonConfig.attributes);
274276
this._sortAttributes();
275277
this._RenderControls();
276278
$(this.element).trigger('swatch.initialized');
@@ -622,6 +624,7 @@ define([
622624
$parent.attr('option-selected', $this.attr('option-id')).find('.selected').removeClass('selected');
623625
$label.text($this.attr('option-label'));
624626
$input.val($this.attr('option-id'));
627+
$input.attr('data-attr-name', this._getAttributeCodeById(attributeId));
625628
$this.addClass('selected');
626629
$widget._toggleCheckedAttributes($this, $wrapper);
627630
}
@@ -638,6 +641,19 @@ define([
638641
$input.trigger('change');
639642
},
640643

644+
/**
645+
* Get human readable attribute code (eg. size, color) by it ID from configuration
646+
*
647+
* @param {Number} attributeId
648+
* @returns {*}
649+
* @private
650+
*/
651+
_getAttributeCodeById: function (attributeId) {
652+
var attribute = this.options.jsonConfig.mappedAttributes[attributeId];
653+
654+
return attribute ? attribute.code : attributeId;
655+
},
656+
641657
/**
642658
* Toggle accessibility attributes
643659
*
@@ -1110,7 +1126,7 @@ define([
11101126
params = $.parseQuery(window.location.href.substr(hashIndex + 1));
11111127

11121128
selectedAttributes = _.invert(_.mapObject(_.invert(params), function (attributeId) {
1113-
var attribute = this.options.jsonConfig.attributes[attributeId];
1129+
var attribute = this.options.jsonConfig.mappedAttributes[attributeId];
11141130

11151131
return attribute ? attribute.code : attributeId;
11161132
}.bind(this)));

dev/tests/functional/tests/app/Magento/Bundle/Test/Block/Adminhtml/Catalog/Product/Edit/Section/Bundle/Option/Selection.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
<selection_qty>
2222
<selector>[name$='[selection_qty]']</selector>
2323
</selection_qty>
24+
<user_defined>
25+
<selector>[name$='[selection_can_change_qty]']</selector>
26+
<input>checkbox</input>
27+
</user_defined>
2428
<getProductName>
2529
<selector>span[data-index="name"]</selector>
2630
</getProductName>

0 commit comments

Comments
 (0)