Skip to content

Commit 10e98bb

Browse files
[EngCom] Public Pull Requests - 2.3-develop
- merged latest code from mainline branch
2 parents 94442d3 + e2ca112 commit 10e98bb

File tree

73 files changed

+2314
-283
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+2314
-283
lines changed

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ private function getDefaultListingMode()
178178
}
179179

180180
/**
181-
* Need use as _prepareLayout - but problem in declaring collection from
182-
* another block (was problem with search result)
181+
* Need use as _prepareLayout - but problem in declaring collection from another block.
182+
* (was problem with search result)
183+
*
183184
* @return $this
184185
*/
185186
protected function _beforeToHtml()
@@ -188,7 +189,9 @@ protected function _beforeToHtml()
188189

189190
$this->addToolbarBlock($collection);
190191

191-
$collection->load();
192+
if (!$collection->isLoaded()) {
193+
$collection->load();
194+
}
192195

193196
return parent::_beforeToHtml();
194197
}
@@ -262,6 +265,8 @@ public function getToolbarHtml()
262265
}
263266

264267
/**
268+
* Set collection.
269+
*
265270
* @param AbstractCollection $collection
266271
* @return $this
267272
*/
@@ -272,7 +277,9 @@ public function setCollection($collection)
272277
}
273278

274279
/**
275-
* @param array|string|integer| Element $code
280+
* Add attribute.
281+
*
282+
* @param array|string|integer|Element $code
276283
* @return $this
277284
*/
278285
public function addAttribute($code)
@@ -282,6 +289,8 @@ public function addAttribute($code)
282289
}
283290

284291
/**
292+
* Get price block template.
293+
*
285294
* @return mixed
286295
*/
287296
public function getPriceBlockTemplate()
@@ -371,6 +380,8 @@ public function getAddToCartPostParams(Product $product)
371380
}
372381

373382
/**
383+
* Get product price.
384+
*
374385
* @param Product $product
375386
* @return string
376387
*/
@@ -396,8 +407,8 @@ public function getProductPrice(Product $product)
396407
}
397408

398409
/**
399-
* Specifies that price rendering should be done for the list of products
400-
* i.e. rendering happens in the scope of product list, but not single product
410+
* Specifies that price rendering should be done for the list of products.
411+
* (rendering happens in the scope of product list, but not single product)
401412
*
402413
* @return Render
403414
*/

app/code/Magento/CatalogInventory/Model/AddStockStatusToCollection.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
namespace Magento\CatalogInventory\Model;
88

99
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Framework\Search\EngineResolverInterface;
11+
use Magento\Search\Model\EngineResolver;
1012

1113
/**
1214
* Catalog inventory module plugin
@@ -17,26 +19,37 @@ class AddStockStatusToCollection
1719
* @var \Magento\CatalogInventory\Helper\Stock
1820
*/
1921
protected $stockHelper;
20-
22+
23+
/**
24+
* @var EngineResolverInterface
25+
*/
26+
private $engineResolver;
27+
2128
/**
22-
* @param \Magento\CatalogInventory\Model\Configuration $configuration
2329
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
30+
* @param EngineResolverInterface $engineResolver
2431
*/
2532
public function __construct(
26-
\Magento\CatalogInventory\Helper\Stock $stockHelper
33+
\Magento\CatalogInventory\Helper\Stock $stockHelper,
34+
EngineResolverInterface $engineResolver
2735
) {
2836
$this->stockHelper = $stockHelper;
37+
$this->engineResolver = $engineResolver;
2938
}
3039

3140
/**
41+
* Add stock filter to collection.
42+
*
3243
* @param Collection $productCollection
3344
* @param bool $printQuery
3445
* @param bool $logQuery
3546
* @return array
3647
*/
3748
public function beforeLoad(Collection $productCollection, $printQuery = false, $logQuery = false)
3849
{
39-
$this->stockHelper->addIsInStockFilterToCollection($productCollection);
50+
if ($this->engineResolver->getCurrentSearchEngine() === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE) {
51+
$this->stockHelper->addIsInStockFilterToCollection($productCollection);
52+
}
4053
return [$printQuery, $logQuery];
4154
}
4255
}

app/code/Magento/CatalogInventory/Model/Plugin/Layer.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\CatalogInventory\Model\Plugin;
78

