From 3eb0b26b1cf22cebbd40f426fb973868fd8aa231 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Mon, 22 Jan 2024 18:08:40 -0600 Subject: [PATCH 01/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryIndexer/etc/indexer.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/InventoryIndexer/etc/indexer.xml b/InventoryIndexer/etc/indexer.xml index cced728ea5de..c269fca7c98a 100644 --- a/InventoryIndexer/etc/indexer.xml +++ b/InventoryIndexer/etc/indexer.xml @@ -10,9 +10,4 @@ Inventory Inventory index (MSI) - - - - - From cbffc4de9de546e65dbe806789cac85252a86800 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 21 Feb 2024 13:36:58 -0600 Subject: [PATCH 02/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 58 ++++++++++++++++++++ InventoryCatalog/etc/di.xml | 1 + 2 files changed, 59 insertions(+) create mode 100644 InventoryCatalog/Model/SortingAdjustment.php diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php new file mode 100644 index 000000000000..cb2f55f96524 --- /dev/null +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -0,0 +1,58 @@ + $pricePos) { + $newOrder = []; + foreach ($order as $pos => $indexerId) { + if ($pos < $pricePos || $pos > $inventoryPos) { + $newOrder[$pos] = $indexerId; + } elseif ($pos === $pricePos) { + $newOrder[$pos] = $order[$inventoryPos]; + $newOrder[$pos+1] = $indexerId; + } elseif ($pos > $pricePos && $pos < $inventoryPos) { + $newOrder[$pos+1] = $indexerId; + } + } + for ($i = 0; $i < count($newOrder); $i++) { + $indexersListAdjusted[$newOrder[$i]] = $indexersList[$newOrder[$i]]; + } + } else { + $indexersListAdjusted = $indexersList; + } + + return $indexersListAdjusted; + } +} diff --git a/InventoryCatalog/etc/di.xml b/InventoryCatalog/etc/di.xml index 3017ef646f5d..5db63017e9c9 100644 --- a/InventoryCatalog/etc/di.xml +++ b/InventoryCatalog/etc/di.xml @@ -210,4 +210,5 @@ + From 9a75fbca52932065cc439fb1b8265b7f4f210b81 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Thu, 22 Feb 2024 13:51:43 -0600 Subject: [PATCH 03/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 34 ++++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php index cb2f55f96524..0beccd001464 100644 --- a/InventoryCatalog/Model/SortingAdjustment.php +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -25,7 +25,7 @@ class SortingAdjustment implements SortingAdjustmentInterface { /** - * @inheirtdoc + * @inheridoc */ public function adjust(array $indexersList): array { @@ -34,23 +34,23 @@ public function adjust(array $indexersList): array $pricePos = array_search(PriceIndexer::INDEXER_ID, $order); $inventoryPos = array_search(InventoryIndexer::INDEXER_ID, $order); - if ($pricePos !== false && $inventoryPos !== false && $inventoryPos > $pricePos) { - $newOrder = []; - foreach ($order as $pos => $indexerId) { - if ($pos < $pricePos || $pos > $inventoryPos) { - $newOrder[$pos] = $indexerId; - } elseif ($pos === $pricePos) { - $newOrder[$pos] = $order[$inventoryPos]; - $newOrder[$pos+1] = $indexerId; - } elseif ($pos > $pricePos && $pos < $inventoryPos) { - $newOrder[$pos+1] = $indexerId; - } - } - for ($i = 0; $i < count($newOrder); $i++) { - $indexersListAdjusted[$newOrder[$i]] = $indexersList[$newOrder[$i]]; + if ($pricePos === false || $inventoryPos === false || $inventoryPos < $pricePos) { + return $indexersList; + } + + $newOrder = []; + foreach ($order as $pos => $indexerId) { + if ($pos < $pricePos || $pos > $inventoryPos) { + $newOrder[$pos] = $indexerId; + } elseif ($pos === $pricePos) { + $newOrder[$pos] = $order[$inventoryPos]; + $newOrder[$pos+1] = $indexerId; + } elseif ($pos > $pricePos && $pos < $inventoryPos) { + $newOrder[$pos+1] = $indexerId; } - } else { - $indexersListAdjusted = $indexersList; + } + for ($i = 0; $i < count($newOrder); $i++) { + $indexersListAdjusted[$newOrder[$i]] = $indexersList[$newOrder[$i]]; } return $indexersListAdjusted; From d6e41ef39dcb1794a7fc18337babd6f356c7df96 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Thu, 22 Feb 2024 15:34:31 -0600 Subject: [PATCH 04/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 44 +++++++++++++++----- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php index 0beccd001464..cd0d9f254aed 100644 --- a/InventoryCatalog/Model/SortingAdjustment.php +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -25,7 +25,7 @@ class SortingAdjustment implements SortingAdjustmentInterface { /** - * @inheridoc + * @inheritDoc */ public function adjust(array $indexersList): array { @@ -40,19 +40,43 @@ public function adjust(array $indexersList): array $newOrder = []; foreach ($order as $pos => $indexerId) { - if ($pos < $pricePos || $pos > $inventoryPos) { - $newOrder[$pos] = $indexerId; - } elseif ($pos === $pricePos) { - $newOrder[$pos] = $order[$inventoryPos]; - $newOrder[$pos+1] = $indexerId; - } elseif ($pos > $pricePos && $pos < $inventoryPos) { - $newOrder[$pos+1] = $indexerId; - } + $newOrder = $this->fillNewOrder($newOrder, $order, $pos, $indexerId, $pricePos, $inventoryPos); } - for ($i = 0; $i < count($newOrder); $i++) { + $c = count($newOrder); + for ($i = 0; $i < $c; $i++) { $indexersListAdjusted[$newOrder[$i]] = $indexersList[$newOrder[$i]]; } return $indexersListAdjusted; } + + /** + * Fill array with new sorting order + * + * @param array $newOrder + * @param array $order + * @param int $pos + * @param string $indexerId + * @param int $pricePos + * @param int $inventoryPos + * @return array + */ + private function fillNewOrder( + array $newOrder, + array $order, + int $pos, + string $indexerId, + int $pricePos, + int $inventoryPos + ) : array { + if ($pos < $pricePos || $pos > $inventoryPos) { + $newOrder[$pos] = $indexerId; + } elseif ($pos === $pricePos) { + $newOrder[$pos] = $order[$inventoryPos]; + $newOrder[$pos+1] = $indexerId; + } elseif ($pos > $pricePos && $pos < $inventoryPos) { + $newOrder[$pos+1] = $indexerId; + } + return $newOrder; + } } From 77a3c6a312b8b09730134b3cc4bd2ab72b54620d Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 28 Feb 2024 09:22:19 -0600 Subject: [PATCH 05/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 86 ++++++++++++-------- 1 file changed, 51 insertions(+), 35 deletions(-) diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php index cd0d9f254aed..fbf2f985890e 100644 --- a/InventoryCatalog/Model/SortingAdjustment.php +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -20,6 +20,7 @@ use Magento\Framework\Indexer\Config\Converter\SortingAdjustmentInterface; use Magento\Catalog\Model\Indexer\Product\Price\Processor as PriceIndexer; +use Magento\CatalogInventory\Model\Indexer\Stock\Processor as StockIndexer; use Magento\InventoryIndexer\Indexer\InventoryIndexer; class SortingAdjustment implements SortingAdjustmentInterface @@ -27,55 +28,70 @@ class SortingAdjustment implements SortingAdjustmentInterface /** * @inheritDoc */ - public function adjust(array $indexersList): array + public function adjust(array $indexersList) : array { - $indexersListAdjusted = []; - $order = array_keys($indexersList); + $indexersListAdjusted = $indexersList; - $pricePos = array_search(PriceIndexer::INDEXER_ID, $order); + $order = array_keys($indexersListAdjusted); $inventoryPos = array_search(InventoryIndexer::INDEXER_ID, $order); - if ($pricePos === false || $inventoryPos === false || $inventoryPos < $pricePos) { - return $indexersList; + $stockPos = array_search(StockIndexer::INDEXER_ID, $order); + if ($stockPos !== false && $inventoryPos !== false) { + $indexersListAdjusted = $this->switchPositions($indexersListAdjusted, $stockPos, $inventoryPos); } - $newOrder = []; - foreach ($order as $pos => $indexerId) { - $newOrder = $this->fillNewOrder($newOrder, $order, $pos, $indexerId, $pricePos, $inventoryPos); - } - $c = count($newOrder); - for ($i = 0; $i < $c; $i++) { - $indexersListAdjusted[$newOrder[$i]] = $indexersList[$newOrder[$i]]; + $order = array_keys($indexersListAdjusted); + $pricePos = array_search(PriceIndexer::INDEXER_ID, $order); + $inventoryPos = array_search(InventoryIndexer::INDEXER_ID, $order); + if ($pricePos !== false && $inventoryPos !== false && $inventoryPos > $pricePos) { + $indexersListAdjusted = $this->switchPositions($indexersListAdjusted, $inventoryPos, $pricePos); } return $indexersListAdjusted; } /** - * Fill array with new sorting order + * Switch position for two indexers if necessary * - * @param array $newOrder - * @param array $order - * @param int $pos - * @param string $indexerId - * @param int $pricePos - * @param int $inventoryPos + * @param array $list + * @param int $posShouldBeUpper + * @param int $posShouldBeLower * @return array */ - private function fillNewOrder( - array $newOrder, - array $order, - int $pos, - string $indexerId, - int $pricePos, - int $inventoryPos - ) : array { - if ($pos < $pricePos || $pos > $inventoryPos) { - $newOrder[$pos] = $indexerId; - } elseif ($pos === $pricePos) { - $newOrder[$pos] = $order[$inventoryPos]; - $newOrder[$pos+1] = $indexerId; - } elseif ($pos > $pricePos && $pos < $inventoryPos) { - $newOrder[$pos+1] = $indexerId; + private function switchPositions(array $list, int $posShouldBeUpper, int $posShouldBeLower) : array + { + if ($posShouldBeUpper > $posShouldBeLower) { + $newOrder = $this->reArrange($list, $posShouldBeUpper, $posShouldBeLower); + $tmpList = []; + $c = count($newOrder); + for ($i = 0; $i < $c; $i++) { + $tmpList[$newOrder[$i]] = $list[$newOrder[$i]]; + } + $list = $tmpList; + } + return $list; + } + + /** + * Perform adjustments in the sorting order + * + * @param array $list + * @param int $posShouldBeUpper + * @param int $posShouldBeLower + * @return array + */ + private function reArrange(array $list, int $posShouldBeUpper, int $posShouldBeLower) : array + { + $newOrder = []; + $order = array_keys($list); + foreach ($order as $pos => $indexerId) { + if ($pos < $posShouldBeLower || $pos > $posShouldBeUpper) { + $newOrder[$pos] = $indexerId; + } elseif ($pos === $posShouldBeUpper) { + $newOrder[$pos] = $order[$posShouldBeLower]; + $newOrder[$pos+1] = $indexerId; + } elseif ($pos < $posShouldBeUpper && $pos > $posShouldBeLower) { + $newOrder[$pos+1] = $indexerId; + } } return $newOrder; } From 1da8c803cc7adf20cf4fa18b1d0aadd489d03d51 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 28 Feb 2024 11:16:32 -0600 Subject: [PATCH 06/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php index fbf2f985890e..c333423c8cfc 100644 --- a/InventoryCatalog/Model/SortingAdjustment.php +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -42,7 +42,7 @@ public function adjust(array $indexersList) : array $order = array_keys($indexersListAdjusted); $pricePos = array_search(PriceIndexer::INDEXER_ID, $order); $inventoryPos = array_search(InventoryIndexer::INDEXER_ID, $order); - if ($pricePos !== false && $inventoryPos !== false && $inventoryPos > $pricePos) { + if ($pricePos !== false && $inventoryPos !== false) { $indexersListAdjusted = $this->switchPositions($indexersListAdjusted, $inventoryPos, $pricePos); } @@ -86,10 +86,10 @@ private function reArrange(array $list, int $posShouldBeUpper, int $posShouldBeL foreach ($order as $pos => $indexerId) { if ($pos < $posShouldBeLower || $pos > $posShouldBeUpper) { $newOrder[$pos] = $indexerId; - } elseif ($pos === $posShouldBeUpper) { - $newOrder[$pos] = $order[$posShouldBeLower]; + } elseif ($pos === $posShouldBeLower) { + $newOrder[$pos] = $order[$posShouldBeUpper]; $newOrder[$pos+1] = $indexerId; - } elseif ($pos < $posShouldBeUpper && $pos > $posShouldBeLower) { + } elseif ($pos > $posShouldBeLower && $pos < $posShouldBeUpper) { $newOrder[$pos+1] = $indexerId; } } From 5ccf3400914a9533969fc956ab248d89756f36aa Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Wed, 28 Feb 2024 17:30:04 -0600 Subject: [PATCH 07/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryIndexer/etc/indexer.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InventoryIndexer/etc/indexer.xml b/InventoryIndexer/etc/indexer.xml index c269fca7c98a..6746448838be 100644 --- a/InventoryIndexer/etc/indexer.xml +++ b/InventoryIndexer/etc/indexer.xml @@ -10,4 +10,9 @@ Inventory Inventory index (MSI) + + + + + From c72a5884e1e0f4e8c35c3008e05639398ba56a6a Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Thu, 29 Feb 2024 09:31:15 -0600 Subject: [PATCH 08/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryIndexer/etc/indexer.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/InventoryIndexer/etc/indexer.xml b/InventoryIndexer/etc/indexer.xml index 6746448838be..c269fca7c98a 100644 --- a/InventoryIndexer/etc/indexer.xml +++ b/InventoryIndexer/etc/indexer.xml @@ -10,9 +10,4 @@ Inventory Inventory index (MSI) - - - - - From 975e66b541728042fdff4f2993fdf35bdb0f913e Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Thu, 29 Feb 2024 10:54:25 -0600 Subject: [PATCH 09/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php index c333423c8cfc..30e47d7ba43d 100644 --- a/InventoryCatalog/Model/SortingAdjustment.php +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -46,6 +46,14 @@ public function adjust(array $indexersList) : array $indexersListAdjusted = $this->switchPositions($indexersListAdjusted, $inventoryPos, $pricePos); } + //put stock first + foreach ($indexersListAdjusted as $id => $data) { + if ($id === StockIndexer::INDEXER_ID) { + $indexersListAdjusted = [$id => $data] + $indexersListAdjusted; + break; + } + } + return $indexersListAdjusted; } From c0807a9780277a8161c8aebcbcd2ca0a095d9fe8 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Thu, 29 Feb 2024 14:21:34 -0600 Subject: [PATCH 10/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php index 30e47d7ba43d..920d9680cfb8 100644 --- a/InventoryCatalog/Model/SortingAdjustment.php +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -36,7 +36,12 @@ public function adjust(array $indexersList) : array $inventoryPos = array_search(InventoryIndexer::INDEXER_ID, $order); $stockPos = array_search(StockIndexer::INDEXER_ID, $order); if ($stockPos !== false && $inventoryPos !== false) { - $indexersListAdjusted = $this->switchPositions($indexersListAdjusted, $stockPos, $inventoryPos); + foreach ($indexersListAdjusted as $id => $data) { + if ($id === StockIndexer::INDEXER_ID) { + $indexersListAdjusted = [$id => $data] + $indexersListAdjusted; + break; + } + } } $order = array_keys($indexersListAdjusted); @@ -46,13 +51,6 @@ public function adjust(array $indexersList) : array $indexersListAdjusted = $this->switchPositions($indexersListAdjusted, $inventoryPos, $pricePos); } - //put stock first - foreach ($indexersListAdjusted as $id => $data) { - if ($id === StockIndexer::INDEXER_ID) { - $indexersListAdjusted = [$id => $data] + $indexersListAdjusted; - break; - } - } return $indexersListAdjusted; } From e1864e638d0d521082129626f3ff35af64d09dc5 Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Fri, 1 Mar 2024 15:55:38 -0600 Subject: [PATCH 11/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- InventoryCatalog/Model/SortingAdjustment.php | 1 - .../Test/Integration/IndexersOrderTest.php | 67 +++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 InventoryCatalog/Test/Integration/IndexersOrderTest.php diff --git a/InventoryCatalog/Model/SortingAdjustment.php b/InventoryCatalog/Model/SortingAdjustment.php index 920d9680cfb8..0a4894433eca 100644 --- a/InventoryCatalog/Model/SortingAdjustment.php +++ b/InventoryCatalog/Model/SortingAdjustment.php @@ -51,7 +51,6 @@ public function adjust(array $indexersList) : array $indexersListAdjusted = $this->switchPositions($indexersListAdjusted, $inventoryPos, $pricePos); } - return $indexersListAdjusted; } diff --git a/InventoryCatalog/Test/Integration/IndexersOrderTest.php b/InventoryCatalog/Test/Integration/IndexersOrderTest.php new file mode 100644 index 000000000000..001ac0b5aa1c --- /dev/null +++ b/InventoryCatalog/Test/Integration/IndexersOrderTest.php @@ -0,0 +1,67 @@ +sortingAdjustment = Bootstrap::getObjectManager()->create(SortingAdjustmentInterface::class); + } + + /** + * @return void + */ + public function testIndexersOrder() + { + $unAdjusted = [ + 'indexer1' => [], + PriceIndexer::INDEXER_ID => [], + 'indexer2' => [], + InventoryIndexer::INDEXER_ID => [], + 'indexer3' => [], + StockIndexer::INDEXER_ID => [], + 'indexer4' => [] + ]; + $output = $this->sortingAdjustment->adjust($unAdjusted); + $this->assertArrayHasKey(PriceIndexer::INDEXER_ID, $output); + $this->assertArrayHasKey(InventoryIndexer::INDEXER_ID, $output); + $this->assertArrayHasKey(StockIndexer::INDEXER_ID, $output); + $order = array_keys($output); + $inventoryPos = array_search(InventoryIndexer::INDEXER_ID, $order); + $stockPos = array_search(StockIndexer::INDEXER_ID, $order); + $pricePos = array_search(PriceIndexer::INDEXER_ID, $order); + $this->assertTrue($stockPos < $inventoryPos); + $this->assertTrue($inventoryPos < $pricePos); + } +} From 9d929c4e640fe0f6f7db04816261252515d9072a Mon Sep 17 00:00:00 2001 From: Oleksandr Iegorov Date: Fri, 1 Mar 2024 16:40:20 -0600 Subject: [PATCH 12/12] ACP2E-767: Remove Magento Catalog dependency on Magento Inventory --- .../NoPriceIndexerDependencyTest.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 InventoryIndexer/Test/Integration/NoPriceIndexerDependencyTest.php diff --git a/InventoryIndexer/Test/Integration/NoPriceIndexerDependencyTest.php b/InventoryIndexer/Test/Integration/NoPriceIndexerDependencyTest.php new file mode 100644 index 000000000000..5d9727c48ba9 --- /dev/null +++ b/InventoryIndexer/Test/Integration/NoPriceIndexerDependencyTest.php @@ -0,0 +1,44 @@ +dependencyInfoProvider = Bootstrap::getObjectManager()->get(DependencyInfoProviderInterface::class); + } + + public function testPriceDependency() + { + $output = $this->dependencyInfoProvider->getIndexerIdsToRunBefore(PriceIndexer::INDEXER_ID); + $this->assertArrayNotHasKey(InventoryIndexer::INDEXER_ID, array_values($output)); + } +}