Skip to content

Commit 5c880a5

Browse files
committed
Merge branch 'MAGETWO-58504' into 2.0-develop-pr4
2 parents 19cef2f + 278e8d9 commit 5c880a5

File tree

33 files changed

+1565
-213
lines changed

33 files changed

+1565
-213
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
@@ -1070,4 +1070,15 @@ public function getAssociatedProducts($product)
10701070
{
10711071
return [];
10721072
}
1073+
1074+
/**
1075+
* Check if product can be potentially buyed from the category page or some other list.
1076+
*
1077+
* @param \Magento\Catalog\Model\Product $product
1078+
* @return bool
1079+
*/
1080+
public function isPossibleBuyFromList($product)
1081+
{
1082+
return !$this->hasRequiredOptions($product);
1083+
}
10731084
}

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

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

150150
$this->typeInstanceMock->expects($this->once())
151-
->method('hasRequiredOptions')
151+
->method('isPossibleBuyFromList')
152152
->with($this->equalTo($this->productMock))
153-
->will($this->returnValue(false));
153+
->will($this->returnValue(true));
154154
$this->cartHelperMock->expects($this->any())
155155
->method('getAddUrl')
156156
->with($this->equalTo($this->productMock), $this->equalTo([]))

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,18 @@ define([
7575
}
7676

7777
if (res.backUrl) {
78+
var eventData = {
79+
'form': form,
80+
'redirectParameters': []
81+
};
82+
83+
// trigger global event, so other modules will be able add parameters to redirect url
84+
$('body').trigger('catalogCategoryAddToCartRedirect', eventData);
85+
if (eventData.redirectParameters.length > 0) {
86+
var parameters = res.backUrl.split('#');
87+
parameters.push(eventData.redirectParameters.join('&'));
88+
res.backUrl = parameters.join('#');
89+
}
7890
window.location = res.backUrl;
7991
return;
8092
}
@@ -120,4 +132,4 @@ define([
120132
});
121133

122134
return $.mage.catalogAddToCart;
123-
});
135+
});

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,4 +1185,23 @@ public function setImageFromChildProduct(\Magento\Catalog\Model\Product $product
11851185
}
11861186
return parent::setImageFromChildProduct($product);
11871187
}
1188+
1189+
/**
1190+
* @inheritdoc
1191+
*/
1192+
public function isPossibleBuyFromList($product)
1193+
{
1194+
$isAllCustomOptionsDisplayed = true;
1195+
1196+
foreach ($this->getConfigurableAttributes($product) as $attribute) {
1197+
$eavAttribute = $attribute->getProductAttribute();
1198+
1199+
$isAllCustomOptionsDisplayed = (
1200+
$isAllCustomOptionsDisplayed
1201+
&& $eavAttribute->getData('used_in_product_listing')
1202+
);
1203+
}
1204+
1205+
return $isAllCustomOptionsDisplayed;
1206+
}
11881207
}

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
@@ -7,7 +7,7 @@
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/swatchRenderer"], function ($) {
10+
require(["jquery", "jquery/ui", "Magento_Swatches/js/SwatchRenderer", "Magento_Swatches/js/catalog-add-to-cart"], function ($) {
1111
$('.swatch-opt-<?php /* @escapeNotVerified */ echo $block->getProduct()->getId() ?>').SwatchRenderer({
1212
selectorProduct: '.product-item-details',
1313
onlySwatches: true,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<script type="text/x-magento-init">
1111
{
1212
"[data-role=swatch-options]": {
13-
"Magento_Swatches/js/swatchRenderer": {
13+
"Magento_Swatches/js/SwatchRenderer": {
1414
"jsonConfig": <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?>,
1515
"jsonSwatchConfig": <?php /* @escapeNotVerified */ echo $block->getJsonSwatchConfig(); ?>,
1616
"mediaCallback": "<?php /* @escapeNotVerified */ echo $block->getMediaCallback() ?>"

0 commit comments

Comments
 (0)