Skip to content

Commit 7ee934d

Browse files
committed
MC-35016: Out of stock products doesn't filter properly using "price" filter
1 parent 38343fe commit 7ee934d

File tree

3 files changed

+85
-20
lines changed

3 files changed

+85
-20
lines changed

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price/Configurable.php

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price;
79

10+
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
811
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier;
912
use Magento\Framework\DB\Select;
1013
use Magento\Framework\Indexer\DimensionalIndexerInterface;
@@ -14,10 +17,8 @@
1417
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructureFactory;
1518
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure;
1619
use Magento\Framework\App\Config\ScopeConfigInterface;
17-
use Magento\Store\Model\ScopeInterface;
1820
use Magento\Framework\App\ObjectManager;
1921
use Magento\CatalogInventory\Model\Stock;
20-
use Magento\CatalogInventory\Model\Configuration;
2122

2223
/**
2324
* Configurable Products Price Indexer Resource model
@@ -76,6 +77,11 @@ class Configurable implements DimensionalIndexerInterface
7677
*/
7778
private $scopeConfig;
7879

80+
/**
81+
* @var BaseSelectProcessorInterface
82+
*/
83+
private $baseSelectProcessor;
84+
7985
/**
8086
* @param BaseFinalPrice $baseFinalPrice
8187
* @param IndexTableStructureFactory $indexTableStructureFactory
@@ -86,6 +92,9 @@ class Configurable implements DimensionalIndexerInterface
8692
* @param bool $fullReindexAction
8793
* @param string $connectionName
8894
* @param ScopeConfigInterface $scopeConfig
95+
* @param BaseSelectProcessorInterface|null $baseSelectProcessor
96+
*
97+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8998
*/
9099
public function __construct(
91100
BaseFinalPrice $baseFinalPrice,
@@ -96,7 +105,8 @@ public function __construct(
96105
BasePriceModifier $basePriceModifier,
97106
$fullReindexAction = false,
98107
$connectionName = 'indexer',
99-
ScopeConfigInterface $scopeConfig = null
108+
ScopeConfigInterface $scopeConfig = null,
109+
?BaseSelectProcessorInterface $baseSelectProcessor = null
100110
) {
101111
$this->baseFinalPrice = $baseFinalPrice;
102112
$this->indexTableStructureFactory = $indexTableStructureFactory;
@@ -107,6 +117,8 @@ public function __construct(
107117
$this->fullReindexAction = $fullReindexAction;
108118
$this->basePriceModifier = $basePriceModifier;
109119
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
120+
$this->baseSelectProcessor = $baseSelectProcessor ?:
121+
ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
110122
}
111123

112124
/**
@@ -223,10 +235,7 @@ private function fillTemporaryOptionsTable(string $temporaryOptionsTableName, ar
223235
[]
224236
);
225237

226-
// Does not make sense to extend query if out of stock products won't appear in tables for indexing
227-
if ($this->isConfigShowOutOfStock()) {
228-
$select = $this->filterSelectByInventory($select);
229-
}
238+
$this->baseSelectProcessor->process($select);
230239

231240
$select->columns(
232241
[
@@ -315,17 +324,4 @@ private function getTable($tableName)
315324
{
316325
return $this->resource->getTableName($tableName, $this->connectionName);
317326
}
318-
319-
/**
320-
* Is flag Show Out Of Stock setted
321-
*
322-
* @return bool
323-
*/
324-
private function isConfigShowOutOfStock(): bool
325-
{
326-
return $this->scopeConfig->isSetFlag(
327-
Configuration::XML_PATH_SHOW_OUT_OF_STOCK,
328-
ScopeInterface::SCOPE_STORE
329-
);
330-
}
331327
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price;
9+
10+
use Magento\CatalogInventory\Model\Stock;
11+
use Magento\Framework\App\ResourceConnection;
12+
use Magento\Framework\DB\Select;
13+
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
14+
use Magento\CatalogInventory\Api\StockConfigurationInterface;
15+
16+
/**
17+
* A Select object processor.
18+
*
19+
* Adds stock status limitations to a given Select object.
20+
*/
21+
class StockStatusBaseSelectProcessor implements BaseSelectProcessorInterface
22+
{
23+
/**
24+
* @var ResourceConnection
25+
*/
26+
private $resource;
27+
28+
/**
29+
* @var StockConfigurationInterface
30+
*/
31+
private $stockConfig;
32+
33+
/**
34+
* @param ResourceConnection $resource
35+
* @param StockConfigurationInterface $stockConfig
36+
*/
37+
public function __construct(
38+
ResourceConnection $resource,
39+
StockConfigurationInterface $stockConfig
40+
) {
41+
$this->resource = $resource;
42+
$this->stockConfig = $stockConfig;
43+
}
44+
45+
/**
46+
* {@inheritdoc}
47+
*/
48+
public function process(Select $select)
49+
{
50+
// Does not make sense to extend query if out of stock products won't appear in tables for indexing
51+
if ($this->stockConfig->isShowOutOfStock()) {
52+
$select->join(
53+
['si' => $this->resource->getTableName('cataloginventory_stock_item')],
54+
'si.product_id = l.product_id',
55+
[]
56+
);
57+
$select->join(
58+
['si_parent' => $this->resource->getTableName('cataloginventory_stock_item')],
59+
'si_parent.product_id = l.parent_id',
60+
[]
61+
);
62+
$select->where('si.is_in_stock = ?', Stock::STOCK_IN_STOCK);
63+
$select->orWhere('si_parent.is_in_stock = ?', Stock::STOCK_OUT_OF_STOCK);
64+
}
65+
66+
return $select;
67+
}
68+
}

app/code/Magento/ConfigurableProduct/etc/di.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@
198198
<arguments>
199199
<argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
200200
<argument name="connectionName" xsi:type="string">indexer</argument>
201+
<argument name="baseSelectProcessor" xsi:type="object">Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\StockStatusBaseSelectProcessor</argument>
201202
</arguments>
202203
</type>
203204
<type name="Magento\ConfigurableProduct\Plugin\Model\ResourceModel\Product">

0 commit comments

Comments
 (0)