diff --git a/vendor/magento/module-inventory-bundle-product-indexer/Indexer/SourceItemIndexerProcessor.php b/vendor/magento/module-inventory-bundle-product-indexer/Indexer/SourceItemIndexerProcessor.php new file mode 100644 index 00000000000..60c038a118f --- /dev/null +++ b/vendor/magento/module-inventory-bundle-product-indexer/Indexer/SourceItemIndexerProcessor.php @@ -0,0 +1,70 @@ +bundleProductsSourceItemIndexer = $configurableProductsSourceItemIndexer; + $this->sortOrder = $sortOrder; + } + + /** + * Reindex source items list for bundle products. + * + * @param array $sourceItemIds + * @param array $saleableStatusesBeforeSync + * @param array $saleableStatusesAfterSync + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + * @throws StateException + */ + public function process( + array $sourceItemIds, + array $saleableStatusesBeforeSync, + array $saleableStatusesAfterSync + ): void { + $this->bundleProductsSourceItemIndexer->executeList($sourceItemIds); + } + + /** + * @inheritdoc + * + * @return int + */ + public function getSortOrder(): int + { + return $this->sortOrder; + } +} diff --git a/vendor/magento/module-inventory-bundle-product-indexer/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/SourceItemIndexerPlugin.php b/vendor/magento/module-inventory-bundle-product-indexer/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/SourceItemIndexerPlugin.php deleted file mode 100644 index 6468b22743d..00000000000 --- a/vendor/magento/module-inventory-bundle-product-indexer/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/SourceItemIndexerPlugin.php +++ /dev/null @@ -1,50 +0,0 @@ -bundleProductsSourceItemIndexer = $configurableProductsSourceItemIndexer; - } - - /** - * Reindex source items list for bundle products. - * - * @param Sync $subject - * @param callable $proceed - * @param array $sourceItemIds - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - * @throws StateException - */ - public function aroundExecuteList( - Sync $subject, - callable $proceed, - array $sourceItemIds - ) { - $proceed($sourceItemIds); - $this->bundleProductsSourceItemIndexer->executeList($sourceItemIds); - } -} diff --git a/vendor/magento/module-inventory-bundle-product-indexer/etc/di.xml b/vendor/magento/module-inventory-bundle-product-indexer/etc/di.xml index f8aed1d917d..c01801a3fc8 100644 --- a/vendor/magento/module-inventory-bundle-product-indexer/etc/di.xml +++ b/vendor/magento/module-inventory-bundle-product-indexer/etc/di.xml @@ -10,9 +10,6 @@ - - - Magento\InventoryIndexer\Indexer\IndexHandler @@ -30,4 +27,16 @@ + + + 5 + + + + + + Magento\InventoryBundleProductIndexer\Indexer\SourceItemIndexerProcessor + + + diff --git a/vendor/magento/module-inventory-cache/Model/CacheFlushProcessor.php b/vendor/magento/module-inventory-cache/Model/CacheFlushProcessor.php new file mode 100644 index 00000000000..c8d805d78c6 --- /dev/null +++ b/vendor/magento/module-inventory-cache/Model/CacheFlushProcessor.php @@ -0,0 +1,112 @@ +flushCacheByIds = $flushCacheByIds; + $this->getCategoryIdsByProductIds = $getCategoryIdsByProductIds; + $this->flushCategoryByCategoryIds = $flushCategoryByCategoryIds; + $this->getProductsIdsToProcess = $getProductsIdsToProcess; + $this->indexerRegistry = $indexerRegistry; + $this->sortOrder = $sortOrder; + } + + /** + * Clean cache for specific products after source items reindex. + * + * @param array $sourceItemIds + * @param array $saleableStatusesBeforeSync + * @param array $saleableStatusesAfterSync + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function process( + array $sourceItemIds, + array $saleableStatusesBeforeSync, + array $saleableStatusesAfterSync + ): void { + $forceDefaultProcessing = !$this->indexerRegistry->get(InventoryIndexer::INDEXER_ID)->isScheduled(); + + $productsIdsToFlush = $this->getProductsIdsToProcess->execute( + $saleableStatusesBeforeSync, + $saleableStatusesAfterSync, + $forceDefaultProcessing + ); + + if (!empty($productsIdsToFlush)) { + $categoryIds = $this->getCategoryIdsByProductIds->execute($productsIdsToFlush); + $this->flushCacheByIds->execute($productsIdsToFlush); + $this->flushCategoryByCategoryIds->execute($categoryIds); + } + } + + /** + * @inheritdoc + * + * @return int + */ + public function getSortOrder(): int + { + return $this->sortOrder; + } +} diff --git a/vendor/magento/module-inventory-cache/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/CacheFlush.php b/vendor/magento/module-inventory-cache/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/CacheFlush.php deleted file mode 100644 index 2114f7cdd28..00000000000 --- a/vendor/magento/module-inventory-cache/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/CacheFlush.php +++ /dev/null @@ -1,105 +0,0 @@ -flushCacheByIds = $flushCacheByIds; - $this->getCategoryIdsByProductIds = $getCategoryIdsByProductIds; - $this->flushCategoryByCategoryIds = $flushCategoryByCategoryIds; - $this->getSalableStatuses = $getSalableStatuses; - $this->getProductsIdsToProcess = $getProductsIdsToProcess; - $this->indexerRegistry = $indexerRegistry; - } - - /** - * Clean cache for specific products after source items reindex. - * - * @param Sync $subject - * @param callable $proceed - * @param array $sourceItemIds - * @return void - * @throws \Exception in case catalog product entity type hasn't been initialized. - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function aroundExecuteList(Sync $subject, callable $proceed, array $sourceItemIds) : void - { - $beforeSalableList = $this->getSalableStatuses->execute($sourceItemIds); - $proceed($sourceItemIds); - $afterSalableList = $this->getSalableStatuses->execute($sourceItemIds); - $forceDefaultProcessing = !$this->indexerRegistry->get(InventoryIndexer::INDEXER_ID)->isScheduled(); - $productsIdsToFlush = $this->getProductsIdsToProcess->execute( - $beforeSalableList, - $afterSalableList, - $forceDefaultProcessing - ); - if (!empty($productsIdsToFlush)) { - $categoryIds = $this->getCategoryIdsByProductIds->execute($productsIdsToFlush); - $this->flushCacheByIds->execute($productsIdsToFlush); - $this->flushCategoryByCategoryIds->execute($categoryIds); - } - } -} diff --git a/vendor/magento/module-inventory-cache/etc/di.xml b/vendor/magento/module-inventory-cache/etc/di.xml index 269ae6223d4..0bace2f47a6 100644 --- a/vendor/magento/module-inventory-cache/etc/di.xml +++ b/vendor/magento/module-inventory-cache/etc/di.xml @@ -9,9 +9,6 @@ - - - Magento\Catalog\Model\Product::CACHE_TAG @@ -25,4 +22,16 @@ + + + 30 + + + + + + Magento\InventoryCache\Model\CacheFlushProcessor + + + diff --git a/vendor/magento/module-inventory-catalog/Model/PriceIndexUpdateProcessor.php b/vendor/magento/module-inventory-catalog/Model/PriceIndexUpdateProcessor.php new file mode 100644 index 00000000000..19bff22889a --- /dev/null +++ b/vendor/magento/module-inventory-catalog/Model/PriceIndexUpdateProcessor.php @@ -0,0 +1,80 @@ +priceIndexProcessor = $priceIndexProcessor; + $this->getProductsIdsToProcess = $getProductsIdsToProcess; + $this->sortOrder = $sortOrder; + } + + /** + * Price index update for specific products after source items reindex. + * + * @param array $sourceItemIds + * @param array $saleableStatusesBeforeSync + * @param array $saleableStatusesAfterSync + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function process( + array $sourceItemIds, + array $saleableStatusesBeforeSync, + array $saleableStatusesAfterSync + ): void { + $productsIdsToReindex = $this->getProductsIdsToProcess->execute( + $saleableStatusesBeforeSync, + $saleableStatusesAfterSync + ); + if (!empty($productsIdsToReindex)) { + $this->priceIndexProcessor->reindexList($productsIdsToReindex, true); + } + } + + /** + * @inheritdoc + * + * @return int + */ + public function getSortOrder(): int + { + return $this->sortOrder; + } +} diff --git a/vendor/magento/module-inventory-catalog/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/PriceIndexUpdater.php b/vendor/magento/module-inventory-catalog/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/PriceIndexUpdater.php deleted file mode 100644 index eb0d359b4ac..00000000000 --- a/vendor/magento/module-inventory-catalog/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/PriceIndexUpdater.php +++ /dev/null @@ -1,95 +0,0 @@ -priceIndexProcessor = $priceIndexProcessor; - $this->getSourceCodesBySourceItemIds = $getSourceCodesBySourceItemIds; - $this->defaultSourceProvider = $defaultSourceProvider; - $this->getSalableStatuses = $getSalableStatuses; - $this->getProductsIdsToProcess = $getProductsIdsToProcess; - } - - /** - * Reindex product prices. - * - * @param Sync $subject - * @param callable $proceed - * @param array $sourceItemIds - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function aroundExecuteList(Sync $subject, callable $proceed, array $sourceItemIds) : void - { - $customSourceItemIds = []; - $defaultSourceCode = $this->defaultSourceProvider->getCode(); - foreach ($this->getSourceCodesBySourceItemIds->execute($sourceItemIds) as $sourceItemId => $sourceCode) { - if ($sourceCode !== $defaultSourceCode) { - $customSourceItemIds[] = $sourceItemId; - } - } - $beforeSalableList = $this->getSalableStatuses->execute($customSourceItemIds); - $proceed($sourceItemIds); - $afterSalableList = $this->getSalableStatuses->execute($customSourceItemIds); - - $productsIdsToReindex = $this->getProductsIdsToProcess->execute($beforeSalableList, $afterSalableList); - if (!empty($productsIdsToReindex)) { - $this->priceIndexProcessor->reindexList($productsIdsToReindex, true); - } - } -} diff --git a/vendor/magento/module-inventory-catalog/etc/di.xml b/vendor/magento/module-inventory-catalog/etc/di.xml index f5e7210230b..a72055ff7a7 100644 --- a/vendor/magento/module-inventory-catalog/etc/di.xml +++ b/vendor/magento/module-inventory-catalog/etc/di.xml @@ -31,9 +31,6 @@ - - - @@ -198,4 +195,16 @@ + + + 10 + + + + + + Magento\InventoryCatalog\Model\PriceIndexUpdateProcessor + + + diff --git a/vendor/magento/module-inventory-catalog-search/Model/FullTextIndexUpdateProcessor.php b/vendor/magento/module-inventory-catalog-search/Model/FullTextIndexUpdateProcessor.php new file mode 100644 index 00000000000..c1c7d608448 --- /dev/null +++ b/vendor/magento/module-inventory-catalog-search/Model/FullTextIndexUpdateProcessor.php @@ -0,0 +1,81 @@ +fulltextIndexProcessor = $fulltextIndexProcessor; + $this->getProductsIdsToProcess = $getProductsIdsToProcess; + $this->sortOrder = $sortOrder; + } + + /** + * Perform fulltext index update for specific products after source items reindex. + * + * @param array $sourceItemIds + * @param array $saleableStatusesBeforeSync + * @param array $saleableStatusesAfterSync + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function process( + array $sourceItemIds, + array $saleableStatusesBeforeSync, + array $saleableStatusesAfterSync + ): void { + $productsIdsToProcess = $this->getProductsIdsToProcess->execute( + $saleableStatusesBeforeSync, + $saleableStatusesAfterSync + ); + + if (!empty($productsIdsToProcess)) { + $this->fulltextIndexProcessor->reindexList($productsIdsToProcess, true); + } + } + + /** + * @inheritdoc + * + * @return int + */ + public function getSortOrder(): int + { + return $this->sortOrder; + } +} diff --git a/vendor/magento/module-inventory-catalog-search/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/FulltextIndexUpdater.php b/vendor/magento/module-inventory-catalog-search/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/FulltextIndexUpdater.php deleted file mode 100644 index 4ae3da00940..00000000000 --- a/vendor/magento/module-inventory-catalog-search/Plugin/InventoryIndexer/Indexer/SourceItem/Strategy/Sync/FulltextIndexUpdater.php +++ /dev/null @@ -1,102 +0,0 @@ -fulltextIndexProcessor = $fulltextIndexProcessor; - $this->productIdsBySourceItemIds = $productIdsBySourceItemIds; - $this->getSalableStatuses = $getSalableStatuses; - $this->getProductsIdsToProcess = $getProductsIdsToProcess; - } - - /** - * Reindex fulltext entities - * - * @param Sync $subject - * @param callable $proceed - * @param array $sourceItemIds - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function aroundExecuteList( - Sync $subject, - callable $proceed, - array $sourceItemIds - ) { - $beforeSalableList = $this->getSalableStatuses->execute($sourceItemIds); - $proceed($sourceItemIds); - $afterSalableList = $this->getSalableStatuses->execute($sourceItemIds); - $productsIdsToProcess = $this->getProductsIdsToProcess->execute($beforeSalableList, $afterSalableList); - if (!empty($productsIdsToProcess)) { - $this->fulltextIndexProcessor->reindexList($productsIdsToProcess, true); - } - } - - /** - * Reindex fulltext entity - * - * @param Sync $subject - * @param callable $proceed - * @param int $sourceItemId - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function aroundExecuteRow( - Sync $subject, - callable $proceed, - int $sourceItemId - ) { - $beforeSalableList = $this->getSalableStatuses->execute([$sourceItemId]); - $proceed($sourceItemId); - $afterSalableList = $this->getSalableStatuses->execute([$sourceItemId]); - $productsIdsToProcess = $this->getProductsIdsToProcess->execute($beforeSalableList, $afterSalableList); - if (!empty($productsIdsToProcess)) { - $this->fulltextIndexProcessor->reindexList($productsIdsToProcess, true); - } - } -} diff --git a/vendor/magento/module-inventory-catalog-search/etc/di.xml b/vendor/magento/module-inventory-catalog-search/etc/di.xml index 99e8662b80e..1078a09b324 100644 --- a/vendor/magento/module-inventory-catalog-search/etc/di.xml +++ b/vendor/magento/module-inventory-catalog-search/etc/di.xml @@ -9,7 +9,16 @@ + + + 20 + + - + + + Magento\InventoryCatalogSearch\Model\FullTextIndexUpdateProcessor + + diff --git a/vendor/magento/module-inventory-indexer/Indexer/SourceItem/CompositeProductProcessorInterface.php b/vendor/magento/module-inventory-indexer/Indexer/SourceItem/CompositeProductProcessorInterface.php new file mode 100644 index 00000000000..5a02482423c --- /dev/null +++ b/vendor/magento/module-inventory-indexer/Indexer/SourceItem/CompositeProductProcessorInterface.php @@ -0,0 +1,32 @@ +getSkuListInStock = $getSkuListInStockToUpdate; $this->indexStructure = $indexStructureHandler; @@ -105,6 +121,8 @@ class Sync $this->defaultStockProvider = $defaultStockProvider; $this->reservationsIndexTable = $reservationsIndexTable; $this->prepareReservationsIndexData = $prepareReservationsIndexData; + $this->getSalableStatuses = $getSalableStatuses; + $this->saleabilityChangesProcessorsPool = $saleabilityChangesProcessorsPool; } /** @@ -114,6 +132,9 @@ class Sync */ public function executeList(array $sourceItemIds) : void { + // Store products salable statuses before reindex + $salableStatusesBefore = $this->getSalableStatuses->execute($sourceItemIds); + $skuListInStockList = $this->getSkuListInStock->execute($sourceItemIds); foreach ($skuListInStockList as $skuListInStock) { @@ -152,6 +173,36 @@ class Sync $this->reservationsIndexTable->dropTable($stockId); } + + // Store products salable statuses after reindex + $salableStatusesAfter = $this->getSalableStatuses->execute($sourceItemIds); + // Process products with changed salable statuses + $this->processProductsWithChangedSaleability($sourceItemIds, $salableStatusesBefore, $salableStatusesAfter); + } + + /** + * Process products with changed salable statuses + * + * @param array $sourceItemIds + * @param array $saleableStatusesBefore + * @param array $saleableStatusesAfter + * @return void + */ + private function processProductsWithChangedSaleability( + array $sourceItemIds, + array $saleableStatusesBefore, + array $saleableStatusesAfter + ): void { + $processors = $this->saleabilityChangesProcessorsPool; + + // Sort processors by sort order + uasort($processors, function ($a, $b) { + return $a->getSortOrder() <=> $b->getSortOrder(); + }); + + foreach ($processors as $processor) { + $processor->process($sourceItemIds, $saleableStatusesBefore, $saleableStatusesAfter); + } } /** diff --git a/vendor/magento/module-inventory-indexer/Model/GetProductsIdsToProcess.php b/vendor/magento/module-inventory-indexer/Model/GetProductsIdsToProcess.php index caa30a2c0a1..2ce0856e481 100644 --- a/vendor/magento/module-inventory-indexer/Model/GetProductsIdsToProcess.php +++ b/vendor/magento/module-inventory-indexer/Model/GetProductsIdsToProcess.php @@ -45,36 +45,58 @@ class GetProductsIdsToProcess * @param array $after * @param bool $forceDefaultStockProcessing * @return array + * @SuppressWarnings(PHPMD.UnusedLocalVariable) */ public function execute(array $before, array $after, bool $forceDefaultStockProcessing = false) : array { - $productIds = []; $productSkus = array_merge( array_diff(array_keys($before), array_keys($after)), array_diff(array_keys($after), array_keys($before)) ); foreach ($before as $sku => $salableData) { - if (!in_array($sku, $productSkus)) { - foreach ($salableData as $stockId => $isSalable) { - if (empty($after[$sku][$stockId]) - || $before[$sku][$stockId] !== $after[$sku][$stockId] - || ($stockId === $this->defaultStockProvider->getId() && $forceDefaultStockProcessing)) { - $productSkus[] = $sku; - } + if (in_array($sku, $productSkus)) { + continue; + } + $afterSalableData = $after[$sku] ?? []; + // get stock IDs from "after" that doesn't exist in "before" + $diff = array_diff(array_keys($afterSalableData), array_keys($salableData)); + if ($diff) { + $productSkus[] = $sku; + continue; + } + foreach ($salableData as $stockId => $isSalable) { + if (!isset($after[$sku][$stockId]) + || $before[$sku][$stockId] !== $after[$sku][$stockId] + || ($stockId === $this->defaultStockProvider->getId() && $forceDefaultStockProcessing)) { + $productSkus[] = $sku; } } } - if (!empty($productSkus)) { - $productSkus = array_unique($productSkus); - foreach ($productSkus as $sku) { - try { - $productId = $this->getProductIdsBySkus->execute([$sku]); - $productIds = array_merge($productIds, $productId); - } catch (NoSuchEntityException $e) { - continue; - } + + return $this->getProductIdsBySkus($productSkus); + } + + /** + * Retrieve product ids by skus + * + * @param array $productSkus + * @return array + */ + private function getProductIdsBySkus(array $productSkus): array + { + if (empty($productSkus)) { + return []; + } + + $productSkus = array_unique($productSkus); + $ids = []; + foreach ($productSkus as $sku) { + try { + $ids[] = $this->getProductIdsBySkus->execute([$sku]); + } catch (NoSuchEntityException $e) { + continue; } } - return $productIds; + return array_merge(...$ids); } }