Skip to content

Commit b59e48c

Browse files
authored
Merge pull request #448 from adobe-commerce-tier-4/T4-02-16-2024
T4-02-16-2024 PR Delivery
2 parents d411e29 + 59128d7 commit b59e48c

File tree

38 files changed

+1097
-1378
lines changed

38 files changed

+1097
-1378
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/************************************************************************
3+
*
4+
* Copyright 2024 Adobe
5+
* All Rights Reserved.
6+
*
7+
* NOTICE: All information contained herein is, and remains
8+
* the property of Adobe and its suppliers, if any. The intellectual
9+
* and technical concepts contained herein are proprietary to Adobe
10+
* and its suppliers and are protected by all applicable intellectual
11+
* property laws, including trade secret and copyright laws.
12+
* Dissemination of this information or reproduction of this material
13+
* is strictly forbidden unless prior written permission is obtained
14+
* from Adobe.
15+
* ************************************************************************
16+
*/
17+
declare(strict_types=1);
18+
19+
namespace Magento\InventoryCache\Model;
20+
21+
use Magento\InventoryCatalogApi\Model\GetProductIdsBySkusInterface;
22+
use Magento\InventoryIndexer\Model\ProductSalabilityChangeProcessorInterface;
23+
use Magento\InventoryIndexer\Model\ResourceModel\GetCategoryIdsByProductIds;
24+
25+
class FlushCacheOnProductSalabilityChange implements ProductSalabilityChangeProcessorInterface
26+
{
27+
/**
28+
* @param GetProductIdsBySkusInterface $getProductIdsBySkus
29+
* @param FlushCacheByProductIds $flushCacheByIds
30+
* @param GetCategoryIdsByProductIds $getCategoryIdsByProductIds
31+
* @param FlushCacheByCategoryIds $flushCategoryByCategoryIds
32+
*/
33+
public function __construct(
34+
private readonly GetProductIdsBySkusInterface $getProductIdsBySkus,
35+
private readonly FlushCacheByProductIds $flushCacheByIds,
36+
private readonly GetCategoryIdsByProductIds $getCategoryIdsByProductIds,
37+
private readonly FlushCacheByCategoryIds $flushCategoryByCategoryIds
38+
) {
39+
}
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function execute(array $skus): void
45+
{
46+
$ids = array_values($this->getProductIdsBySkus->execute($skus));
47+
if (empty($ids)) {
48+
return;
49+
}
50+
$categoryIds = $this->getCategoryIdsByProductIds->execute($ids);
51+
$this->flushCacheByIds->execute($ids);
52+
$this->flushCategoryByCategoryIds->execute($categoryIds);
53+
}
54+
}

InventoryCache/etc/di.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@
3434
</argument>
3535
</arguments>
3636
</type>
37+
<type name="Magento\InventoryIndexer\Model\CompositeProductSalabilityChangeProcessor">
38+
<arguments>
39+
<argument name="processors" xsi:type="array">
40+
<item name="flush_cache" sortOrder="30" xsi:type="object">Magento\InventoryCache\Model\FlushCacheOnProductSalabilityChange</item>
41+
</argument>
42+
</arguments>
43+
</type>
3744
</config>

InventoryCatalog/Model/Cache/ProductIdsBySkusStorage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public function set(string $sku, int $id): void
4949
$this->storage[$this->normalizeSku($sku)] = $id;
5050
}
5151

52+
/**
53+
* Invalidate cache for provided sku
54+
*
55+
* @param string $sku
56+
*/
57+
public function delete(string $sku): void
58+
{
59+
unset($this->storage[$this->normalizeSku($sku)]);
60+
}
61+
5262
/**
5363
* Clean storage
5464
*

InventoryCatalog/Model/Cache/ProductSkusByIdsStorage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public function set(int $id, string $sku): void
4949
$this->storage[$id] = $sku;
5050
}
5151

52+
/**
53+
* Invalidate cache for provided id
54+
*
55+
* @param int $id
56+
*/
57+
public function delete(int $id): void
58+
{
59+
unset($this->storage[$id]);
60+
}
61+
5262
/**
5363
* Clean storage
5464
*

InventoryCatalog/Model/Cache/ProductTypesBySkusStorage.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ public function set(string $sku, string $type): void
4949
$this->storage[$this->normalizeSku($sku)] = $type;
5050
}
5151

52+
/**
53+
* Invalidate cache for provided sku
54+
*
55+
* @param string $sku
56+
*/
57+
public function delete(string $sku): void
58+
{
59+
unset($this->storage[$this->normalizeSku($sku)]);
60+
}
61+
5262
/**
5363
* Clean storage
5464
*

0 commit comments

Comments
 (0)