Skip to content

Commit 3d7e5bc

Browse files
author
Yaroslav Onischenko
authored
Merge pull request #666 from magento-tsg/2.0-develop-pr4
[TSG] Backporting for 2.0 (pr4)
2 parents 809c7c3 + 150b020 commit 3d7e5bc

File tree

49 files changed

+2325
-496
lines changed

Some content is hidden

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

49 files changed

+2325
-496
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+
});

0 commit comments

Comments
 (0)