diff --git a/app/code/Magento/InventoryCache/Model/FlushCacheByProductIds.php b/app/code/Magento/InventoryCache/Model/FlushCacheByProductIds.php index 580b0853e95cf..7ce14dfdac7e2 100644 --- a/app/code/Magento/InventoryCache/Model/FlushCacheByProductIds.php +++ b/app/code/Magento/InventoryCache/Model/FlushCacheByProductIds.php @@ -7,7 +7,6 @@ namespace Magento\InventoryCache\Model; -use Magento\Catalog\Model\Product; use Magento\Framework\EntityManager\EventManager; use Magento\Framework\Indexer\CacheContext; @@ -26,16 +25,24 @@ class FlushCacheByProductIds */ private $eventManager; + /** + * @var string + */ + private $productCacheTag; + /** * @param CacheContext $cacheContext * @param EventManager $eventManager + * @param string $productCacheTag */ public function __construct( CacheContext $cacheContext, - EventManager $eventManager + EventManager $eventManager, + string $productCacheTag ) { $this->cacheContext = $cacheContext; $this->eventManager = $eventManager; + $this->productCacheTag = $productCacheTag; } /** @@ -47,7 +54,7 @@ public function __construct( public function execute(array $productIds) { if ($productIds) { - $this->cacheContext->registerEntities(Product::CACHE_TAG, $productIds); + $this->cacheContext->registerEntities($this->productCacheTag, $productIds); $this->eventManager->dispatch('clean_cache_by_tags', ['object' => $this->cacheContext]); } } diff --git a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php b/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php index e4a39b2f3a7f9..b95baaa77607a 100644 --- a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php +++ b/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php @@ -7,7 +7,6 @@ namespace Magento\InventoryCache\Model\ResourceModel; -use Magento\Catalog\Api\Data\ProductInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\EntityManager\MetadataPool; use Magento\InventoryCatalogApi\Api\DefaultStockProviderInterface; @@ -44,25 +43,41 @@ class GetProductIdsByStockIds */ private $indexStructure; + /** + * @var string + */ + private $productSkuColumn; + + /** + * @var string + */ + private $productInterfaceClassName; + /** * @param ResourceConnection $resource * @param MetadataPool $metadataPool * @param StockIndexTableNameResolverInterface $stockIndexTableNameResolver * @param DefaultStockProviderInterface $defaultStockProvider * @param IndexStructure $indexStructure + * @param string $productSkuColumn + * @param string $productInterfaceClassName */ public function __construct( ResourceConnection $resource, MetadataPool $metadataPool, StockIndexTableNameResolverInterface $stockIndexTableNameResolver, DefaultStockProviderInterface $defaultStockProvider, - IndexStructure $indexStructure + IndexStructure $indexStructure, + string $productSkuColumn, + string $productInterfaceClassName ) { $this->resource = $resource; $this->metadataPool = $metadataPool; $this->defaultStockProvider = $defaultStockProvider; $this->indexStructure = $indexStructure; $this->stockIndexTableNameResolver = $stockIndexTableNameResolver; + $this->productSkuColumn = $productSkuColumn; + $this->productInterfaceClassName = $productInterfaceClassName; } /** @@ -78,14 +93,14 @@ public function execute(array $stockIds): array continue; } $stockIndexTableName = $this->stockIndexTableNameResolver->execute($stockId); - $entityMetadata = $this->metadataPool->getMetadata(ProductInterface::class); + $entityMetadata = $this->metadataPool->getMetadata($this->productInterfaceClassName); $linkField = $entityMetadata->getLinkField(); $connection = $this->resource->getConnection(); $sql = $connection->select() ->from(['main' => $stockIndexTableName], []) ->join( ['product' => $this->resource->getTableName('catalog_product_entity')], - 'product.' . ProductInterface::SKU . '=main.' . ProductInterface::SKU, + 'product.' . $this->productSkuColumn . '=main.' . $this->productSkuColumn, [$linkField] ); diff --git a/app/code/Magento/InventoryCache/Plugin/InventoryIndexer/Indexer/Source/SourceItemIndexer/CacheFlush.php b/app/code/Magento/InventoryCache/Plugin/InventoryIndexer/Indexer/Source/SourceItemIndexer/CacheFlush.php index 6b3fa13da92bd..5da92eb0d8bb4 100644 --- a/app/code/Magento/InventoryCache/Plugin/InventoryIndexer/Indexer/Source/SourceItemIndexer/CacheFlush.php +++ b/app/code/Magento/InventoryCache/Plugin/InventoryIndexer/Indexer/Source/SourceItemIndexer/CacheFlush.php @@ -8,7 +8,7 @@ namespace Magento\InventoryCache\Plugin\InventoryIndexer\Indexer\Source\SourceItemIndexer; use Magento\InventoryCache\Model\FlushCacheByProductIds; -use Magento\InventoryCache\Model\ResourceModel\GetProductIdsBySourceItemIds; +use Magento\InventoryIndexer\Model\ResourceModel\GetProductIdsBySourceItemIds; use Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer; /** diff --git a/app/code/Magento/InventoryCache/composer.json b/app/code/Magento/InventoryCache/composer.json index 10943df36314b..43c12b4f9f42b 100644 --- a/app/code/Magento/InventoryCache/composer.json +++ b/app/code/Magento/InventoryCache/composer.json @@ -4,12 +4,11 @@ "require": { "php": "~7.1.3||~7.2.0", "magento/framework": "*", - "magento/module-catalog": "*", "magento/module-inventory-catalog-api": "*", "magento/module-inventory-indexer": "*" }, "suggest": { - "magento/module-inventory": "*" + "magento/module-catalog": "*" }, "type": "magento2-module", "license": [ diff --git a/app/code/Magento/InventoryCache/etc/di.xml b/app/code/Magento/InventoryCache/etc/di.xml index 5c386c920d767..e13424af444f7 100644 --- a/app/code/Magento/InventoryCache/etc/di.xml +++ b/app/code/Magento/InventoryCache/etc/di.xml @@ -12,10 +12,15 @@ - + - Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM - Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME + Magento\Catalog\Api\Data\ProductInterface::SKU + Magento\Catalog\Api\Data\ProductInterface + + + + + Magento\Catalog\Model\Product::CACHE_TAG diff --git a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsBySourceItemIds.php b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php similarity index 81% rename from app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsBySourceItemIds.php rename to app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php index 12e72e93762fa..fc8cc717bce78 100644 --- a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsBySourceItemIds.php +++ b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php @@ -5,9 +5,8 @@ */ declare(strict_types=1); -namespace Magento\InventoryCache\Model\ResourceModel; +namespace Magento\InventoryIndexer\Model\ResourceModel; -use Magento\Catalog\Api\Data\ProductInterface; use Magento\Framework\App\ResourceConnection; use Magento\Framework\EntityManager\MetadataPool; @@ -36,6 +35,11 @@ class GetProductIdsBySourceItemIds */ private $sourceItemIdFieldName; + /** + * @var string + */ + private $productInterfaceClassName; + /** * GetProductIdsByStockIds constructor. * @@ -43,17 +47,20 @@ class GetProductIdsBySourceItemIds * @param MetadataPool $metadataPool * @param string $tableNameSourceItem * @param string $sourceItemIdFieldName + * @param string $productInterfaceClassName */ public function __construct( ResourceConnection $resource, MetadataPool $metadataPool, - $tableNameSourceItem, - $sourceItemIdFieldName + string $tableNameSourceItem, + string $sourceItemIdFieldName, + string $productInterfaceClassName ) { $this->resource = $resource; $this->metadataPool = $metadataPool; $this->tableNameSourceItem = $tableNameSourceItem; $this->sourceItemIdFieldName = $sourceItemIdFieldName; + $this->productInterfaceClassName = $productInterfaceClassName; } /** @@ -65,7 +72,7 @@ public function __construct( */ public function execute(array $sourceItemIds): array { - $productLinkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); + $productLinkField = $this->metadataPool->getMetadata($this->productInterfaceClassName)->getLinkField(); $connection = $this->resource->getConnection(); $sourceItemTable = $this->resource->getTableName($this->tableNameSourceItem); $select = $connection->select() diff --git a/app/code/Magento/InventoryIndexer/composer.json b/app/code/Magento/InventoryIndexer/composer.json index a28e391e6492c..176ba4b03278a 100644 --- a/app/code/Magento/InventoryIndexer/composer.json +++ b/app/code/Magento/InventoryIndexer/composer.json @@ -11,6 +11,9 @@ "magento/module-inventory-sales-api": "*", "magento/module-inventory-sales": "*" }, + "suggest": { + "magento/module-catalog": "*" + }, "type": "magento2-module", "license": [ "OSL-3.0", diff --git a/app/code/Magento/InventoryIndexer/etc/di.xml b/app/code/Magento/InventoryIndexer/etc/di.xml index 47fdc1eaf9ef9..46b93f86d868f 100644 --- a/app/code/Magento/InventoryIndexer/etc/di.xml +++ b/app/code/Magento/InventoryIndexer/etc/di.xml @@ -56,4 +56,11 @@ stock_ + + + Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM + Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME + Magento\Catalog\Api\Data\ProductInterface + +