Skip to content

Commit c67d8de

Browse files
committed
Merge branch 'main_develop' into bugfix1
2 parents 85324c7 + e643a67 commit c67d8de

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
@@ -264,6 +264,8 @@ define([
264264
*/
265265
_init: function () {
266266
if (this.options.jsonConfig !== '' && this.options.jsonSwatchConfig !== '') {
267+
// store unsorted attributes
268+
this.options.jsonConfig.mappedAttributes = _.clone(this.options.jsonConfig.attributes);
267269
this._sortAttributes();
268270
this._RenderControls();
269271
$(this.element).trigger('swatch.initialized');
@@ -617,6 +619,7 @@ define([
617619
$parent.attr('option-selected', $this.attr('option-id')).find('.selected').removeClass('selected');
618620
$label.text($this.attr('option-label'));
619621
$input.val($this.attr('option-id'));
622+
$input.attr('data-attr-name', this._getAttributeCodeById(attributeId));
620623
$this.addClass('selected');
621624
$widget._toggleCheckedAttributes($this, $wrapper);
622625
}
@@ -633,6 +636,19 @@ define([
633636
$input.trigger('change');
634637
},
635638

639+
/**
640+
* Get human readable attribute code (eg. size, color) by it ID from configuration
641+
*
642+
* @param {Number} attributeId
643+
* @returns {*}
644+
* @private
645+
*/
646+
_getAttributeCodeById: function (attributeId) {
647+
var attribute = this.options.jsonConfig.mappedAttributes[attributeId];
648+
649+
return attribute ? attribute.code : attributeId;
650+
},
651+
636652
/**
637653
* Toggle accessibility attributes
638654
*
@@ -1104,7 +1120,7 @@ define([
11041120
params = $.parseQuery(window.location.href.substr(hashIndex + 1));
11051121

11061122
selectedAttributes = _.invert(_.mapObject(_.invert(params), function (attributeId) {
1107-
var attribute = this.options.jsonConfig.attributes[attributeId];
1123+
var attribute = this.options.jsonConfig.mappedAttributes[attributeId];
11081124

11091125
return attribute ? attribute.code : attributeId;
11101126
}.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)