Skip to content

Commit bce4179

Browse files
author
Victor Rad
committed
MAGETWO-30468: [GitHub] Related products not able to add to cart #1279
1 parent 5e8b706 commit bce4179

File tree

4 files changed

+66
-3
lines changed

4 files changed

+66
-3
lines changed

Diff for: app/code/Magento/Catalog/Block/Product/ProductList/Related.php

+15
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,19 @@ public function getIdentities()
131131
}
132132
return $identities;
133133
}
134+
135+
/**
136+
* Find out if some products can be easy added to cart
137+
*
138+
* @return bool
139+
*/
140+
public function canItemsAddToCart()
141+
{
142+
foreach ($this->getItems() as $item) {
143+
if (!$item->isComposite() && $item->isSaleable() && !$item->getRequiredOptions()) {
144+
return true;
145+
}
146+
}
147+
return false;
148+
}
134149
}

Diff for: app/code/Magento/Catalog/Test/Unit/Block/Product/ProductList/RelatedTest.php

+43
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,47 @@ public function testGetIdentities()
4141
$this->block->getIdentities()
4242
);
4343
}
44+
45+
/**
46+
* @dataProvider canItemsAddToCartDataProvider
47+
* @param bool $isComposite
48+
* @param bool $isSaleable
49+
* @param bool $hasRequiredOptions
50+
* @param bool $canItemsAddToCart
51+
*/
52+
public function testCanItemsAddToCart($isComposite, $isSaleable, $hasRequiredOptions, $canItemsAddToCart)
53+
{
54+
$product = $this->getMock(
55+
'Magento\Catalog\Model\Product',
56+
['isComposite', 'isSaleable', 'getRequiredOptions'],
57+
[],
58+
'',
59+
false
60+
);
61+
$product->expects($this->any())->method('isComposite')->willReturn($isComposite);
62+
$product->expects($this->any())->method('isSaleable')->willReturn($isSaleable);
63+
$product->expects($this->any())->method('getRequiredOptions')->willReturn($hasRequiredOptions);
64+
65+
$itemsCollection = new \ReflectionProperty(
66+
'Magento\Catalog\Block\Product\ProductList\Related',
67+
'_itemCollection'
68+
);
69+
$itemsCollection->setAccessible(true);
70+
$itemsCollection->setValue($this->block, [$product]);
71+
72+
$this->assertEquals(
73+
$canItemsAddToCart,
74+
$this->block->canItemsAddToCart()
75+
);
76+
}
77+
78+
public function canItemsAddToCartDataProvider()
79+
{
80+
return [
81+
[false, true, false, true],
82+
[false, false, false, false],
83+
[true, false, false, false],
84+
[true, false, true, false],
85+
];
86+
}
4487
}

Diff for: app/code/Magento/Catalog/view/frontend/templates/product/list/items.phtml

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ switch ($type = $block->getType()) {
2323
$items = $block->getAllItems();
2424
$limit = $block->getPositionLimit();
2525
$shuffle = (int) $block->isShuffled();
26+
$canItemsAddToCart = $block->canItemsAddToCart();
2627

2728
$showWishlist = true;
2829
$showCompare = true;
@@ -44,6 +45,7 @@ switch ($type = $block->getType()) {
4445
$items = $block->getItems();
4546
$limit = 0;
4647
$shuffle = 0;
48+
$canItemsAddToCart = $block->canItemsAddToCart();
4749

4850
$showWishlist = true;
4951
$showCompare = true;
@@ -70,6 +72,7 @@ switch ($type = $block->getType()) {
7072
$showCart = false;
7173
$templateType = null;
7274
$description = false;
75+
$canItemsAddToCart = false;
7376
}
7477
break;
7578

@@ -91,6 +94,7 @@ switch ($type = $block->getType()) {
9194
$showCart = false;
9295
$templateType = null;
9396
$description = false;
97+
$canItemsAddToCart = false;
9498
}
9599
break;
96100

@@ -110,6 +114,7 @@ switch ($type = $block->getType()) {
110114
$showCart = true;
111115
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
112116
$description = false;
117+
$canItemsAddToCart = false;
113118
}
114119
break;
115120

@@ -129,6 +134,7 @@ switch ($type = $block->getType()) {
129134
$showCart = true;
130135
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
131136
$description = false;
137+
$canItemsAddToCart = false;
132138
}
133139
break;
134140

@@ -150,6 +156,7 @@ switch ($type = $block->getType()) {
150156
$showCart = true;
151157
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
152158
$description = ($mode == 'list') ? true : false;
159+
$canItemsAddToCart = false;
153160
}
154161
break;
155162

@@ -173,7 +180,7 @@ switch ($type = $block->getType()) {
173180
<strong id="block-<?php echo $class?>-heading" role="heading" aria-level="2"><?php echo $title; ?></strong>
174181
</div>
175182
<div class="block-content content" aria-labelledby="block-<?php echo $class?>-heading">
176-
<?php if ($type == 'related'): ?>
183+
<?php if ($type == 'related' && $canItemsAddToCart): ?>
177184
<div class="block-actions">
178185
<?php echo __('Check items to add to the cart or') ?>
179186
<button type="button" class="action select" role="select-all"><span><?php echo __('select all') ?></span></button>

Diff for: app/design/frontend/Magento/luma/i18n/en_US.csv

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
"Items %1-%2 of %3","%3 items"
66
"Regular Price", "was"
77
"Shop By","Filter"
8-
"select all", "Add all"
9-
"unselect all", "Select none"
108
"Remove item", "Remove"
119
"Proceed to Checkout", "Go to Checkout"
1210
"Grand Total", "Estimated Total"

0 commit comments

Comments
 (0)