9+
use Magento\Framework\Search\EngineResolverInterface;
10+
use Magento\Search\Model\EngineResolver;
11+
12+
/**
13+
* Catalog inventory plugin for layer.
14+
*/
815
class Layer
916
{
1017
/**
@@ -21,16 +28,24 @@ class Layer
2128
*/
2229
protected $scopeConfig;
2330

31+
/**
32+
* @var EngineResolverInterface
33+
*/
34+
private $engineResolver;
35+
2436
/**
2537
* @param \Magento\CatalogInventory\Helper\Stock $stockHelper
2638
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
39+
* @param EngineResolverInterface $engineResolver
2740
*/
2841
public function __construct(
2942
\Magento\CatalogInventory\Helper\Stock $stockHelper,
30-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
43+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
44+
EngineResolverInterface $engineResolver
3145
) {
3246
$this->stockHelper = $stockHelper;
3347
$this->scopeConfig = $scopeConfig;
48+
$this->engineResolver = $engineResolver;
3449
}
3550

3651
/**
@@ -46,12 +61,22 @@ public function beforePrepareProductCollection(
4661
\Magento\Catalog\Model\Layer $subject,
4762
\Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection $collection
4863
) {
49-
if ($this->_isEnabledShowOutOfStock()) {
64+
if (!$this->isCurrentEngineMysql() || $this->_isEnabledShowOutOfStock()) {
5065
return;
5166
}
5267
$this->stockHelper->addIsInStockFilterToCollection($collection);
5368
}
5469

70+
/**
71+
* Check if current engine is MYSQL.
72+
*
73+
* @return bool
74+
*/
75+
private function isCurrentEngineMysql()
76+
{
77+
return $this->engineResolver->getCurrentSearchEngine() === EngineResolver::CATALOG_SEARCH_MYSQL_ENGINE;
78+
}
79+
5580
/**
5681
* Get config value for 'display out of stock' option
5782
*

app/code/Magento/CatalogInventory/Test/Unit/Model/AddStockStatusToCollectionTest.php

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

88
use Magento\CatalogInventory\Model\AddStockStatusToCollection;
9+
use Magento\Framework\Search\EngineResolverInterface;
910

1011
class AddStockStatusToCollectionTest extends \PHPUnit\Framework\TestCase
1112
{
@@ -19,13 +20,24 @@ class AddStockStatusToCollectionTest extends \PHPUnit\Framework\TestCase
1920
*/
2021
protected $stockHelper;
2122

23+
/**
24+
* @var EngineResolverInterface|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
private $engineResolver;
27+
2228
protected function setUp()
2329
{
2430
$this->stockHelper = $this->createMock(\Magento\CatalogInventory\Helper\Stock::class);
31+
$this->engineResolver = $this->getMockBuilder(EngineResolverInterface::class)
32+
->disableOriginalConstructor()
33+
->setMethods(['getCurrentSearchEngine'])
34+
->getMockForAbstractClass();
35+
2536
$this->plugin = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))->getObject(
2637
\Magento\CatalogInventory\Model\AddStockStatusToCollection::class,
2738
[
2839
'stockHelper' => $this->stockHelper,
40+
'engineResolver' => $this->engineResolver
2941
]
3042
);
3143
}
@@ -36,6 +48,10 @@ public function testAddStockStatusToCollection()
3648
->disableOriginalConstructor()
3749
->getMock();
3850

51+
$this->engineResolver->expects($this->any())
52+
->method('getCurrentSearchEngine')
53+
->willReturn('mysql');
54+
3955
$this->stockHelper->expects($this->once())
4056
->method('addIsInStockFilterToCollection')
4157
->with($productCollection)

app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/LayerTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\CatalogInventory\Test\Unit\Model\Plugin;
77

8+
use Magento\Framework\Search\EngineResolverInterface;
9+
810
class LayerTest extends \PHPUnit\Framework\TestCase
911
{
1012
/**
@@ -22,14 +24,24 @@ class LayerTest extends \PHPUnit\Framework\TestCase
2224
*/
2325
protected $_stockHelperMock;
2426

27+
/**
28+
* @var EngineResolverInterface|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $engineResolver;
31+
2532
protected function setUp()
2633
{
2734
$this->_scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
2835
$this->_stockHelperMock = $this->createMock(\Magento\CatalogInventory\Helper\Stock::class);
36+
$this->engineResolver = $this->getMockBuilder(EngineResolverInterface::class)
37+
->disableOriginalConstructor()
38+
->setMethods(['getCurrentSearchEngine'])
39+
->getMockForAbstractClass();
2940

3041
$this->_model = new \Magento\CatalogInventory\Model\Plugin\Layer(
3142
$this->_stockHelperMock,
32-
$this->_scopeConfigMock
43+
$this->_scopeConfigMock,
44+
$this->engineResolver
3345
);
3446
}
3547

@@ -38,6 +50,10 @@ protected function setUp()
3850
*/
3951
public function testAddStockStatusDisabledShow()
4052
{
53+
$this->engineResolver->expects($this->any())
54+
->method('getCurrentSearchEngine')
55+
->willReturn('mysql');
56+
4157
$this->_scopeConfigMock->expects(
4258
$this->once()
4359
)->method(
@@ -60,6 +76,10 @@ public function testAddStockStatusDisabledShow()
6076
*/
6177
public function testAddStockStatusEnabledShow()
6278
{
79+
$this->engineResolver->expects($this->any())
80+
->method('getCurrentSearchEngine')
81+
->willReturn('mysql');
82+
6383
$this->_scopeConfigMock->expects(
6484
$this->once()
6585
)->method(

app/code/Magento/CatalogInventory/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"php": "~7.1.3||~7.2.0",
99
"magento/framework": "*",
1010
"magento/module-catalog": "*",
11+
"magento/module-search": "*",
1112
"magento/module-config": "*",
1213
"magento/module-customer": "*",
1314
"magento/module-eav": "*",

app/code/Magento/CatalogSearch/Controller/Advanced/Result.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,9 @@ public function execute()
6060
{
6161
try {
6262
$this->_catalogSearchAdvanced->addFilters($this->getRequest()->getQueryValue());
63-
$size = $this->_catalogSearchAdvanced->getProductCollection()->getSize();
64-
65-
$handles = null;
66-
if ($size == 0) {
67-
$this->_view->getPage()->initLayout();
68-
$handles = $this->_view->getLayout()->getUpdate()->getHandles();
69-
$handles[] = static::DEFAULT_NO_RESULT_HANDLE;
70-
}
71-
63+
$this->_view->getPage()->initLayout();
64+
$handles = $this->_view->getLayout()->getUpdate()->getHandles();
65+
$handles[] = static::DEFAULT_NO_RESULT_HANDLE;
7266
$this->_view->loadLayout($handles);
7367
$this->_view->renderLayout();
7468
} catch (\Magento\Framework\Exception\LocalizedException $e) {

0 commit comments

Comments
 (0)