From 2d6244ebc7d721b860817ab9597758c182dc7292 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Tue, 15 May 2018 21:06:35 +0300 Subject: [PATCH 1/5] Removed InventoryCache dependency on Inventory --- .../Indexer/Source/SourceItemIndexer/CacheFlush.php | 2 +- app/code/Magento/InventoryCache/composer.json | 3 --- app/code/Magento/InventoryCache/etc/di.xml | 6 ------ .../Model/ResourceModel/GetProductIdsBySourceItemIds.php | 2 +- app/code/Magento/InventoryIndexer/etc/di.xml | 6 ++++++ 5 files changed, 8 insertions(+), 11 deletions(-) rename app/code/Magento/{InventoryCache => InventoryIndexer}/Model/ResourceModel/GetProductIdsBySourceItemIds.php (97%) 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..211321cb38196 100644 --- a/app/code/Magento/InventoryCache/composer.json +++ b/app/code/Magento/InventoryCache/composer.json @@ -8,9 +8,6 @@ "magento/module-inventory-catalog-api": "*", "magento/module-inventory-indexer": "*" }, - "suggest": { - "magento/module-inventory": "*" - }, "type": "magento2-module", "license": [ "OSL-3.0", diff --git a/app/code/Magento/InventoryCache/etc/di.xml b/app/code/Magento/InventoryCache/etc/di.xml index 5c386c920d767..855c467f103de 100644 --- a/app/code/Magento/InventoryCache/etc/di.xml +++ b/app/code/Magento/InventoryCache/etc/di.xml @@ -12,10 +12,4 @@ - - - Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM - Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME - - diff --git a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsBySourceItemIds.php b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php similarity index 97% rename from app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsBySourceItemIds.php rename to app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php index 12e72e93762fa..ac1316c68548c 100644 --- a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsBySourceItemIds.php +++ b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php @@ -5,7 +5,7 @@ */ 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; diff --git a/app/code/Magento/InventoryIndexer/etc/di.xml b/app/code/Magento/InventoryIndexer/etc/di.xml index 30aec2ce542af..21553eafea042 100644 --- a/app/code/Magento/InventoryIndexer/etc/di.xml +++ b/app/code/Magento/InventoryIndexer/etc/di.xml @@ -56,4 +56,10 @@ stock_ + + + Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM + Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME + + From 7f0e4c1f1598f17ff49c26753468cf802fb0db16 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Wed, 16 May 2018 14:43:06 +0300 Subject: [PATCH 2/5] Declared missing dependency --- app/code/Magento/InventoryIndexer/composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryIndexer/composer.json b/app/code/Magento/InventoryIndexer/composer.json index a28e391e6492c..d3811da430bcf 100644 --- a/app/code/Magento/InventoryIndexer/composer.json +++ b/app/code/Magento/InventoryIndexer/composer.json @@ -9,7 +9,8 @@ "magento/module-inventory-api": "*", "magento/module-inventory-catalog-api": "*", "magento/module-inventory-sales-api": "*", - "magento/module-inventory-sales": "*" + "magento/module-inventory-sales": "*", + "magento/module-catalog": "*" }, "type": "magento2-module", "license": [ From 389306c7f44e3655fe7b5c9b5cd1418abc92deff Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Thu, 17 May 2018 19:31:01 +0300 Subject: [PATCH 3/5] Removed InventoryCache and InventoryIndexer dependencies on catalog --- .../ResourceModel/GetProductIdsByStockIds.php | 23 +++++++++++++++---- app/code/Magento/InventoryCache/composer.json | 4 +++- app/code/Magento/InventoryCache/etc/di.xml | 6 +++++ .../GetProductIdsBySourceItemIds.php | 13 ++++++++--- .../Magento/InventoryIndexer/composer.json | 4 +++- app/code/Magento/InventoryIndexer/etc/di.xml | 1 + 6 files changed, 42 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php b/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php index e4a39b2f3a7f9..90fc28e454ca9 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 $productSkuColumn + * @param $productInterfaceClassName */ public function __construct( ResourceConnection $resource, MetadataPool $metadataPool, StockIndexTableNameResolverInterface $stockIndexTableNameResolver, DefaultStockProviderInterface $defaultStockProvider, - IndexStructure $indexStructure + IndexStructure $indexStructure, + $productSkuColumn, + $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/composer.json b/app/code/Magento/InventoryCache/composer.json index 211321cb38196..43c12b4f9f42b 100644 --- a/app/code/Magento/InventoryCache/composer.json +++ b/app/code/Magento/InventoryCache/composer.json @@ -4,10 +4,12 @@ "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-catalog": "*" + }, "type": "magento2-module", "license": [ "OSL-3.0", diff --git a/app/code/Magento/InventoryCache/etc/di.xml b/app/code/Magento/InventoryCache/etc/di.xml index 855c467f103de..5686c12a84ac7 100644 --- a/app/code/Magento/InventoryCache/etc/di.xml +++ b/app/code/Magento/InventoryCache/etc/di.xml @@ -12,4 +12,10 @@ + + + Magento\Catalog\Api\Data\ProductInterface::SKU + Magento\Catalog\Api\Data\ProductInterface + + diff --git a/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php index ac1316c68548c..70742195bd4b3 100644 --- a/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php +++ b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php @@ -7,7 +7,6 @@ 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 $productInterfaceClassName */ public function __construct( ResourceConnection $resource, MetadataPool $metadataPool, $tableNameSourceItem, - $sourceItemIdFieldName + $sourceItemIdFieldName, + $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 d3811da430bcf..176ba4b03278a 100644 --- a/app/code/Magento/InventoryIndexer/composer.json +++ b/app/code/Magento/InventoryIndexer/composer.json @@ -9,7 +9,9 @@ "magento/module-inventory-api": "*", "magento/module-inventory-catalog-api": "*", "magento/module-inventory-sales-api": "*", - "magento/module-inventory-sales": "*", + "magento/module-inventory-sales": "*" + }, + "suggest": { "magento/module-catalog": "*" }, "type": "magento2-module", diff --git a/app/code/Magento/InventoryIndexer/etc/di.xml b/app/code/Magento/InventoryIndexer/etc/di.xml index 21600cc7f0327..2a731cbe88086 100644 --- a/app/code/Magento/InventoryIndexer/etc/di.xml +++ b/app/code/Magento/InventoryIndexer/etc/di.xml @@ -60,6 +60,7 @@ Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME + Magento\Catalog\Api\Data\ProductInterface From 1f9dd5e8ac69a31b9e3e2ad30a51e494d28e8b42 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Thu, 17 May 2018 21:07:16 +0300 Subject: [PATCH 4/5] Fixed arguments types --- app/code/Magento/InventoryCache/etc/di.xml | 2 +- app/code/Magento/InventoryIndexer/etc/di.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/InventoryCache/etc/di.xml b/app/code/Magento/InventoryCache/etc/di.xml index 5686c12a84ac7..87e50b7697e02 100644 --- a/app/code/Magento/InventoryCache/etc/di.xml +++ b/app/code/Magento/InventoryCache/etc/di.xml @@ -15,7 +15,7 @@ Magento\Catalog\Api\Data\ProductInterface::SKU - Magento\Catalog\Api\Data\ProductInterface + Magento\Catalog\Api\Data\ProductInterface diff --git a/app/code/Magento/InventoryIndexer/etc/di.xml b/app/code/Magento/InventoryIndexer/etc/di.xml index 2a731cbe88086..46b93f86d868f 100644 --- a/app/code/Magento/InventoryIndexer/etc/di.xml +++ b/app/code/Magento/InventoryIndexer/etc/di.xml @@ -60,7 +60,7 @@ Magento\Inventory\Model\ResourceModel\SourceItem::TABLE_NAME_SOURCE_ITEM Magento\Inventory\Model\ResourceModel\SourceItem::ID_FIELD_NAME - Magento\Catalog\Api\Data\ProductInterface + Magento\Catalog\Api\Data\ProductInterface From ab39b56aa50241c4dfa5c321b01c9f1e66d5dace Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Sat, 19 May 2018 12:51:11 +0300 Subject: [PATCH 5/5] Fixed static test checks issues --- .../InventoryCache/Model/FlushCacheByProductIds.php | 13 ++++++++++--- .../Model/ResourceModel/GetProductIdsByStockIds.php | 8 ++++---- app/code/Magento/InventoryCache/etc/di.xml | 5 +++++ .../ResourceModel/GetProductIdsBySourceItemIds.php | 8 ++++---- 4 files changed, 23 insertions(+), 11 deletions(-) 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 90fc28e454ca9..b95baaa77607a 100644 --- a/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php +++ b/app/code/Magento/InventoryCache/Model/ResourceModel/GetProductIdsByStockIds.php @@ -59,8 +59,8 @@ class GetProductIdsByStockIds * @param StockIndexTableNameResolverInterface $stockIndexTableNameResolver * @param DefaultStockProviderInterface $defaultStockProvider * @param IndexStructure $indexStructure - * @param $productSkuColumn - * @param $productInterfaceClassName + * @param string $productSkuColumn + * @param string $productInterfaceClassName */ public function __construct( ResourceConnection $resource, @@ -68,8 +68,8 @@ public function __construct( StockIndexTableNameResolverInterface $stockIndexTableNameResolver, DefaultStockProviderInterface $defaultStockProvider, IndexStructure $indexStructure, - $productSkuColumn, - $productInterfaceClassName + string $productSkuColumn, + string $productInterfaceClassName ) { $this->resource = $resource; $this->metadataPool = $metadataPool; diff --git a/app/code/Magento/InventoryCache/etc/di.xml b/app/code/Magento/InventoryCache/etc/di.xml index 87e50b7697e02..e13424af444f7 100644 --- a/app/code/Magento/InventoryCache/etc/di.xml +++ b/app/code/Magento/InventoryCache/etc/di.xml @@ -18,4 +18,9 @@ Magento\Catalog\Api\Data\ProductInterface + + + Magento\Catalog\Model\Product::CACHE_TAG + + diff --git a/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php index 70742195bd4b3..fc8cc717bce78 100644 --- a/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php +++ b/app/code/Magento/InventoryIndexer/Model/ResourceModel/GetProductIdsBySourceItemIds.php @@ -47,14 +47,14 @@ class GetProductIdsBySourceItemIds * @param MetadataPool $metadataPool * @param string $tableNameSourceItem * @param string $sourceItemIdFieldName - * @param $productInterfaceClassName + * @param string $productInterfaceClassName */ public function __construct( ResourceConnection $resource, MetadataPool $metadataPool, - $tableNameSourceItem, - $sourceItemIdFieldName, - $productInterfaceClassName + string $tableNameSourceItem, + string $sourceItemIdFieldName, + string $productInterfaceClassName ) { $this->resource = $resource; $this->metadataPool = $metadataPool;