Skip to content

Commit 91b9091

Browse files
author
Konosov, Andrey(akonosov)
committed
Merge pull request #493 from akonosov/MAGETWO-39139
[MX] GitHub
2 parents 0bb5b8c + f03bd5b commit 91b9091

File tree

49 files changed

+579
-110
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

+579
-110
lines changed

app/code/Magento/Catalog/Block/Product/ProductList/Related.php

Lines changed: 15 additions & 0 deletions
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
}

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Framework\Api\Data\ImageContentInterfaceFactory;
1414
use Magento\Framework\Api\ImageContentValidatorInterface;
1515
use Magento\Framework\Api\ImageProcessorInterface;
16-
use Magento\Framework\Api\SearchCriteriaInterface;
1716
use Magento\Framework\Api\SortOrder;
1817
use Magento\Framework\Exception\InputException;
1918
use Magento\Framework\Exception\NoSuchEntityException;
@@ -658,7 +657,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCr
658657
$field = $sortOrder->getField();
659658
$collection->addOrder(
660659
$field,
661-
($sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC) ? 'ASC' : 'DESC'
660+
($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
662661
);
663662
}
664663
$collection->setCurPage($searchCriteria->getCurrentPage());

app/code/Magento/Catalog/Model/Resource/Product/Collection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1312,7 +1312,7 @@ protected function _addUrlRewrite()
13121312
$select = $this->getConnection()
13131313
->select()
13141314
->from(['u' => $this->getTable('url_rewrite')], ['u.entity_id', 'u.request_path'])
1315-
->where('u.store_id = ?', $this->_storeManager->getStore()->getId())
1315+
->where('u.store_id = ?', $this->_storeManager->getStore($this->getStoreId())->getId())
13161316
->where('u.is_autogenerated = 1')
13171317
->where('u.entity_type = ?', ProductUrlRewriteGenerator::ENTITY_TYPE)
13181318
->where('u.entity_id IN(?)', $productIds);

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

Lines changed: 43 additions & 0 deletions
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
}

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Magento\Catalog\Model\Layer\Filter\Dynamic\AlgorithmFactory;
1313
use Magento\Framework\Api\Data\ImageContentInterface;
14+
use Magento\Framework\Api\SortOrder;
1415
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1516
use Magento\Store\Model\ScopeInterface;
1617

@@ -602,7 +603,7 @@ public function testGetList()
602603
$searchCriteriaMock->expects($this->once())->method('getSortOrders')->willReturn([$sortOrderMock]);
603604
$sortOrderMock->expects($this->once())->method('getField')->willReturn('field');
604605
$sortOrderMock->expects($this->once())->method('getDirection')
605-
->willReturn(\Magento\Framework\Api\SearchCriteriaInterface::SORT_ASC);
606+
->willReturn(SortOrder::SORT_ASC);
606607
$collectionMock->expects($this->once())->method('addOrder')->with('field', 'ASC');
607608
$searchCriteriaMock->expects($this->once())->method('getCurrentPage')->willReturn(4);
608609
$collectionMock->expects($this->once())->method('setCurPage')->with(4);

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

Lines changed: 8 additions & 1 deletion
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>

app/code/Magento/Cms/Model/BlockRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Magento\Cms\Api\Data;
99
use Magento\Cms\Api\BlockRepositoryInterface;
1010
use Magento\Framework\Api\DataObjectHelper;
11-
use Magento\Framework\Api\SearchCriteriaInterface;
11+
use Magento\Framework\Api\SortOrder;
1212
use Magento\Framework\Exception\CouldNotDeleteException;
1313
use Magento\Framework\Exception\CouldNotSaveException;
1414
use Magento\Framework\Exception\NoSuchEntityException;
@@ -146,7 +146,7 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria
146146
foreach ($sortOrders as $sortOrder) {
147147
$collection->addOrder(
148148
$sortOrder->getField(),
149-
($sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC) ? 'ASC' : 'DESC'
149+
($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
150150
);
151151
}
152152
}

app/code/Magento/Cms/Model/PageRepository.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
use Magento\Cms\Api\Data;
99
use Magento\Cms\Api\PageRepositoryInterface;
1010
use Magento\Framework\Api\DataObjectHelper;
11-
use Magento\Framework\Api\SearchCriteriaInterface;
11+
use Magento\Framework\Api\SortOrder;
1212
use Magento\Framework\Exception\CouldNotDeleteException;
1313
use Magento\Framework\Exception\CouldNotSaveException;
1414
use Magento\Framework\Exception\NoSuchEntityException;
@@ -143,10 +143,11 @@ public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria
143143
$searchResults->setTotalCount($collection->getSize());
144144
$sortOrders = $criteria->getSortOrders();
145145
if ($sortOrders) {
146+
/** @var SortOrder $sortOrder */
146147
foreach ($sortOrders as $sortOrder) {
147148
$collection->addOrder(
148149
$sortOrder->getField(),
149-
($sortOrder->getDirection() == SearchCriteriaInterface::SORT_ASC) ? 'ASC' : 'DESC'
150+
($sortOrder->getDirection() == SortOrder::SORT_ASC) ? 'ASC' : 'DESC'
150151
);
151152
}
152153
}

app/code/Magento/Cms/Test/Unit/Model/BlockRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Cms\Test\Unit\Model;
77

88
use Magento\Cms\Model\BlockRepository;
9-
use Magento\Framework\Api\SearchCriteriaInterface;
9+
use Magento\Framework\Api\SortOrder;
1010

1111
/**
1212
* Test for Magento\Cms\Model\BlockRepository
@@ -236,7 +236,7 @@ public function testGetList()
236236
$storeFilter->expects($this->any())->method('getField')->willReturn('store_id');
237237
$storeFilter->expects($this->once())->method('getValue')->willReturn(1);
238238
$sortOrder->expects($this->once())->method('getField')->willReturn($sortField);
239-
$sortOrder->expects($this->once())->method('getDirection')->willReturn(SearchCriteriaInterface::SORT_DESC);
239+
$sortOrder->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_DESC);
240240

241241
/** @var \Magento\Framework\Api\SearchCriteriaInterface $criteria */
242242

app/code/Magento/Cms/Test/Unit/Model/PageRepositoryTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Magento\Cms\Test\Unit\Model;
77

88
use Magento\Cms\Model\PageRepository;
9-
use Magento\Framework\Api\SearchCriteriaInterface;
9+
use Magento\Framework\Api\SortOrder;
1010

1111
/**
1212
* Test for Magento\Cms\Model\PageRepository
@@ -236,7 +236,7 @@ public function testGetList()
236236
$storeFilter->expects($this->any())->method('getField')->willReturn('store_id');
237237
$storeFilter->expects($this->once())->method('getValue')->willReturn(1);
238238
$sortOrder->expects($this->once())->method('getField')->willReturn($sortField);
239-
$sortOrder->expects($this->once())->method('getDirection')->willReturn(SearchCriteriaInterface::SORT_DESC);
239+
$sortOrder->expects($this->once())->method('getDirection')->willReturn(SortOrder::SORT_DESC);
240240

241241
/** @var \Magento\Framework\Api\SearchCriteriaInterface $criteria */
242242

0 commit comments

Comments
 (0)