Skip to content

Commit 412ba39

Browse files
Merge pull request #399 from magento-l3/PR-L3-08112023
Pr l3 08112023
2 parents 95df453 + 423d564 commit 412ba39

File tree

20 files changed

+953
-478
lines changed

20 files changed

+953
-478
lines changed
Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,66 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer\Indexer\SourceItem\Strategy\Sync;
8+
namespace Magento\InventoryBundleProductIndexer\Indexer;
99

1010
use Magento\Framework\Exception\StateException;
1111
use Magento\InventoryBundleProductIndexer\Indexer\SourceItem\SourceItemIndexer as BundleProductsSourceItemIndexer;
12-
use Magento\InventoryIndexer\Indexer\SourceItem\Strategy\Sync;
12+
use Magento\InventoryIndexer\Indexer\SourceItem\CompositeProductProcessorInterface;
1313

1414
/**
1515
* Reindex bundle product source items.
1616
*/
17-
class SourceItemIndexerPlugin
17+
class SourceItemIndexerProcessor implements CompositeProductProcessorInterface
1818
{
1919
/**
2020
* @var BundleProductsSourceItemIndexer
2121
*/
2222
private $bundleProductsSourceItemIndexer;
2323

24+
/**
25+
* Processor sort order
26+
*
27+
* @var int
28+
*/
29+
private $sortOrder;
30+
2431
/**
2532
* @param BundleProductsSourceItemIndexer $configurableProductsSourceItemIndexer
33+
* @param array $sortOrder
2634
*/
2735
public function __construct(
28-
BundleProductsSourceItemIndexer $configurableProductsSourceItemIndexer
36+
BundleProductsSourceItemIndexer $configurableProductsSourceItemIndexer,
37+
int $sortOrder = 5
2938
) {
3039
$this->bundleProductsSourceItemIndexer = $configurableProductsSourceItemIndexer;
40+
$this->sortOrder = $sortOrder;
3141
}
3242

3343
/**
3444
* Reindex source items list for bundle products.
3545
*
36-
* @param Sync $subject
37-
* @param callable $proceed
3846
* @param array $sourceItemIds
47+
* @param array $saleableStatusesBeforeSync
48+
* @param array $saleableStatusesAfterSync
49+
* @return void
3950
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4051
* @throws StateException
4152
*/
42-
public function aroundExecuteList(
43-
Sync $subject,
44-
callable $proceed,
45-
array $sourceItemIds
46-
) {
47-
$proceed($sourceItemIds);
53+
public function process(
54+
array $sourceItemIds,
55+
array $saleableStatusesBeforeSync,
56+
array $saleableStatusesAfterSync
57+
): void {
4858
$this->bundleProductsSourceItemIndexer->executeList($sourceItemIds);
4959
}
60+
61+
/**
62+
* @inheritdoc
63+
*
64+
* @return int
65+
*/
66+
public function getSortOrder(): int
67+
{
68+
return $this->sortOrder;
69+
}
5070
}

InventoryBundleProductIndexer/etc/di.xml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
<plugin name="bundle_product_index_full" type="Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer\Indexer\Stock\Strategy\Sync\ReindexFullPlugin"/>
1111
<plugin name="bundle_product_index_list" type="Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer\Indexer\Stock\Strategy\Sync\ReindexListPlugin"/>
1212
</type>
13-
<type name="Magento\InventoryIndexer\Indexer\SourceItem\Strategy\Sync">
14-
<plugin name="bundle_product_index" type="Magento\InventoryBundleProductIndexer\Plugin\InventoryIndexer\Indexer\SourceItem\Strategy\Sync\SourceItemIndexerPlugin" sortOrder="20"/>
15-
</type>
1613
<type name="Magento\InventoryBundleProductIndexer\Indexer\Stock\StockIndexer">
1714
<arguments>
1815
<argument name="indexHandler" xsi:type="object">Magento\InventoryIndexer\Indexer\IndexHandler</argument>
@@ -33,4 +30,16 @@
3330
<type name="Magento\Bundle\Api\ProductLinkManagementAddChildrenInterface">
3431
<plugin name="reindex_source_items_after_bulk_add_bundle_selection" type="Magento\InventoryBundleProductIndexer\Plugin\Bundle\Model\LinkManagement\ReindexSourceItemsAfterBulkAddBundleSelectionPlugin"/>
3532
</type>
33+
<type name="Magento\InventoryBundleProductIndexer\Indexer\SourceItemIndexerProcessor">
34+
<arguments>
35+
<argument name="sortOrder" xsi:type="number">5</argument>
36+
</arguments>
37+
</type>
38+
<type name="Magento\InventoryIndexer\Indexer\SourceItem\Strategy\Sync">
39+
<arguments>
40+
<argument name="saleabilityChangesProcessorsPool" xsi:type="array">
41+
<item name="sourceItemIndexerProcessor" xsi:type="object">Magento\InventoryBundleProductIndexer\Indexer\SourceItemIndexerProcessor</item>
42+
</argument>
43+
</arguments>
44+
</type>
3645
</config>
Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\InventoryCache\Plugin\InventoryIndexer\Indexer\SourceItem\Strategy\Sync;
8+
namespace Magento\InventoryCache\Model;
99

1010
use Magento\Framework\Indexer\IndexerRegistry;
11-
use Magento\InventoryCache\Model\FlushCacheByCategoryIds;
12-
use Magento\InventoryCache\Model\FlushCacheByProductIds;
11+
use Magento\InventoryIndexer\Indexer\InventoryIndexer;
12+
use Magento\InventoryIndexer\Indexer\SourceItem\CompositeProductProcessorInterface;
1313
use Magento\InventoryIndexer\Model\GetProductsIdsToProcess;
14-
use Magento\InventoryIndexer\Indexer\SourceItem\Strategy\Sync;
15-
use Magento\InventoryIndexer\Indexer\SourceItem\GetSalableStatuses;
1614
use Magento\InventoryIndexer\Model\ResourceModel\GetCategoryIdsByProductIds;
17-
use Magento\InventoryIndexer\Indexer\InventoryIndexer;
1815

19-
/**
20-
* Clean cache for corresponding products after source item reindex.
21-
*/
22-
class CacheFlush
16+
class CacheFlushProcessor implements CompositeProductProcessorInterface
2317
{
18+
/**
19+
* Processor sort order
20+
*
21+
* @var int
22+
*/
23+
private $sortOrder;
24+
2425
/**
2526
* @var FlushCacheByProductIds
2627
*/
@@ -31,11 +32,6 @@ class CacheFlush
3132
*/
3233
private $getCategoryIdsByProductIds;
3334

34-
/**
35-
* @var GetSalableStatuses
36-
*/
37-
private $getSalableStatuses;
38-
3935
/**
4036
* @var FlushCacheByCategoryIds
4137
*/
@@ -44,62 +40,73 @@ class CacheFlush
4440
/**
4541
* @var GetProductsIdsToProcess
4642
*/
47-
private $getProductsIdsToProcess;
43+
private GetProductsIdsToProcess $getProductsIdsToProcess;
4844

4945
/**
5046
* @var IndexerRegistry
5147
*/
52-
private $indexerRegistry;
48+
private IndexerRegistry $indexerRegistry;
5349

5450
/**
5551
* @param FlushCacheByProductIds $flushCacheByIds
5652
* @param GetCategoryIdsByProductIds $getCategoryIdsByProductIds
5753
* @param FlushCacheByCategoryIds $flushCategoryByCategoryIds
58-
* @param GetSalableStatuses $getSalableStatuses
5954
* @param GetProductsIdsToProcess $getProductsIdsToProcess
6055
* @param IndexerRegistry $indexerRegistry
56+
* @param int $sortOrder
6157
*/
6258
public function __construct(
6359
FlushCacheByProductIds $flushCacheByIds,
6460
GetCategoryIdsByProductIds $getCategoryIdsByProductIds,
6561
FlushCacheByCategoryIds $flushCategoryByCategoryIds,
66-
GetSalableStatuses $getSalableStatuses,
6762
GetProductsIdsToProcess $getProductsIdsToProcess,
68-
IndexerRegistry $indexerRegistry
63+
IndexerRegistry $indexerRegistry,
64+
int $sortOrder = 30
6965
) {
7066
$this->flushCacheByIds = $flushCacheByIds;
7167
$this->getCategoryIdsByProductIds = $getCategoryIdsByProductIds;
7268
$this->flushCategoryByCategoryIds = $flushCategoryByCategoryIds;
73-
$this->getSalableStatuses = $getSalableStatuses;
7469
$this->getProductsIdsToProcess = $getProductsIdsToProcess;
7570
$this->indexerRegistry = $indexerRegistry;
71+
$this->sortOrder = $sortOrder;
7672
}
7773

7874
/**
7975
* Clean cache for specific products after source items reindex.
8076
*
81-
* @param Sync $subject
82-
* @param callable $proceed
8377
* @param array $sourceItemIds
78+
* @param array $saleableStatusesBeforeSync
79+
* @param array $saleableStatusesAfterSync
8480
* @return void
85-
* @throws \Exception in case catalog product entity type hasn't been initialized.
8681
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
8782
*/
88-
public function aroundExecuteList(Sync $subject, callable $proceed, array $sourceItemIds) : void
89-
{
90-
$beforeSalableList = $this->getSalableStatuses->execute($sourceItemIds);
91-
$proceed($sourceItemIds);
92-
$afterSalableList = $this->getSalableStatuses->execute($sourceItemIds);
83+
public function process(
84+
array $sourceItemIds,
85+
array $saleableStatusesBeforeSync,
86+
array $saleableStatusesAfterSync
87+
): void {
9388
$forceDefaultProcessing = !$this->indexerRegistry->get(InventoryIndexer::INDEXER_ID)->isScheduled();
89+
9490
$productsIdsToFlush = $this->getProductsIdsToProcess->execute(
95-
$beforeSalableList,
96-
$afterSalableList,
91+
$saleableStatusesBeforeSync,
92+
$saleableStatusesAfterSync,
9793
$forceDefaultProcessing
9894
);
95+
9996
if (!empty($productsIdsToFlush)) {
10097
$categoryIds = $this->getCategoryIdsByProductIds->execute($productsIdsToFlush);
10198
$this->flushCacheByIds->execute($productsIdsToFlush);
10299
$this->flushCategoryByCategoryIds->execute($categoryIds);
103100
}
104101
}
102+
103+
/**
104+
* @inheritdoc
105+
*
106+
* @return int
107+
*/
108+
public function getSortOrder(): int
109+
{
110+
return $this->sortOrder;
111+
}
105112
}
Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,24 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\InventoryCache\Test\Unit\Plugin\InventoryIndexer\Indexer\SourceItem\Strategy\Sync;
8+
namespace Magento\InventoryCache\Test\Unit\Model;
99

10-
use Magento\Framework\Indexer\IndexerRegistry;
1110
use Magento\Framework\Indexer\IndexerInterface;
12-
use Magento\InventoryCache\Plugin\InventoryIndexer\Indexer\SourceItem\Strategy\Sync\CacheFlush;
11+
use Magento\Framework\Indexer\IndexerRegistry;
12+
use Magento\InventoryCache\Model\CacheFlushProcessor;
1313
use Magento\InventoryCache\Model\FlushCacheByCategoryIds;
1414
use Magento\InventoryCache\Model\FlushCacheByProductIds;
15-
use Magento\InventoryIndexer\Model\ResourceModel\GetCategoryIdsByProductIds;
1615
use Magento\InventoryIndexer\Model\GetProductsIdsToProcess;
17-
use Magento\InventoryIndexer\Indexer\SourceItem\GetSalableStatuses;
18-
use Magento\InventoryIndexer\Indexer\SourceItem\Strategy\Sync;
19-
use PHPUnit\Framework\TestCase;
16+
use Magento\InventoryIndexer\Model\ResourceModel\GetCategoryIdsByProductIds;
2017
use PHPUnit\Framework\MockObject\MockObject;
18+
use PHPUnit\Framework\TestCase;
2119

22-
class CacheFlushTest extends TestCase
20+
class CacheFlushProcessorTest extends TestCase
2321
{
2422
/**
2523
* @var CacheFlush
2624
*/
27-
private $cacheFlush;
25+
private $cacheFlushProcessor;
2826

2927
/**
3028
* @var FlushCacheByProductIds|MockObject
@@ -41,26 +39,11 @@ class CacheFlushTest extends TestCase
4139
*/
4240
private $flushCategoryByCategoryIds;
4341

44-
/**
45-
* @var GetSalableStatuses|MockObject
46-
*/
47-
private $getSalableStatuses;
48-
4942
/**
5043
* @var GetProductsIdsToProcess|MockObject
5144
*/
5245
private $getProductsIdsToProcess;
5346

54-
/**
55-
* @var Sync|MockObject
56-
*/
57-
private $sync;
58-
59-
/**
60-
* @var \Callable|MockObject
61-
*/
62-
private $proceedMock;
63-
6447
/**
6548
* @var IndexerRegistry|MockObject
6649
*/
@@ -71,16 +54,8 @@ class CacheFlushTest extends TestCase
7154
*/
7255
private $indexer;
7356

74-
/**
75-
* @var bool
76-
*/
77-
private $isProceedMockCalled = false;
78-
7957
protected function setUp(): void
8058
{
81-
$this->proceedMock = function () {
82-
$this->isProceedMockCalled = true;
83-
};
8459
$this->flushCacheByIds = $this->getMockBuilder(FlushCacheByProductIds::class)
8560
->disableOriginalConstructor()
8661
->getMock();
@@ -90,40 +65,33 @@ protected function setUp(): void
9065
$this->flushCategoryByCategoryIds = $this->getMockBuilder(FlushCacheByCategoryIds::class)
9166
->disableOriginalConstructor()
9267
->getMock();
93-
$this->getSalableStatuses = $this->getMockBuilder(GetSalableStatuses::class)
94-
->disableOriginalConstructor()
95-
->getMock();
9668
$this->getProductsIdsToProcess = $this->getMockBuilder(GetProductsIdsToProcess::class)
9769
->disableOriginalConstructor()
9870
->getMock();
99-
$this->sync = $this->getMockBuilder(Sync::class)
100-
->disableOriginalConstructor()
101-
->getMock();
10271
$this->indexer = $this->getMockBuilder(IndexerInterface::class)
10372
->getMockForAbstractClass();
10473
$this->indexerRegistry = $this->getMockBuilder(IndexerRegistry::class)
10574
->disableOriginalConstructor()
10675
->getMock();
107-
$this->cacheFlush = new CacheFlush(
76+
$this->cacheFlushProcessor = new CacheFlushProcessor(
10877
$this->flushCacheByIds,
10978
$this->getCategoryIdsByProductIds,
11079
$this->flushCategoryByCategoryIds,
111-
$this->getSalableStatuses,
11280
$this->getProductsIdsToProcess,
11381
$this->indexerRegistry
11482
);
11583
}
11684

11785
/**
118-
* @dataProvider executeListDataProvider
86+
* @dataProvider processDataProvider
11987
* @param array $sourceItemIds
12088
* @param array $beforeSalableList
12189
* @param array $afterSalableList
12290
* @param array $changedProductIds,
12391
* @param int $numberOfCacheCleans,
12492
* @return void
12593
*/
126-
public function testAroundExecuteList(
94+
public function testProcess(
12795
array $sourceItemIds,
12896
array $beforeSalableList,
12997
array $afterSalableList,
@@ -133,16 +101,9 @@ public function testAroundExecuteList(
133101
$this->indexerRegistry->expects($this->once())
134102
->method('get')
135103
->willReturn($this->indexer);
136-
$this->indexer->expects($this->any())
104+
$this->indexer->expects($this->once())
137105
->method('isScheduled')
138106
->willReturn(true);
139-
$this->getSalableStatuses->expects($this->exactly(2))
140-
->method('execute')
141-
->with($sourceItemIds)
142-
->willReturnOnConsecutiveCalls(
143-
$beforeSalableList,
144-
$afterSalableList
145-
);
146107
$this->getProductsIdsToProcess->expects($this->once())
147108
->method('execute')
148109
->with($beforeSalableList, $afterSalableList)
@@ -158,15 +119,13 @@ public function testAroundExecuteList(
158119
$this->flushCategoryByCategoryIds->expects($this->exactly($numberOfCacheCleans))
159120
->method('execute');
160121

161-
$this->cacheFlush->aroundExecuteList($this->sync, $this->proceedMock, $sourceItemIds);
162-
$this->assertTrue($this->isProceedMockCalled);
122+
$this->cacheFlushProcessor->process($sourceItemIds, $beforeSalableList, $afterSalableList);
163123
}
164124

165125
/**
166-
* Data provider for testAroundExecuteList
167126
* @return array
168127
*/
169-
public function executeListDataProvider(): array
128+
public function processDataProvider(): array
170129
{
171130
return [
172131
[[1], ['sku1' => [1 => true]], ['sku1' => [1 => true]], [], 0],

0 commit comments

Comments
 (0)