diff --git a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/BaseStockStatusSelectProcessor.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/BaseStockStatusSelectProcessor.php index cbeaf2cea90..73aeee118e6 100644 --- a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/BaseStockStatusSelectProcessor.php +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/BaseStockStatusSelectProcessor.php @@ -49,18 +49,18 @@ class BaseStockStatusSelectProcessor implements BaseSelectProcessorInterface { // 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', + $stockIndexTableName = $this->resource->getTableName('cataloginventory_stock_status'); + $select->joinInner( + ['child_stock_default' => $stockIndexTableName], + 'child_stock_default.product_id = l.product_id', [] - ); - $select->join( - ['si_parent' => $this->resource->getTableName('cataloginventory_stock_item')], - 'si_parent.product_id = l.parent_id', + )->joinInner( + ['parent_stock_default' => $stockIndexTableName], + 'parent_stock_default.product_id = le.entity_id', [] + )->where( + 'child_stock_default.stock_status = 1 OR parent_stock_default.stock_status = 0' ); - $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 --git 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 d00e5c72a46..73810e8d4cf 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 @@ -9,7 +9,6 @@ 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; @@ -18,7 +17,6 @@ use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructur use Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableStructure; use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\App\ObjectManager; -use Magento\CatalogInventory\Model\Stock; /** * Configurable Products Price Indexer Resource model @@ -82,6 +80,11 @@ class Configurable implements DimensionalIndexerInterface */ private $baseSelectProcessor; + /** + * @var OptionsIndexerInterface + */ + private $optionsIndexer; + /** * @param BaseFinalPrice $baseFinalPrice * @param IndexTableStructureFactory $indexTableStructureFactory @@ -91,9 +94,9 @@ class Configurable implements DimensionalIndexerInterface * @param BasePriceModifier $basePriceModifier * @param bool $fullReindexAction * @param string $connectionName - * @param ScopeConfigInterface $scopeConfig + * @param ScopeConfigInterface|null $scopeConfig * @param BaseSelectProcessorInterface|null $baseSelectProcessor - * + * @param OptionsIndexerInterface|null $optionsIndexer * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -106,7 +109,8 @@ class Configurable implements DimensionalIndexerInterface $fullReindexAction = false, $connectionName = 'indexer', ScopeConfigInterface $scopeConfig = null, - ?BaseSelectProcessorInterface $baseSelectProcessor = null + ?BaseSelectProcessorInterface $baseSelectProcessor = null, + ?OptionsIndexerInterface $optionsIndexer = null ) { $this->baseFinalPrice = $baseFinalPrice; $this->indexTableStructureFactory = $indexTableStructureFactory; @@ -119,6 +123,8 @@ class Configurable implements DimensionalIndexerInterface $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); $this->baseSelectProcessor = $baseSelectProcessor ?: ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class); + $this->optionsIndexer = $optionsIndexer + ?: ObjectManager::getInstance()->get(OptionsIndexerInterface::class); } /** @@ -175,7 +181,8 @@ class Configurable implements DimensionalIndexerInterface true ); - $this->fillTemporaryOptionsTable($temporaryOptionsTableName, $dimensions, $entityIds); + $indexTableName = $this->getMainTable($dimensions); + $this->optionsIndexer->execute($indexTableName, $temporaryOptionsTableName, $entityIds); $this->updateTemporaryTable($temporaryPriceTable->getTableName(), $temporaryOptionsTableName); $this->getConnection()->delete($temporaryOptionsTableName); @@ -183,54 +190,6 @@ class Configurable implements DimensionalIndexerInterface return $this; } - /** - * Put data into catalog product price indexer config option temp table - * - * @param string $temporaryOptionsTableName - * @param array $dimensions - * @param array $entityIds - * - * @return void - * @throws \Exception - */ - private function fillTemporaryOptionsTable(string $temporaryOptionsTableName, array $dimensions, array $entityIds) - { - $metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); - $linkField = $metadata->getLinkField(); - - $select = $this->getConnection()->select()->from( - ['i' => $this->getMainTable($dimensions)], - [] - )->join( - ['l' => $this->getTable('catalog_product_super_link')], - 'l.product_id = i.entity_id', - [] - )->join( - ['le' => $this->getTable('catalog_product_entity')], - 'le.' . $linkField . ' = l.parent_id', - [] - ); - - $this->baseSelectProcessor->process($select); - - $select->columns( - [ - 'le.entity_id', - 'customer_group_id', - 'website_id', - 'MIN(final_price)', - 'MAX(final_price)', - 'MIN(tier_price)', - ] - )->group( - ['le.entity_id', 'customer_group_id', 'website_id'] - ); - if ($entityIds !== null) { - $select->where('le.entity_id IN (?)', $entityIds, \Zend_Db::INT_TYPE); - } - $this->tableMaintainer->insertFromSelect($select, $temporaryOptionsTableName, []); - } - /** * Update data in the catalog product price indexer temp table * diff --git a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsIndexer.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsIndexer.php new file mode 100644 index 00000000000..bceb95b00cc --- /dev/null +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsIndexer.php @@ -0,0 +1,47 @@ +selectBuilder = $selectBuilder; + $this->tableMaintainer = $tableMaintainer; + } + + /** + * @inheritdoc + */ + public function execute(string $indexTable, string $tempIndexTable, ?array $entityIds = null): void + { + $select = $this->selectBuilder->execute($indexTable, $entityIds); + $this->tableMaintainer->insertFromSelect($select, $tempIndexTable, []); + } +} diff --git a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsIndexerInterface.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsIndexerInterface.php new file mode 100644 index 00000000000..401451b2b68 --- /dev/null +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsIndexerInterface.php @@ -0,0 +1,25 @@ +selectProcessor = $selectProcessor; + $this->metadataPool = $metadataPool; + $this->resourceConnection = $resourceConnection; + $this->connectionName = $connectionName; + } + + /** + * @inheritdoc + */ + public function execute(string $indexTable, ?array $entityIds = null): Select + { + $connection = $this->resourceConnection->getConnection($this->connectionName); + $metadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); + $linkField = $metadata->getLinkField(); + + $select = $connection->select() + ->from( + ['i' => $indexTable], + [] + ) + ->join( + ['l' => $this->resourceConnection->getTableName('catalog_product_super_link', $this->connectionName)], + 'l.product_id = i.entity_id', + [] + ) + ->join( + ['le' => $this->resourceConnection->getTableName('catalog_product_entity', $this->connectionName)], + 'le.' . $linkField . ' = l.parent_id', + [] + ); + + $select->columns( + [ + 'le.entity_id', + 'customer_group_id', + 'website_id', + 'MIN(final_price)', + 'MAX(final_price)', + 'MIN(tier_price)', + ] + )->group( + ['le.entity_id', 'customer_group_id', 'website_id'] + ); + if ($entityIds !== null) { + $select->where('le.entity_id IN (?)', $entityIds, \Zend_Db::INT_TYPE); + } + return $this->selectProcessor->process($select); + } +} diff --git a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsSelectBuilderInterface.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsSelectBuilderInterface.php new file mode 100644 index 00000000000..bc5084671d5 --- /dev/null +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/OptionsSelectBuilderInterface.php @@ -0,0 +1,25 @@ + + + @@ -201,6 +203,12 @@ Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\BaseStockStatusSelectProcessor + + + Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\BaseStockStatusSelectProcessor + indexer + + Magento\Catalog\Model\Indexer\Product\Full