|
8 | 8 |
|
9 | 9 | use Magento\Catalog\Api\ProductRepositoryInterface;
|
10 | 10 | use Magento\Catalog\Model\Config as CatalogConfig;
|
11 |
| -use Magento\Catalog\Model\Product\Visibility; |
12 | 11 | use Magento\Catalog\Model\Indexer\Product\Category as ProductCategoryIndexer;
|
13 | 12 | use Magento\Catalog\Model\Indexer\Product\Price\Processor as ProductPriceIndexer;
|
| 13 | +use Magento\Catalog\Model\Product\Visibility; |
14 | 14 | use Magento\CatalogImportExport\Model\Import\Product\ImageTypeProcessor;
|
15 | 15 | use Magento\CatalogImportExport\Model\Import\Product\LinkProcessor;
|
16 | 16 | use Magento\CatalogImportExport\Model\Import\Product\MediaGalleryProcessor;
|
|
31 | 31 | use Magento\Framework\Model\ResourceModel\Db\ObjectRelationProcessor;
|
32 | 32 | use Magento\Framework\Model\ResourceModel\Db\TransactionManagerInterface;
|
33 | 33 | use Magento\Framework\Stdlib\DateTime;
|
| 34 | +use Magento\Framework\Indexer\Config\DependencyInfoProviderInterface; |
34 | 35 | use Magento\ImportExport\Model\Import;
|
35 | 36 | use Magento\ImportExport\Model\Import\Entity\AbstractEntity;
|
36 | 37 | use Magento\ImportExport\Model\Import\ErrorProcessing\ProcessingError;
|
@@ -767,6 +768,11 @@ class Product extends AbstractEntity
|
767 | 768 | */
|
768 | 769 | private $stockItemProcessor;
|
769 | 770 |
|
| 771 | + /** |
| 772 | + * @var DependencyInfoProviderInterface |
| 773 | + */ |
| 774 | + private $dependencyInfoProvider; |
| 775 | + |
770 | 776 | /**
|
771 | 777 | * @param \Magento\Framework\Json\Helper\Data $jsonHelper
|
772 | 778 | * @param \Magento\ImportExport\Helper\Data $importExportData
|
@@ -817,6 +823,7 @@ class Product extends AbstractEntity
|
817 | 823 | * @param LinkProcessor|null $linkProcessor
|
818 | 824 | * @param File|null $fileDriver
|
819 | 825 | * @param StockItemProcessorInterface|null $stockItemProcessor
|
| 826 | + * @param DependencyInfoProviderInterface|null $dependencyInfoProvider |
820 | 827 | * @throws LocalizedException
|
821 | 828 | * @throws \Magento\Framework\Exception\FileSystemException
|
822 | 829 | * @SuppressWarnings(PHPMD.ExcessiveParameterList)
|
@@ -872,7 +879,8 @@ public function __construct(
|
872 | 879 | StockProcessor $stockProcessor = null,
|
873 | 880 | LinkProcessor $linkProcessor = null,
|
874 | 881 | ?File $fileDriver = null,
|
875 |
| - ?StockItemProcessorInterface $stockItemProcessor = null |
| 882 | + ?StockItemProcessorInterface $stockItemProcessor = null, |
| 883 | + ?DependencyInfoProviderInterface $dependencyInfoProvider = null |
876 | 884 | ) {
|
877 | 885 | $this->_eventManager = $eventManager;
|
878 | 886 | $this->stockRegistry = $stockRegistry;
|
@@ -938,6 +946,8 @@ public function __construct(
|
938 | 946 | ->get(ProductRepositoryInterface::class);
|
939 | 947 | $this->stockItemProcessor = $stockItemProcessor ?? ObjectManager::getInstance()
|
940 | 948 | ->get(StockItemProcessorInterface::class);
|
| 949 | + $this->dependencyInfoProvider = $dependencyInfoProvider ?? ObjectManager::getInstance() |
| 950 | + ->get(DependencyInfoProviderInterface::class); |
941 | 951 | }
|
942 | 952 |
|
943 | 953 | /**
|
@@ -1662,7 +1672,7 @@ protected function _saveProducts()
|
1662 | 1672 | $prevAttributeSet,
|
1663 | 1673 | $attributes
|
1664 | 1674 | );
|
1665 |
| - // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch |
| 1675 | + // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch |
1666 | 1676 | } catch (Skip $skip) {
|
1667 | 1677 | // Product is skipped. Go on to the next one.
|
1668 | 1678 | }
|
@@ -2464,14 +2474,25 @@ private function reindexStockStatus(array $productIds): void
|
2464 | 2474 | */
|
2465 | 2475 | private function reindexProducts($productIdsToReindex = [])
|
2466 | 2476 | {
|
2467 |
| - $indexersToReindex = [ |
2468 |
| - ProductCategoryIndexer::INDEXER_ID, |
2469 |
| - ProductPriceIndexer::INDEXER_ID |
2470 |
| - ]; |
2471 |
| - foreach ($indexersToReindex as $id) { |
2472 |
| - $indexer = $this->indexerRegistry->get($id); |
2473 |
| - if (is_array($productIdsToReindex) && count($productIdsToReindex) > 0 && !$indexer->isScheduled()) { |
2474 |
| - $indexer->reindexList($productIdsToReindex); |
| 2477 | + if (is_array($productIdsToReindex) && !empty($productIdsToReindex)) { |
| 2478 | + $indexersToReindex = [ |
| 2479 | + ProductCategoryIndexer::INDEXER_ID, |
| 2480 | + ProductPriceIndexer::INDEXER_ID |
| 2481 | + ]; |
| 2482 | + foreach ($indexersToReindex as $id) { |
| 2483 | + $indexer = $this->indexerRegistry->get($id); |
| 2484 | + if (!$indexer->isScheduled()) { |
| 2485 | + //trick for dependent indexers in scheduled mode |
| 2486 | + //related issue: AC-7851 |
| 2487 | + $idsToRunBefore = $this->dependencyInfoProvider->getIndexerIdsToRunBefore($id); |
| 2488 | + foreach ($idsToRunBefore as $dependentId) { |
| 2489 | + $dependentIndexer = $this->indexerRegistry->get($dependentId); |
| 2490 | + if ($dependentIndexer->isScheduled()) { |
| 2491 | + $dependentIndexer->reindexList($productIdsToReindex); |
| 2492 | + } |
| 2493 | + } |
| 2494 | + $indexer->reindexList($productIdsToReindex); |
| 2495 | + } |
2475 | 2496 | }
|
2476 | 2497 | }
|
2477 | 2498 | }
|
|
0 commit comments