Skip to content

Commit 626f7f8

Browse files
committed
MC-29376: [On Pre] [2.2.7] Status Change Doesn't Update the Stock Index
- Add ability to prevent running stock indexer when msi is enabled
1 parent f4422d9 commit 626f7f8

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
use Magento\CatalogImportExport\Model\Import\Product\MediaGalleryProcessor;
1515
use Magento\CatalogImportExport\Model\Import\Product\RowValidatorInterface as ValidatorInterface;
1616
use Magento\CatalogImportExport\Model\Import\Product\StatusProcessor;
17+
use Magento\CatalogImportExport\Model\Import\Product\StockProcessor;
1718
use Magento\CatalogImportExport\Model\StockItemImporterInterface;
1819
use Magento\CatalogInventory\Api\Data\StockItemInterface;
19-
use Magento\CatalogInventory\Model\Indexer\Stock\Processor as StockProcessor;
2020
use Magento\Framework\App\Filesystem\DirectoryList;
2121
use Magento\Framework\App\ObjectManager;
2222
use Magento\Framework\Exception\LocalizedException;
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\CatalogImportExport\Model\Import\Product;
9+
10+
use Magento\Framework\Indexer\IndexerRegistry;
11+
12+
/**
13+
* Imported product stock manager
14+
*/
15+
class StockProcessor
16+
{
17+
/**
18+
* @var IndexerRegistry
19+
*/
20+
private $indexerRegistry;
21+
/**
22+
* @var array
23+
*/
24+
private $indexers;
25+
26+
/**
27+
* Initializes dependencies.
28+
*
29+
* @param IndexerRegistry $indexerRegistry
30+
* @param array $indexers
31+
*/
32+
public function __construct(
33+
IndexerRegistry $indexerRegistry,
34+
array $indexers = []
35+
) {
36+
$this->indexerRegistry = $indexerRegistry;
37+
$this->indexers = array_filter($indexers);
38+
}
39+
40+
/**
41+
* Reindex products by ids
42+
*
43+
* @param array $ids
44+
* @return void
45+
*/
46+
public function reindexList(array $ids = []): void
47+
{
48+
if ($ids) {
49+
foreach ($this->indexers as $indexerName) {
50+
$indexer = $this->indexerRegistry->get($indexerName);
51+
if (!$indexer->isScheduled()) {
52+
$indexer->reindexList($ids);
53+
}
54+
}
55+
}
56+
}
57+
}

app/code/Magento/CatalogImportExport/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
<plugin name="invalidateProductCategoryIndexerOnImport" type="Magento\CatalogImportExport\Model\Indexer\Product\Category\Plugin\Import" />
1717
<plugin name="invalidateCategoryProductIndexerOnImport" type="Magento\CatalogImportExport\Model\Indexer\Category\Product\Plugin\Import" />
1818
</type>
19+
<type name="Magento\CatalogImportExport\Model\Import\Product\StockProcessor">
20+
<arguments>
21+
<argument name="indexers" xsi:type="array">
22+
<item name="cataloginventory_stock" xsi:type="const">Magento\CatalogInventory\Model\Indexer\Stock\Processor::INDEXER_ID</item>
23+
</argument>
24+
</arguments>
25+
</type>
1926
<type name="Magento\CatalogImportExport\Model\Import\Product\Validator">
2027
<arguments>
2128
<argument name="validators" xsi:type="array">

0 commit comments

Comments
 (0)