Skip to content

Commit b50a893

Browse files
authored
Merge pull request magento#1120 from magento-engcom/1117-Fix-hard-dependency-InventoryCache-module-on-Inventory
Fix hard dependency InventoryCache module on Inventory module
2 parents 045d9a5 + 7dc538c commit b50a893

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsBySourceItemIds.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\EntityManager\MetadataPool;
13-
use Magento\Inventory\Model\ResourceModel\SourceItem;
1413

1514
/**
1615
* Provides product ids related to specified source items ids.
@@ -27,16 +26,34 @@ class GetProductIdsBySourceItemIds
2726
*/
2827
private $metadataPool;
2928

29+
/**
30+
* @var string
31+
*/
32+
private $tableNameSourceItem;
33+
34+
/**
35+
* @var string
36+
*/
37+
private $sourceItemIdFieldName;
38+
3039
/**
3140
* GetProductIdsByStockIds constructor.
3241
*
3342
* @param ResourceConnection $resource
3443
* @param MetadataPool $metadataPool
44+
* @param string $tableNameSourceItem
45+
* @param string $sourceItemIdFieldName
3546
*/
36-
public function __construct(ResourceConnection $resource, MetadataPool $metadataPool)
37-
{
47+
public function __construct(
48+
ResourceConnection $resource,
49+
MetadataPool $metadataPool,
50+
$tableNameSourceItem,
51+
$sourceItemIdFieldName
52+
) {
3853
$this->resource = $resource;
3954
$this->metadataPool = $metadataPool;
55+
$this->tableNameSourceItem = $tableNameSourceItem;
56+
$this->sourceItemIdFieldName = $sourceItemIdFieldName;
4057
}
4158

4259
/**
@@ -50,13 +67,13 @@ public function execute(array $sourceItemIds): array
5067
{
5168
$productLinkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
5269
$connection = $this->resource->getConnection();
53-
$sourceItemTable = $this->resource->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM);
70+
$sourceItemTable = $this->resource->getTableName($this->tableNameSourceItem);
5471
$select = $connection->select()
5572
->from(
5673
['source_items_table' => $sourceItemTable],
5774
[]
5875
)->where(
59-
SourceItem::ID_FIELD_NAME . ' IN (?)',
76+
$this->sourceItemIdFieldName . ' IN (?)',
6077
$sourceItemIds
6178
)->join(
6279
['product_table' => $this->resource->getTableName('catalog_product_entity')],

app/code/Magento/InventoryCache/composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
"php": "~7.1.3||~7.2.0",
66
"magento/framework": "*",
77
"magento/module-catalog": "*",
8-
"magento/module-inventory": "*",
98
"magento/module-inventory-catalog-api": "*",
109
"magento/module-inventory-indexer": "*"
1110
},
11+
"suggest": {
12+
"magento/module-inventory": "*"
13+
},
1214
"type": "magento2-module",
1315
"license": [
1416
"OSL-3.0",

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@
1212
<type name="Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer">
1313
<plugin name="invalidate_products_cache" type="Magento\InventoryCache\Plugin\InventoryIndexer\Indexer\Source\SourceItemIndexer\CacheFlush"/>
1414
</type>
15+
<type name="Magento\InventoryCache\Model\ResourceModel\GetProductIdsBySourceItemIds">
16+
<arguments>
17+
<argument name="tableNameSourceItem" xsi:type="const">Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM</argument>
18+
<argument name="sourceItemIdFieldName" xsi:type="const">Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME</argument>
19+
</arguments>
20+
</type>
1521
</config>

0 commit comments

Comments
 (0)