Skip to content

Commit 12d3d89

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-58503' into 2.1-develop-pr36
2 parents 1c6d457 + 6882cec commit 12d3d89

File tree

26 files changed

+894
-19
lines changed

26 files changed

+894
-19
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: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,4 +1092,16 @@ public function getAssociatedProducts($product)
10921092
{
10931093
return [];
10941094
}
1095+
1096+
/**
1097+
* Check if product can be potentially buyed from the category page or some
1098+
* other list
1099+
*
1100+
* @param \Magento\Catalog\Model\Product $product
1101+
* @return bool
1102+
*/
1103+
public function isPossibleBuyFromList($product)
1104+
{
1105+
return !$this->hasRequiredOptions($product);
1106+
}
10951107
}

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

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

197197
$this->typeInstanceMock->expects($this->once())
198-
->method('hasRequiredOptions')
198+
->method('isPossibleBuyFromList')
199199
->with($this->equalTo($this->productMock))
200-
->will($this->returnValue(false));
200+
->will($this->returnValue(true));
201201
$this->cartHelperMock->expects($this->any())
202202
->method('getAddUrl')
203203
->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
@@ -86,6 +86,17 @@ define([
8686
}
8787

8888
if (res.backUrl) {
89+
var eventData = {
90+
'form': form,
91+
'redirectParameters': []
92+
}
93+
// trigger global event, so other modules will be able add parameters to redirect url
94+
$('body').trigger('catalogCategoryAddToCartRedirect', eventData);
95+
if (eventData.redirectParameters.length > 0) {
96+
var parameters = res.backUrl.split('#');
97+
parameters.push(eventData.redirectParameters.join('&'));
98+
res.backUrl = parameters.join('#');
99+
}
89100
window.location = res.backUrl;
90101
return;
91102
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,4 +1488,25 @@ public function getSalableUsedProducts(Product $product, $requiredAttributeIds =
14881488

14891489
return $usedSalableProducts;
14901490
}
1491+
1492+
/**
1493+
* @inheritdoc
1494+
*/
1495+
public function isPossibleBuyFromList($product)
1496+
{
1497+
/** @var bool $isAllCustomOptionsDisplayed */
1498+
$isAllCustomOptionsDisplayed = true;
1499+
1500+
foreach ($this->getConfigurableAttributes($product) as $attribute) {
1501+
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $eavAttribute */
1502+
$eavAttribute = $attribute->getProductAttribute();
1503+
1504+
$isAllCustomOptionsDisplayed = (
1505+
$isAllCustomOptionsDisplayed
1506+
&& $eavAttribute->getData('used_in_product_listing')
1507+
);
1508+
}
1509+
1510+
return $isAllCustomOptionsDisplayed;
1511+
}
14911512
}

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\Listing\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() ?>'
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+
});
1922
});
20-
});
2123
</script>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Copyright © 2013-2017 Magento, Inc. 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+
});

dev/tests/functional/tests/app/Magento/Catalog/Test/Page/Category/CatalogCategoryView.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@
1515
<block name="listProductBlock" class="Magento\Catalog\Test\Block\Product\ListProduct" locator=".products.wrapper.grid" strategy="css selector"/>
1616
<block name="topToolbar" class="Magento\Catalog\Test\Block\Product\ProductList\TopToolbar" locator=".//*[contains(@class,'toolbar-products')][1]" strategy="xpath"/>
1717
<block name="bottomToolbar" class="Magento\Catalog\Test\Block\Product\ProductList\BottomToolbar" locator=".//*[contains(@class,'toolbar-products')][2]" strategy="xpath"/>
18+
<block name="messagesBlock" class="Magento\Backend\Test\Block\Messages" locator=".page.messages" strategy="css selector" />
1819
</page>
1920
</config>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Checkout\Test\TestStep;
8+
9+
use Magento\Checkout\Test\Page\CheckoutCart;
10+
use Magento\Mtf\TestStep\TestStepInterface;
11+
12+
/**
13+
* Clear shopping cart.
14+
*/
15+
class ClearShoppingCartStep implements TestStepInterface
16+
{
17+
/**
18+
* Page of checkout page.
19+
*
20+
* @var CheckoutCart
21+
*/
22+
private $checkoutCart;
23+
24+
/**
25+
* @param CheckoutCart $checkoutCart
26+
*/
27+
public function __construct(CheckoutCart $checkoutCart)
28+
{
29+
$this->checkoutCart = $checkoutCart;
30+
}
31+
32+
/**
33+
* Clear shopping cart.
34+
*
35+
* @return void
36+
*/
37+
public function run()
38+
{
39+
$this->checkoutCart->open()->getCartBlock()->clearShoppingCart();
40+
}
41+
}

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
@@ -152,7 +152,7 @@ protected function prepareConfigurableMatrix(FixtureInterface $product)
152152
$keyIds[] = $attribute['options'][$optionKey]['id'];
153153
$configurableAttribute[] = sprintf(
154154
'"%s":"%s"',
155-
$attribute['attribute_code'],
155+
isset($attribute['attribute_code']) ? $attribute['attribute_code'] : $attribute['frontend_label'],
156156
$attribute['options'][$optionKey]['id']
157157
);
158158
}

0 commit comments

Comments
 (0)