Skip to content

Commit

Permalink
MAGETWO-30468: [GitHub] Related products not able to add to cart #1279
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Rad committed Jul 23, 2015
1 parent 5e8b706 commit bce4179
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
15 changes: 15 additions & 0 deletions app/code/Magento/Catalog/Block/Product/ProductList/Related.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,19 @@ public function getIdentities()
}
return $identities;
}

/**
* Find out if some products can be easy added to cart
*
* @return bool
*/
public function canItemsAddToCart()
{
foreach ($this->getItems() as $item) {
if (!$item->isComposite() && $item->isSaleable() && !$item->getRequiredOptions()) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,47 @@ public function testGetIdentities()
$this->block->getIdentities()
);
}

/**
* @dataProvider canItemsAddToCartDataProvider
* @param bool $isComposite
* @param bool $isSaleable
* @param bool $hasRequiredOptions
* @param bool $canItemsAddToCart
*/
public function testCanItemsAddToCart($isComposite, $isSaleable, $hasRequiredOptions, $canItemsAddToCart)
{
$product = $this->getMock(
'Magento\Catalog\Model\Product',
['isComposite', 'isSaleable', 'getRequiredOptions'],
[],
'',
false
);
$product->expects($this->any())->method('isComposite')->willReturn($isComposite);
$product->expects($this->any())->method('isSaleable')->willReturn($isSaleable);
$product->expects($this->any())->method('getRequiredOptions')->willReturn($hasRequiredOptions);

$itemsCollection = new \ReflectionProperty(
'Magento\Catalog\Block\Product\ProductList\Related',
'_itemCollection'
);
$itemsCollection->setAccessible(true);
$itemsCollection->setValue($this->block, [$product]);

$this->assertEquals(
$canItemsAddToCart,
$this->block->canItemsAddToCart()
);
}

public function canItemsAddToCartDataProvider()
{
return [
[false, true, false, true],
[false, false, false, false],
[true, false, false, false],
[true, false, true, false],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ switch ($type = $block->getType()) {
$items = $block->getAllItems();
$limit = $block->getPositionLimit();
$shuffle = (int) $block->isShuffled();
$canItemsAddToCart = $block->canItemsAddToCart();

$showWishlist = true;
$showCompare = true;
Expand All @@ -44,6 +45,7 @@ switch ($type = $block->getType()) {
$items = $block->getItems();
$limit = 0;
$shuffle = 0;
$canItemsAddToCart = $block->canItemsAddToCart();

$showWishlist = true;
$showCompare = true;
Expand All @@ -70,6 +72,7 @@ switch ($type = $block->getType()) {
$showCart = false;
$templateType = null;
$description = false;
$canItemsAddToCart = false;
}
break;

Expand All @@ -91,6 +94,7 @@ switch ($type = $block->getType()) {
$showCart = false;
$templateType = null;
$description = false;
$canItemsAddToCart = false;
}
break;

Expand All @@ -110,6 +114,7 @@ switch ($type = $block->getType()) {
$showCart = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
$description = false;
$canItemsAddToCart = false;
}
break;

Expand All @@ -129,6 +134,7 @@ switch ($type = $block->getType()) {
$showCart = true;
$templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
$description = false;
$canItemsAddToCart = false;
}
break;

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

Expand All @@ -173,7 +180,7 @@ switch ($type = $block->getType()) {
<strong id="block-<?php echo $class?>-heading" role="heading" aria-level="2"><?php echo $title; ?></strong>
</div>
<div class="block-content content" aria-labelledby="block-<?php echo $class?>-heading">
<?php if ($type == 'related'): ?>
<?php if ($type == 'related' && $canItemsAddToCart): ?>
<div class="block-actions">
<?php echo __('Check items to add to the cart or') ?>
<button type="button" class="action select" role="select-all"><span><?php echo __('select all') ?></span></button>
Expand Down
2 changes: 0 additions & 2 deletions app/design/frontend/Magento/luma/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
"Items %1-%2 of %3","%3 items"
"Regular Price", "was"
"Shop By","Filter"
"select all", "Add all"
"unselect all", "Select none"
"Remove item", "Remove"
"Proceed to Checkout", "Go to Checkout"
"Grand Total", "Estimated Total"
Expand Down

0 comments on commit bce4179

Please sign in to comment.