diff -Nuar a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php index b7bbf7aa187..5a22ad8238a 100644 --- a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php @@ -3,9 +3,13 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price; +use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface; use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BasePriceModifier; +use Magento\Framework\DB\Select; use Magento\Framework\Indexer\DimensionalIndexerInterface; use Magento\Framework\EntityManager\MetadataPool; use Magento\Catalog\Model\Indexer\Product\Price\TableMaintainer; @@ -13,10 +17,8 @@ use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Query\BaseFinalPri use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructureFactory; use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure; use Magento\Framework\App\Config\ScopeConfigInterface; -use Magento\Store\Model\ScopeInterface; use Magento\Framework\App\ObjectManager; use Magento\CatalogInventory\Model\Stock; -use Magento\CatalogInventory\Model\Configuration; /** * Configurable Products Price Indexer Resource model @@ -75,6 +77,11 @@ class Configurable implements DimensionalIndexerInterface */ private $scopeConfig; + /** + * @var BaseSelectProcessorInterface + */ + private $baseSelectProcessor; + /** * @param BaseFinalPrice $baseFinalPrice * @param IndexTableStructureFactory $indexTableStructureFactory @@ -85,6 +92,9 @@ class Configurable implements DimensionalIndexerInterface * @param bool $fullReindexAction * @param string $connectionName * @param ScopeConfigInterface $scopeConfig + * @param BaseSelectProcessorInterface|null $baseSelectProcessor + * + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( BaseFinalPrice $baseFinalPrice, @@ -95,7 +105,8 @@ class Configurable implements DimensionalIndexerInterface BasePriceModifier $basePriceModifier, $fullReindexAction = false, $connectionName = 'indexer', - ScopeConfigInterface $scopeConfig = null + ScopeConfigInterface $scopeConfig = null, + ?BaseSelectProcessorInterface $baseSelectProcessor = null ) { $this->baseFinalPrice = $baseFinalPrice; $this->indexTableStructureFactory = $indexTableStructureFactory; @@ -106,6 +117,8 @@ class Configurable implements DimensionalIndexerInterface $this->fullReindexAction = $fullReindexAction; $this->basePriceModifier = $basePriceModifier; $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); + $this->baseSelectProcessor = $baseSelectProcessor ?: + ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class); } /** @@ -199,15 +212,7 @@ class Configurable implements DimensionalIndexerInterface [] ); - // Does not make sense to extend query if out of stock products won't appear in tables for indexing - if ($this->isConfigShowOutOfStock()) { - $select->join( - ['si' => $this->getTable('cataloginventory_stock_item')], - 'si.product_id = l.product_id', - [] - ); - $select->where('si.is_in_stock = ?', Stock::STOCK_IN_STOCK); - } + $this->baseSelectProcessor->process($select); $select->columns( [ @@ -297,17 +302,4 @@ class Configurable implements DimensionalIndexerInterface { return $this->resource->getTableName($tableName, $this->connectionName); } - - /** - * Is flag Show Out Of Stock setted - * - * @return bool - */ - private function isConfigShowOutOfStock(): bool - { - return $this->scopeConfig->isSetFlag( - Configuration::XML_PATH_SHOW_OUT_OF_STOCK, - ScopeInterface::SCOPE_STORE - ); - } } diff -Nuar a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/StockStatusBaseSelectProcessor.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/StockStatusBaseSelectProcessor.php new file mode 100644 index 00000000000..b5cbaa57858 --- /dev/null +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/StockStatusBaseSelectProcessor.php @@ -0,0 +1,68 @@ +resource = $resource; + $this->stockConfig = $stockConfig; + } + + /** + * @inheritdoc + */ + public function process(Select $select) + { + // Does not make sense to extend query if out of stock products won't appear in tables for indexing + if ($this->stockConfig->isShowOutOfStock()) { + $select->join( + ['si' => $this->resource->getTableName('cataloginventory_stock_item')], + 'si.product_id = l.product_id', + [] + ); + $select->join( + ['si_parent' => $this->resource->getTableName('cataloginventory_stock_item')], + 'si_parent.product_id = l.parent_id', + [] + ); + $select->where('si.is_in_stock = ?', Stock::STOCK_IN_STOCK); + $select->orWhere('si_parent.is_in_stock = ?', Stock::STOCK_OUT_OF_STOCK); + } + + return $select; + } +} diff -Nuar a/vendor/magento/module-configurable-product/etc/di.xml b/vendor/magento/module-configurable-product/etc/di.xml index c8a278df92d..9f01af66f97 100644 --- a/vendor/magento/module-configurable-product/etc/di.xml +++ b/vendor/magento/module-configurable-product/etc/di.xml @@ -198,6 +198,7 @@ Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy indexer + Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\StockStatusBaseSelectProcessor