Skip to content

Commit

Permalink
Merge pull request #666 from magento-tsg/2.0-develop-pr4
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.0 (pr4)
  • Loading branch information
Yaroslav Onischenko authored Dec 13, 2016
2 parents 809c7c3 + 150b020 commit 3d7e5bc
Show file tree
Hide file tree
Showing 49 changed files with 2,325 additions and 496 deletions.
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/AbstractProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function __construct(\Magento\Catalog\Block\Product\Context $context, arr
*/
public function getAddToCartUrl($product, $additional = [])
{
if ($product->getTypeInstance()->hasRequiredOptions($product)) {
if (!$product->getTypeInstance()->isPossibleBuyFromList($product)) {
if (!isset($additional['_escape'])) {
$additional['_escape'] = true;
}
Expand Down
11 changes: 11 additions & 0 deletions app/code/Magento/Catalog/Model/Product/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -1070,4 +1070,15 @@ public function getAssociatedProducts($product)
{
return [];
}

/**
* Check if product can be potentially buyed from the category page or some other list.
*
* @param \Magento\Catalog\Model\Product $product
* @return bool
*/
public function isPossibleBuyFromList($product)
{
return !$this->hasRequiredOptions($product);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ public function testGetAddToCartPostParams()
];

$this->typeInstanceMock->expects($this->once())
->method('hasRequiredOptions')
->method('isPossibleBuyFromList')
->with($this->equalTo($this->productMock))
->will($this->returnValue(false));
->will($this->returnValue(true));
$this->cartHelperMock->expects($this->any())
->method('getAddUrl')
->with($this->equalTo($this->productMock), $this->equalTo([]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ define([
}

if (res.backUrl) {
var eventData = {
'form': form,
'redirectParameters': []
};

// trigger global event, so other modules will be able add parameters to redirect url
$('body').trigger('catalogCategoryAddToCartRedirect', eventData);
if (eventData.redirectParameters.length > 0) {
var parameters = res.backUrl.split('#');
parameters.push(eventData.redirectParameters.join('&'));
res.backUrl = parameters.join('#');
}
window.location = res.backUrl;
return;
}
Expand Down Expand Up @@ -120,4 +132,4 @@ define([
});

return $.mage.catalogAddToCart;
});
});
Loading

0 comments on commit 3d7e5bc

Please sign in to comment.