Skip to content

Commit

Permalink
Merge pull request magento#1120 from magento-engcom/1117-Fix-hard-dep…
Browse files Browse the repository at this point in the history
…endency-InventoryCache-module-on-Inventory

Fix hard dependency InventoryCache module on Inventory module
  • Loading branch information
maghamed authored May 12, 2018
2 parents 045d9a5 + 7dc538c commit b50a893
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Inventory\Model\ResourceModel\SourceItem;

/**
* Provides product ids related to specified source items ids.
Expand All @@ -27,16 +26,34 @@ class GetProductIdsBySourceItemIds
*/
private $metadataPool;

/**
* @var string
*/
private $tableNameSourceItem;

/**
* @var string
*/
private $sourceItemIdFieldName;

/**
* GetProductIdsByStockIds constructor.
*
* @param ResourceConnection $resource
* @param MetadataPool $metadataPool
* @param string $tableNameSourceItem
* @param string $sourceItemIdFieldName
*/
public function __construct(ResourceConnection $resource, MetadataPool $metadataPool)
{
public function __construct(
ResourceConnection $resource,
MetadataPool $metadataPool,
$tableNameSourceItem,
$sourceItemIdFieldName
) {
$this->resource = $resource;
$this->metadataPool = $metadataPool;
$this->tableNameSourceItem = $tableNameSourceItem;
$this->sourceItemIdFieldName = $sourceItemIdFieldName;
}

/**
Expand All @@ -50,13 +67,13 @@ public function execute(array $sourceItemIds): array
{
$productLinkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$connection = $this->resource->getConnection();
$sourceItemTable = $this->resource->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM);
$sourceItemTable = $this->resource->getTableName($this->tableNameSourceItem);
$select = $connection->select()
->from(
['source_items_table' => $sourceItemTable],
[]
)->where(
SourceItem::ID_FIELD_NAME . ' IN (?)',
$this->sourceItemIdFieldName . ' IN (?)',
$sourceItemIds
)->join(
['product_table' => $this->resource->getTableName('catalog_product_entity')],
Expand Down
4 changes: 3 additions & 1 deletion app/code/Magento/InventoryCache/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
"php": "~7.1.3||~7.2.0",
"magento/framework": "*",
"magento/module-catalog": "*",
"magento/module-inventory": "*",
"magento/module-inventory-catalog-api": "*",
"magento/module-inventory-indexer": "*"
},
"suggest": {
"magento/module-inventory": "*"
},
"type": "magento2-module",
"license": [
"OSL-3.0",
Expand Down
6 changes: 6 additions & 0 deletions app/code/Magento/InventoryCache/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@
<type name="Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer">
<plugin name="invalidate_products_cache" type="Magento\InventoryCache\Plugin\InventoryIndexer\Indexer\Source\SourceItemIndexer\CacheFlush"/>
</type>
<type name="Magento\InventoryCache\Model\ResourceModel\GetProductIdsBySourceItemIds">
<arguments>
<argument name="tableNameSourceItem" xsi:type="const">Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM</argument>
<argument name="sourceItemIdFieldName" xsi:type="const">Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME</argument>
</arguments>
</type>
</config>

0 comments on commit b50a893

Please sign in to comment.