Skip to content

Commit 7a69b8f

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-47017' into troll_bugfix
2 parents 9130f67 + e8c210f commit 7a69b8f

File tree

32 files changed

+1033
-15
lines changed

32 files changed

+1033
-15
lines changed

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/Catalog/Test/Handler/CatalogProductAttribute/Curl.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ class Curl extends AbstractCurl implements CatalogProductAttributeInterface
4747
'No' => 0,
4848
'Yes' => 1,
4949
],
50+
'is_global' => [
51+
'Store View' => '0',
52+
'Global' => '1',
53+
],
54+
'used_in_product_listing' => [
55+
'No' => '0',
56+
'Yes' => '1',
57+
],
5058
];
5159

5260
/**
@@ -76,6 +84,7 @@ public function persist(FixtureInterface $fixture = null)
7684
unset($data['options']);
7785
}
7886

87+
$data = $this->changeStructureOfTheData($data);
7988
$url = $_ENV['app_backend_url'] . 'catalog/product_attribute/save/back/edit';
8089
$curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
8190
$curl->write($url, $data);
@@ -104,4 +113,13 @@ public function persist(FixtureInterface $fixture = null)
104113

105114
return $resultData;
106115
}
116+
117+
/**
118+
* @param array $data
119+
* @return array
120+
*/
121+
protected function changeStructureOfTheData(array $data)
122+
{
123+
return $data;
124+
}
107125
}

dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Handler/ConfigurableProduct/Curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ protected function prepareConfigurableMatrix(FixtureInterface $product)
172172
$keyIds[] = $attribute['options'][$optionKey]['id'];
173173
$configurableAttribute[] = sprintf(
174174
'"%s":"%s"',
175-
$attribute['attribute_code'],
175+
isset($attribute['attribute_code']) ? $attribute['attribute_code'] : $attribute['frontend_label'],
176176
$attribute['options'][$optionKey]['id']
177177
);
178178
}

0 commit comments

Comments
 (0)