Skip to content

Commit 8fe11d7

Browse files
committed
ACP2E-165: [Magento Cloud] min_price and max_price DB values are set to non-zero when configurable product stock status is Out Of Stock and child products are Out Of Stock and Disabled
1 parent b2cd0c1 commit 8fe11d7

File tree

5 files changed

+85
-13
lines changed

5 files changed

+85
-13
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ public function process(Select $select)
4949
{
5050
// Does not make sense to extend query if out of stock products won't appear in tables for indexing
5151
if ($this->stockConfig->isShowOutOfStock()) {
52-
$select->join(
53-
['si' => $this->resource->getTableName('cataloginventory_stock_item')],
54-
'si.product_id = l.product_id',
52+
$stockIndexTableName = $this->resource->getTableName('cataloginventory_stock_status');
53+
$select->joinInner(
54+
['child_stock_default' => $stockIndexTableName],
55+
'child_stock_default.product_id = l.product_id',
5556
[]
56-
);
57-
$select->join(
58-
['si_parent' => $this->resource->getTableName('cataloginventory_stock_item')],
59-
'si_parent.product_id = l.parent_id',
57+
)->joinInner(
58+
['parent_stock_default' => $stockIndexTableName],
59+
'parent_stock_default.product_id = le.entity_id',
6060
[]
61+
)->where(
62+
'child_stock_default.stock_status = 1 OR parent_stock_default.stock_status = 0'
6163
);
62-
$select->where('si.is_in_stock = ?', Stock::STOCK_IN_STOCK);
63-
$select->orWhere('si_parent.is_in_stock = ?', Stock::STOCK_OUT_OF_STOCK);
6464
}
6565

6666
return $select;

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ class Configurable implements DimensionalIndexerInterface
8282
*/
8383
private $baseSelectProcessor;
8484

85+
/**
86+
* @var PopulateIndexTableInterface
87+
*/
88+
private $populateOptionsIndexTable;
89+
8590
/**
8691
* @param BaseFinalPrice $baseFinalPrice
8792
* @param IndexTableStructureFactory $indexTableStructureFactory
@@ -91,9 +96,9 @@ class Configurable implements DimensionalIndexerInterface
9196
* @param BasePriceModifier $basePriceModifier
9297
* @param bool $fullReindexAction
9398
* @param string $connectionName
94-
* @param ScopeConfigInterface $scopeConfig
99+
* @param ScopeConfigInterface|null $scopeConfig
95100
* @param BaseSelectProcessorInterface|null $baseSelectProcessor
96-
*
101+
* @param PopulateIndexTableInterface|null $populateOptionsIndexTable
97102
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
98103
*/
99104
public function __construct(
@@ -106,7 +111,8 @@ public function __construct(
106111
$fullReindexAction = false,
107112
$connectionName = 'indexer',
108113
ScopeConfigInterface $scopeConfig = null,
109-
?BaseSelectProcessorInterface $baseSelectProcessor = null
114+
?BaseSelectProcessorInterface $baseSelectProcessor = null,
115+
?PopulateIndexTableInterface $populateOptionsIndexTable = null
110116
) {
111117
$this->baseFinalPrice = $baseFinalPrice;
112118
$this->indexTableStructureFactory = $indexTableStructureFactory;
@@ -119,6 +125,8 @@ public function __construct(
119125
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
120126
$this->baseSelectProcessor = $baseSelectProcessor ?:
121127
ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
128+
$this->populateOptionsIndexTable = $populateOptionsIndexTable
129+
?: ObjectManager::getInstance()->get(PopulateIndexTableInterface::class);
122130
}
123131

124132
/**
@@ -228,7 +236,7 @@ private function fillTemporaryOptionsTable(string $temporaryOptionsTableName, ar
228236
if ($entityIds !== null) {
229237
$select->where('le.entity_id IN (?)', $entityIds, \Zend_Db::INT_TYPE);
230238
}
231-
$this->tableMaintainer->insertFromSelect($select, $temporaryOptionsTableName, []);
239+
$this->populateOptionsIndexTable->execute($select, $temporaryOptionsTableName);
232240
}
233241

234242
/**
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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\Catalog\Model\Indexer\Product\Price\TableMaintainer;
11+
use Magento\Framework\DB\Select;
12+
13+
/**
14+
* Populate index table with data from select
15+
*/
16+
class PopulateIndexTable implements PopulateIndexTableInterface
17+
{
18+
/**
19+
* @var TableMaintainer
20+
*/
21+
private $tableMaintainer;
22+
23+
/**
24+
* @param TableMaintainer $tableMaintainer
25+
*/
26+
public function __construct(
27+
TableMaintainer $tableMaintainer
28+
) {
29+
$this->tableMaintainer = $tableMaintainer;
30+
}
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
public function execute(Select $select, string $indexTableName): void
36+
{
37+
$this->tableMaintainer->insertFromSelect($select, $indexTableName, []);
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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\Framework\DB\Select;
11+
12+
/**
13+
* Populate index table with data from select statement
14+
*/
15+
interface PopulateIndexTableInterface
16+
{
17+
/**
18+
* Insert data from select statement into index table
19+
*
20+
* @param Select $select
21+
* @param string $indexTableName
22+
*/
23+
public function execute(Select $select, string $indexTableName): void;
24+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<preference for="Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProviderInterface" type="Magento\ConfigurableProduct\Pricing\Price\LowestPriceOptionsProvider" />
1818
<preference for="Magento\ConfigurableProduct\Model\AttributeOptionProviderInterface" type="Magento\ConfigurableProduct\Model\AttributeOptionProvider" />
1919
<preference for="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilderInterface" type="Magento\ConfigurableProduct\Model\ResourceModel\Attribute\OptionSelectBuilder" />
20+
<preference for="Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\PopulateIndexTableInterface" type="\Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\PopulateIndexTable" />
2021

2122
<type name="Magento\CatalogInventory\Model\Quote\Item\QuantityValidator\Initializer\Option">
2223
<plugin name="configurable_product" type="Magento\ConfigurableProduct\Model\Quote\Item\QuantityValidator\Initializer\Option\Plugin\ConfigurableProduct" sortOrder="50" />

0 commit comments

Comments
 (0)