Skip to content

Commit 3487aff

Browse files
committed
MC-35016: Out of stock products doesn't filter properly using "price" filter
1 parent 1c9ba3e commit 3487aff

File tree

1 file changed

+26
-6
lines changed
  • app/code/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Price

1 file changed

+26
-6
lines changed

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

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price;
77

88
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier;
9+
use Magento\Framework\DB\Select;
910
use Magento\Framework\Indexer\DimensionalIndexerInterface;
1011
use Magento\Framework\EntityManager\MetadataPool;
1112
use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer;
@@ -140,6 +141,30 @@ public function executeByDimensions(array $dimensions, \Traversable $entityIds)
140141
$this->applyConfigurableOption($temporaryPriceTable, $dimensions, iterator_to_array($entityIds));
141142
}
142143

144+
/**
145+
* Filter select by inventory
146+
*
147+
* @param Select $select
148+
* @return Select
149+
*/
150+
public function filterSelectByInventory(Select $select)
151+
{
152+
$select->join(
153+
['si' => $this->getTable('cataloginventory_stock_item')],
154+
'si.product_id = l.product_id',
155+
[]
156+
);
157+
$select->join(
158+
['si_parent' => $this->getTable('cataloginventory_stock_item')],
159+
'si_parent.product_id = l.parent_id',
160+
[]
161+
);
162+
$select->where('si.is_in_stock = ?', Stock::STOCK_IN_STOCK);
163+
$select->orWhere('si_parent.is_in_stock = ?', Stock::STOCK_OUT_OF_STOCK);
164+
165+
return $select;
166+
}
167+
143168
/**
144169
* Apply configurable option
145170
*
@@ -200,12 +225,7 @@ private function fillTemporaryOptionsTable(string $temporaryOptionsTableName, ar
200225

201226
// Does not make sense to extend query if out of stock products won't appear in tables for indexing
202227
if ($this->isConfigShowOutOfStock()) {
203-
$select->join(
204-
['si' => $this->getTable('cataloginventory_stock_item')],
205-
'si.product_id = l.product_id',
206-
[]
207-
);
208-
$select->where('si.is_in_stock = ?', Stock::STOCK_IN_STOCK);
228+
$select = $this->filterSelectByInventory($select);
209229
}
210230

211231
$select->columns(

0 commit comments

Comments
 (0)