From a9d9b604ea66e955440369b2a8ffb6ead36fed89 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Tue, 27 Mar 2018 14:29:33 +0300 Subject: [PATCH 1/5] MSI-732: Delete InventoryBundleIndexer module --- ...dleSkuAndChildrenSourceItemsIdsIndexer.php | 92 -------- .../ChildrenSourceItemsIdsProvider.php | 128 ----------- .../Indexer/SourceItem/GetSkuListInStock.php | 137 ------------ .../SourceItem/IndexDataBySkuListProvider.php | 75 ------- .../Indexer/SourceItem/SourceItemIndexer.php | 79 ------- ...eItemsIdsByChildrenProductsIdsProvider.php | 51 ----- .../InventoryBundleIndexer/LICENSE.txt | 48 ----- .../InventoryBundleIndexer/LICENSE_AFL.txt | 48 ----- .../AddBundleDataToIndexByBundleIds.php | 93 -------- .../AddBundleDataToIndexBySourceItemsIds.php | 58 ----- .../Magento/InventoryBundleIndexer/README.md | 1 - .../Integration/SourceItemIndexerTest.php | 204 ------------------ .../Test/_files/bundle_product_eu_website.php | 106 --------- .../bundle_product_eu_website_rollback.php | 26 --- .../InventoryBundleIndexer/composer.json | 30 --- .../Magento/InventoryBundleIndexer/etc/di.xml | 27 --- .../InventoryBundleIndexer/etc/module.xml | 10 - .../InventoryBundleIndexer/registration.php | 12 -- composer.json | 1 - composer.lock | 134 ++++++------ .../Test/Php/_files/whitelist/strict_type.txt | 1 - 21 files changed, 66 insertions(+), 1295 deletions(-) delete mode 100644 app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ByBundleSkuAndChildrenSourceItemsIdsIndexer.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ChildrenSourceItemsIdsProvider.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/GetSkuListInStock.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/IndexDataBySkuListProvider.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemIndexer.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemsIdsByChildrenProductsIdsProvider.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/LICENSE.txt delete mode 100644 app/code/Magento/InventoryBundleIndexer/LICENSE_AFL.txt delete mode 100644 app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexByBundleIds.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexBySourceItemsIds.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/README.md delete mode 100644 app/code/Magento/InventoryBundleIndexer/Test/Integration/SourceItemIndexerTest.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website_rollback.php delete mode 100644 app/code/Magento/InventoryBundleIndexer/composer.json delete mode 100644 app/code/Magento/InventoryBundleIndexer/etc/di.xml delete mode 100644 app/code/Magento/InventoryBundleIndexer/etc/module.xml delete mode 100644 app/code/Magento/InventoryBundleIndexer/registration.php diff --git a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ByBundleSkuAndChildrenSourceItemsIdsIndexer.php b/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ByBundleSkuAndChildrenSourceItemsIdsIndexer.php deleted file mode 100644 index 24034f678176b..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ByBundleSkuAndChildrenSourceItemsIdsIndexer.php +++ /dev/null @@ -1,92 +0,0 @@ - [bundle children source item ids]] - */ -class ByBundleSkuAndChildrenSourceItemsIdsIndexer -{ - /** - * @var GetSkuListInStock - */ - private $getSkuListInStock; - - /** - * @var IndexDataBySkuListProvider - */ - private $indexDataBySkuListProvider; - - /** - * @var IndexNameBuilder - */ - private $indexNameBuilder; - - /** - * @var IndexHandlerInterface - */ - private $indexHandler; - - /** - * @param GetSkuListInStock $getSkuListInStock - * @param IndexDataBySkuListProvider $indexDataBySkuListProvider - * @param IndexNameBuilder $indexNameBuilder - * @param IndexHandlerInterface $indexHandler - */ - public function __construct( - GetSkuListInStock $getSkuListInStock, - IndexDataBySkuListProvider $indexDataBySkuListProvider, - IndexNameBuilder $indexNameBuilder, - IndexHandlerInterface $indexHandler - ) { - $this->getSkuListInStock = $getSkuListInStock; - $this->indexDataBySkuListProvider = $indexDataBySkuListProvider; - $this->indexNameBuilder = $indexNameBuilder; - $this->indexHandler = $indexHandler; - } - - /** - * @param array $bundleChildrenSourceItemsIdsWithSku - * - * @return void - */ - public function execute(array $bundleChildrenSourceItemsIdsWithSku) - { - $skuListInStockList = $this->getSkuListInStock->execute($bundleChildrenSourceItemsIdsWithSku); - - foreach ($skuListInStockList as $skuListInStock) { - $stockId = $skuListInStock->getStockId(); - $skuList = $skuListInStock->getSkuList(); - - $mainIndexName = $this->indexNameBuilder - ->setIndexId(InventoryIndexer::INDEXER_ID) - ->addDimension('stock_', (string)$stockId) - ->setAlias(Alias::ALIAS_MAIN) - ->build(); - - $this->indexHandler->cleanIndex( - $mainIndexName, - new \ArrayIterator(array_keys($skuList)), - ResourceConnection::DEFAULT_CONNECTION - ); - - $indexData = $this->indexDataBySkuListProvider->execute($stockId, $skuList); - $this->indexHandler->saveIndex( - $mainIndexName, - $indexData, - ResourceConnection::DEFAULT_CONNECTION - ); - } - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ChildrenSourceItemsIdsProvider.php b/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ChildrenSourceItemsIdsProvider.php deleted file mode 100644 index 2dee1f6e84c52..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/ChildrenSourceItemsIdsProvider.php +++ /dev/null @@ -1,128 +0,0 @@ -resourceConnection = $resourceConnection; - } - - /** - * @param array $sourceItemsIds - * - * @return array - */ - public function execute(array $sourceItemsIds = []): array - { - $select = $this->getChildrenSourceItemsIdsSelect(); - if ($sourceItemsIds) { - $bundleIdsSelect = $this->getBundleIdsSelect($sourceItemsIds); - $select->where('relation.parent_id IN (?)', $bundleIdsSelect); - } else { - $select->where('bundle_product.' . ProductInterface::TYPE_ID . ' = ?', ProductType::TYPE_BUNDLE); - } - - $bundleChildren = $select->query()->fetchAll(); - $bundleChildrenSourceItemsIdsBySku = []; - - foreach ($bundleChildren as $bundleChild) { - $bundleChildrenSourceItemsIdsBySku[$bundleChild['sku']][] = $bundleChild[SourceItem::ID_FIELD_NAME]; - } - - return $bundleChildrenSourceItemsIdsBySku; - } - - /** - * Get parent bundle ids by children source items ids. - * - * @param $sourceItemsIds - * @return Select - */ - private function getBundleIdsSelect($sourceItemsIds): Select - { - $productTable = $this->resourceConnection->getTableName('catalog_product_entity'); - $select = $this->resourceConnection->getConnection()->select(); - $select->from( - ['source_item' => $this->resourceConnection->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)], - [] - )->joinInner( - ['product' => $productTable], - 'source_item.sku = product.sku', - [] - )->joinInner( - ['relation' => $this->resourceConnection->getTableName('catalog_product_relation')], - 'product.entity_id = relation.child_id', - [] - )->joinInner( - ['bundle_product' => $productTable], - 'bundle_product.entity_id = relation.parent_id', - ['bundle_product.entity_id'] - )->where( - 'source_item.' . SourceItem::ID_FIELD_NAME . ' IN (?)', - $sourceItemsIds - )->where( - 'bundle_product.' . ProductInterface::TYPE_ID . ' = ?', - ProductType::TYPE_BUNDLE - )->distinct(true); - - return $select; - } - - /** - * @return Select - */ - private function getChildrenSourceItemsIdsSelect(): Select - { - $select = $this->resourceConnection->getConnection()->select(); - $select - ->from( - ['source_item' => $this->resourceConnection->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)], - [SourceItem::ID_FIELD_NAME] - )->joinInner( - ['product' => $this->resourceConnection->getTableName('catalog_product_entity')], - 'source_item.' . SourceItemInterface::SKU . ' = product.' . ProductInterface::SKU, - [] - )->joinInner( - ['relation' => $this->resourceConnection->getTableName('catalog_product_relation')], - 'relation.child_id = product.entity_id', - [] - )->joinInner( - ['bundle_product' => $this->resourceConnection->getTableName('catalog_product_entity')], - 'bundle_product.entity_id = relation.parent_id', - ['bundle_product.sku'] - ); - - return $select; - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/GetSkuListInStock.php b/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/GetSkuListInStock.php deleted file mode 100644 index 25dc76e5a7709..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/GetSkuListInStock.php +++ /dev/null @@ -1,137 +0,0 @@ -resourceConnection = $resourceConnection; - $this->skuListInStockFactory = $skuListInStockFactory; - $this->groupConcatMaxLen = $groupConcatMaxLen; - } - - /** - * Returns all assigned Stock ids by given Source Item ids. - * - * @param array $bundleChildrenSourceItemsIds - * - * @return SkuListInStock[] - */ - public function execute(array $bundleChildrenSourceItemsIds): array - { - $connection = $this->resourceConnection->getConnection(); - $sourceStockLinkTable = $this->resourceConnection->getTableName( - StockSourceLinkResourceModel::TABLE_NAME_STOCK_SOURCE_LINK - ); - $sourceItemTable = $this->resourceConnection->getTableName( - SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM - ); - - $select = $connection - ->select() - ->from( - ['source_item' => $sourceItemTable], - [ - SourceItemInterface::SKU => - sprintf("GROUP_CONCAT(DISTINCT %s SEPARATOR ',')", 'source_item.' . SourceItemInterface::SKU), - SourceItem::ID_FIELD_NAME => - sprintf("GROUP_CONCAT(DISTINCT %s SEPARATOR ',')", 'source_item.' . SourceItem::ID_FIELD_NAME) - ] - )->joinInner( - ['stock_source_link' => $sourceStockLinkTable], - sprintf( - 'source_item.%s = stock_source_link.%s', - SourceItemInterface::SOURCE_CODE, - StockSourceLink::SOURCE_CODE - ), - [StockSourceLink::STOCK_ID] - )->where( - 'source_item.source_item_id IN (?)', - $bundleChildrenSourceItemsIds - ) - ->group(['stock_source_link.' . StockSourceLink::STOCK_ID]); - - $connection->query('SET group_concat_max_len = ' . $this->groupConcatMaxLen); - $items = $connection->fetchAll($select); - - return $this->getStockIdToSkuList($items, $bundleChildrenSourceItemsIds); - } - - /** - * Return the assigned stock id to sku list; - * Sku list format: [bundle sku => [children skus]]. - * - * @param array $items - * @param array $bundleChildrenSourceItemsIds - * - * @return SkuListInStock[] - */ - private function getStockIdToSkuList(array $items, array $bundleChildrenSourceItemsIds): array - { - $skuListInStockList = []; - foreach ($items as $item) { - $skus = []; - $sourceItemsIdsWithSkus = array_combine( - explode(',', $item[SourceItem::ID_FIELD_NAME]), - explode(',', $item[SourceItemInterface::SKU]) - ); - foreach ($bundleChildrenSourceItemsIds as $bundleSku => $sourceItemIds) { - foreach ($sourceItemIds as $sourceItemId) { - if (isset($sourceItemsIdsWithSkus[$sourceItemId])) { - $skus[$bundleSku][] = $sourceItemsIdsWithSkus[$sourceItemId]; - } - } - } - /** @var SkuListInStock $skuListInStock */ - $skuListInStock = $this->skuListInStockFactory->create(); - $skuListInStock->setStockId((int)$item[StockSourceLink::STOCK_ID]); - $skuListInStock->setSkuList($skus); - $skuListInStockList[] = $skuListInStock; - } - - return $skuListInStockList; - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/IndexDataBySkuListProvider.php b/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/IndexDataBySkuListProvider.php deleted file mode 100644 index c64c0ffc0ec83..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/IndexDataBySkuListProvider.php +++ /dev/null @@ -1,75 +0,0 @@ -stockIndexTableNameResolver = $stockIndexTableNameResolver; - $this->resourceConnection = $resourceConnection; - } - - /** - * @param int $stockId - * @param array $bundleChildrenSourceItemsSkus - * @return ArrayIterator - */ - public function execute(int $stockId, array $bundleChildrenSourceItemsSkus): ArrayIterator - { - $stockIndexTable = $this->stockIndexTableNameResolver->execute($stockId); - - $indexData = []; - foreach ($bundleChildrenSourceItemsSkus as $bundleSku => $bundleChildrenSourceItems) { - $select = $this->resourceConnection->getConnection()->select(); - $select->from( - ['stock_index' => $stockIndexTable], - [IndexStructure::IS_SALABLE => 'MAX(stock_index.' . IndexStructure::IS_SALABLE . ')'] - )->joinInner( - ['source_item' => $this->resourceConnection->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)], - 'stock_index.' . IndexStructure::SKU . ' = source_item.' . SourceItemInterface::SKU, - [] - )->where('source_item.' . SourceItemInterface::SKU . ' IN (?)', $bundleChildrenSourceItems); - - $isSalable = $this->resourceConnection->getConnection()->fetchOne($select); - - $indexData[] = [ - IndexStructure::SKU => $bundleSku, - IndexStructure::QUANTITY => 0, - IndexStructure::IS_SALABLE => $isSalable, - ]; - } - return new ArrayIterator($indexData); - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemIndexer.php b/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemIndexer.php deleted file mode 100644 index b2fb1b8d24777..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemIndexer.php +++ /dev/null @@ -1,79 +0,0 @@ -childrenSourceItemsIdsProvider = $childrenSourceItemsIdsProvider; - $this->byBundleSkuAndChildrenSourceItemsIdsIndexer = $byBundleSkuAndChildrenSourceItemsIdsIndexer; - } - - /** - * @return void - */ - public function executeFull() - { - $bundleChildrenSourceItemsIdsWithSku = $this->childrenSourceItemsIdsProvider->execute(); - - if (count($bundleChildrenSourceItemsIdsWithSku)) { - $this->byBundleSkuAndChildrenSourceItemsIdsIndexer->execute($bundleChildrenSourceItemsIdsWithSku); - } - } - - /** - * @param int $sourceItemId - * @return void - */ - public function executeRow(int $sourceItemId) - { - $this->executeList([$sourceItemId]); - } - - /** - * @param array $sourceItemIds - * @return void - */ - public function executeList(array $sourceItemIds) - { - $bundleChildrenSourceItemsIdsWithSku = $this->childrenSourceItemsIdsProvider->execute($sourceItemIds); - - if (count($bundleChildrenSourceItemsIdsWithSku)) { - $this->byBundleSkuAndChildrenSourceItemsIdsIndexer->execute($bundleChildrenSourceItemsIdsWithSku); - } - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemsIdsByChildrenProductsIdsProvider.php b/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemsIdsByChildrenProductsIdsProvider.php deleted file mode 100644 index 30dd52d350a9d..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Indexer/SourceItem/SourceItemsIdsByChildrenProductsIdsProvider.php +++ /dev/null @@ -1,51 +0,0 @@ -resourceConnection = $resourceConnection; - } - - /** - * @param array $productIds - * - * @return array - */ - public function execute(array $productIds): array - { - $select = $this->resourceConnection->getConnection()->select(); - $select->from( - ['source_item' => $this->resourceConnection->getTableName(SourceItem::TABLE_NAME_SOURCE_ITEM)], - [SourceItem::ID_FIELD_NAME] - )->joinInner( - ['product' => $this->resourceConnection->getTableName('catalog_product_entity')], - 'source_item.sku = product.sku', - [] - )->where( - 'product.entity_id in (?)', - $productIds - ); - - return array_column($select->query()->fetchAll(), 'source_item_id'); - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/LICENSE.txt b/app/code/Magento/InventoryBundleIndexer/LICENSE.txt deleted file mode 100644 index 49525fd99da9c..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/LICENSE.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Open Software License ("OSL") v. 3.0 - -This Open Software License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Open Software License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, with the proviso that copies of Original Work or Derivative Works that You distribute or communicate shall be licensed under this Open Software License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including 'fair use' or 'fair dealing'). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright (C) 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Open Software License" or "OSL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. \ No newline at end of file diff --git a/app/code/Magento/InventoryBundleIndexer/LICENSE_AFL.txt b/app/code/Magento/InventoryBundleIndexer/LICENSE_AFL.txt deleted file mode 100644 index f39d641b18a19..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/LICENSE_AFL.txt +++ /dev/null @@ -1,48 +0,0 @@ - -Academic Free License ("AFL") v. 3.0 - -This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following licensing notice adjacent to the copyright notice for the Original Work: - -Licensed under the Academic Free License version 3.0 - - 1. Grant of Copyright License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, for the duration of the copyright, to do the following: - - 1. to reproduce the Original Work in copies, either alone or as part of a collective work; - - 2. to translate, adapt, alter, transform, modify, or arrange the Original Work, thereby creating derivative works ("Derivative Works") based upon the Original Work; - - 3. to distribute or communicate copies of the Original Work and Derivative Works to the public, under any license of your choice that does not contradict the terms and conditions, including Licensor's reserved rights and remedies, in this Academic Free License; - - 4. to perform the Original Work publicly; and - - 5. to display the Original Work publicly. - - 2. Grant of Patent License. Licensor grants You a worldwide, royalty-free, non-exclusive, sublicensable license, under patent claims owned or controlled by the Licensor that are embodied in the Original Work as furnished by the Licensor, for the duration of the patents, to make, use, sell, offer for sale, have made, and import the Original Work and Derivative Works. - - 3. Grant of Source Code License. The term "Source Code" means the preferred form of the Original Work for making modifications to it and all available documentation describing how to modify the Original Work. Licensor agrees to provide a machine-readable copy of the Source Code of the Original Work along with each copy of the Original Work that Licensor distributes. Licensor reserves the right to satisfy this obligation by placing a machine-readable copy of the Source Code in an information repository reasonably calculated to permit inexpensive and convenient access by You for as long as Licensor continues to distribute the Original Work. - - 4. Exclusions From License Grant. Neither the names of Licensor, nor the names of any contributors to the Original Work, nor any of their trademarks or service marks, may be used to endorse or promote products derived from this Original Work without express prior permission of the Licensor. Except as expressly stated herein, nothing in this License grants any license to Licensor's trademarks, copyrights, patents, trade secrets or any other intellectual property. No patent license is granted to make, use, sell, offer for sale, have made, or import embodiments of any patent claims other than the licensed claims defined in Section 2. No license is granted to the trademarks of Licensor even if such marks are included in the Original Work. Nothing in this License shall be interpreted to prohibit Licensor from licensing under terms different from this License any Original Work that Licensor otherwise would have a right to license. - - 5. External Deployment. The term "External Deployment" means the use, distribution, or communication of the Original Work or Derivative Works in any way such that the Original Work or Derivative Works may be used by anyone other than You, whether those works are distributed or communicated to those persons or made available as an application intended for use over a network. As an express condition for the grants of license hereunder, You must treat any External Deployment by You of the Original Work or a Derivative Work as a distribution under section 1(c). - - 6. Attribution Rights. You must retain, in the Source Code of any Derivative Works that You create, all copyright, patent, or trademark notices from the Source Code of the Original Work, as well as any notices of licensing and any descriptive text identified therein as an "Attribution Notice." You must cause the Source Code for any Derivative Works that You create to carry a prominent Attribution Notice reasonably calculated to inform recipients that You have modified the Original Work. - - 7. Warranty of Provenance and Disclaimer of Warranty. Licensor warrants that the copyright in and to the Original Work and the patent rights granted herein by Licensor are owned by the Licensor or are sublicensed to You under the terms of this License with the permission of the contributor(s) of those copyrights and patent rights. Except as expressly stated in the immediately preceding sentence, the Original Work is provided under this License on an "AS IS" BASIS and WITHOUT WARRANTY, either express or implied, including, without limitation, the warranties of non-infringement, merchantability or fitness for a particular purpose. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential part of this License. No license to the Original Work is granted by this License except under this disclaimer. - - 8. Limitation of Liability. Under no circumstances and under no legal theory, whether in tort (including negligence), contract, or otherwise, shall the Licensor be liable to anyone for any indirect, special, incidental, or consequential damages of any character arising as a result of this License or the use of the Original Work including, without limitation, damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses. This limitation of liability shall not apply to the extent applicable law prohibits such limitation. - - 9. Acceptance and Termination. If, at any time, You expressly assented to this License, that assent indicates your clear and irrevocable acceptance of this License and all of its terms and conditions. If You distribute or communicate copies of the Original Work or a Derivative Work, You must make a reasonable effort under the circumstances to obtain the express assent of recipients to the terms of this License. This License conditions your rights to undertake the activities listed in Section 1, including your right to create Derivative Works based upon the Original Work, and doing so without honoring these terms and conditions is prohibited by copyright law and international treaty. Nothing in this License is intended to affect copyright exceptions and limitations (including "fair use" or "fair dealing"). This License shall terminate immediately and You may no longer exercise any of the rights granted to You by this License upon your failure to honor the conditions in Section 1(c). - - 10. Termination for Patent Action. This License shall terminate automatically and You may no longer exercise any of the rights granted to You by this License as of the date You commence an action, including a cross-claim or counterclaim, against Licensor or any licensee alleging that the Original Work infringes a patent. This termination provision shall not apply for an action alleging patent infringement by combinations of the Original Work with other software or hardware. - - 11. Jurisdiction, Venue and Governing Law. Any action or suit relating to this License may be brought only in the courts of a jurisdiction wherein the Licensor resides or in which Licensor conducts its primary business, and under the laws of that jurisdiction excluding its conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. Any use of the Original Work outside the scope of this License or after its termination shall be subject to the requirements and penalties of copyright or patent law in the appropriate jurisdiction. This section shall survive the termination of this License. - - 12. Attorneys' Fees. In any action to enforce the terms of this License or seeking damages relating thereto, the prevailing party shall be entitled to recover its costs and expenses, including, without limitation, reasonable attorneys' fees and costs incurred in connection with such action, including any appeal of such action. This section shall survive the termination of this License. - - 13. Miscellaneous. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. - - 14. Definition of "You" in This License. "You" throughout this License, whether in upper or lower case, means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity that controls, is controlled by, or is under common control with you. For purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. - - 15. Right to Use. You may use the Original Work in all ways not otherwise restricted or conditioned by this License or by law, and Licensor promises not to interfere with or be responsible for such uses by You. - - 16. Modification of This License. This License is Copyright © 2005 Lawrence Rosen. Permission is granted to copy, distribute, or communicate this License without modification. Nothing in this License permits You to modify this License as applied to the Original Work or to Derivative Works. However, You may modify the text of this License and copy, distribute or communicate your modified version (the "Modified License") and apply it to other original works of authorship subject to the following conditions: (i) You may not indicate in any way that your Modified License is the "Academic Free License" or "AFL" and you may not use those names in the name of your Modified License; (ii) You must replace the notice specified in the first paragraph above with the notice "Licensed under " or with a notice of your own that is not confusingly similar to the notice in this License; and (iii) You may not claim that your original works are open source software unless your Modified License has been approved by Open Source Initiative (OSI) and You comply with its license review and certification process. diff --git a/app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexByBundleIds.php b/app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexByBundleIds.php deleted file mode 100644 index 12ef183c40204..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexByBundleIds.php +++ /dev/null @@ -1,93 +0,0 @@ -productRepository = $productRepository; - $this->bundleBySkuAndChildrenSourceItemsIdsIndexer = $bundleBySkuAndChildrenSourceItemsIdsIndexer; - $this->sourceItemsIdsByChildrenProductsIdsProvider = $sourceItemsIdsByChildrenProductsIdsProvider; - } - - /** - * @param ProductOptionRepositoryInterface $subject - * @param $result - * @param ProductInterface $product - * @param OptionInterface $option - * - * @return int - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterSave( - ProductOptionRepositoryInterface $subject, - $result, - ProductInterface $product, - OptionInterface $option - ) { - $childrenIds = $this->getChildrenProductIdsByProductLinks($option->getProductLinks()); - - $bundleChildrenSourceItemsIdsWithSku = [ - $product->getSku() => $this->sourceItemsIdsByChildrenProductsIdsProvider->execute($childrenIds) - ]; - - $this->bundleBySkuAndChildrenSourceItemsIdsIndexer->execute($bundleChildrenSourceItemsIdsWithSku); - - return $result; - } - - /** - * @param array $productLinks - * - * @return array - */ - private function getChildrenProductIdsByProductLinks(array $productLinks): array - { - $productIds = []; - foreach ($productLinks as $productLink) { - $productId = $productLink->getProductId(); - if (null === $productId) { - $productId = $this->productRepository->get($productLink->getSku())->getId(); - } - $productIds[] = $productId; - } - - return $productIds; - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexBySourceItemsIds.php b/app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexBySourceItemsIds.php deleted file mode 100644 index 3c9bd776f6df6..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Plugin/InventoryIndexer/Indexer/SourceItem/AddBundleDataToIndexBySourceItemsIds.php +++ /dev/null @@ -1,58 +0,0 @@ -sourceItemIndexer = $sourceItemIndexer; - } - - /** - * @param SourceItemIndexer $sourceItemIndexer - * @param void $result - * @return void - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterExecuteFull( - SourceItemIndexer $sourceItemIndexer, - $result - ) { - $this->sourceItemIndexer->executeFull(); - } - - /** - * @param SourceItemIndexer $subject - * @param void $result - * @param array $sourceItemIds - * @return void - * - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterExecuteList( - SourceItemIndexer $subject, - $result, - array $sourceItemIds - ) { - $this->sourceItemIndexer->executeList($sourceItemIds); - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/README.md b/app/code/Magento/InventoryBundleIndexer/README.md deleted file mode 100644 index 94c2a6eb45352..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/README.md +++ /dev/null @@ -1 +0,0 @@ -# InventoryBundleIndexer diff --git a/app/code/Magento/InventoryBundleIndexer/Test/Integration/SourceItemIndexerTest.php b/app/code/Magento/InventoryBundleIndexer/Test/Integration/SourceItemIndexerTest.php deleted file mode 100644 index 2302e36ec0d4e..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Test/Integration/SourceItemIndexerTest.php +++ /dev/null @@ -1,204 +0,0 @@ -productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class); - $this->getStockItemData = Bootstrap::getObjectManager()->get(GetStockItemDataInterface::class); - $this->selection = Bootstrap::getObjectManager()->get(Selection::class); - $this->getProductIdsBySkus = Bootstrap::getObjectManager()->get(GetProductIdsBySkusInterface::class); - $this->sourceItemRepository = Bootstrap::getObjectManager()->get(SourceItemRepositoryInterface::class); - $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); - $this->sourceItemsSave = Bootstrap::getObjectManager()->get(SourceItemsSaveInterface::class); - } - - /** - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items_eu_stock_only.php - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php - * - * @return void - */ - public function testReindexWithAllChildrenInStock() - { - $bundleStockItemData = $this->getStockItemData->execute('bundle-product-eu-website', 10); - - self::assertEquals(1, $bundleStockItemData[GetStockItemDataInterface::IS_SALABLE]); - } - - /** - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items_eu_stock_only.php - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php - * - * @return void - */ - public function testReindexWithOneChildOutOfStock() - { - $this->makeChildrenOutOfStock(1); - $bundleStockItemData = $this->getStockItemData->execute('bundle-product-eu-website', 10); - - self::assertEquals(1, $bundleStockItemData[GetStockItemDataInterface::IS_SALABLE]); - } - - /** - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items_eu_stock_only.php - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php - * - * @return void - */ - public function testReindexWithAllChildrenOutOfStock() - { - $this->makeChildrenOutOfStock(3); - $bundleStockItemData = $this->getStockItemData->execute('bundle-product-eu-website', 10); - - self::assertEquals(0, $bundleStockItemData[GetStockItemDataInterface::IS_SALABLE]); - } - - /** - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/websites_with_stores.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/products.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/sources.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stocks.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/stock_source_links.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryApi/Test/_files/source_items_eu_stock_only.php - * @magentoDataFixture ../../../../app/code/Magento/InventorySalesApi/Test/_files/stock_website_sales_channels.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php - * @magentoDataFixture ../../../../app/code/Magento/InventoryIndexer/Test/_files/reindex_inventory.php - * - * @return void - */ - public function testReindexWhenSaveParent() - { - $bundleSku = 'bundle-product-eu-website'; - - $this->makeChildrenOutOfStock(2); - $bundleStockItemData = $this->getStockItemData->execute($bundleSku, 10); - self::assertEquals(1, (bool)$bundleStockItemData[GetStockItemDataInterface::IS_SALABLE]); - - //unassign only in stock product from bundle to make it out of stock - $bundleProduct = $this->productRepository->get($bundleSku, true, null, true); - $productLinks = $bundleProduct->getExtensionAttributes()->getBundleProductOptions()[0]->getProductLinks(); - $unassignedLink = $productLinks[2]; - unset($productLinks[2]); - $bundleProduct->getExtensionAttributes()->getBundleProductOptions()[0]->setProductLinks($productLinks); - $this->productRepository->save($bundleProduct); - $bundleStockItemData = $this->getStockItemData->execute($bundleSku, 10); - self::assertEquals(0, (bool)$bundleStockItemData[GetStockItemDataInterface::IS_SALABLE]); - - //assign product in stock to make bundle in stock - $unassignedLink->setId(null); - $productLinks[2] = $unassignedLink; - $bundleProduct->getExtensionAttributes()->getBundleProductOptions()[0]->setProductLinks($productLinks); - $this->productRepository->save($bundleProduct); - $bundleStockItemData = $this->getStockItemData->execute($bundleSku, 10); - self::assertEquals(1, (bool)$bundleStockItemData[GetStockItemDataInterface::IS_SALABLE]); - } - - /** - * @param int $childrenQty - * @return void - */ - private function makeChildrenOutOfStock(int $childrenQty) - { - $ids = $this->getProductIdsBySkus->execute(['bundle-product-eu-website']); - $id = reset($ids); - - $childrenIds = $this->selection->getChildrenIds($id)[0]; - foreach ($childrenIds as $childId) { - if ($childrenQty === 0) { - break; - } - $child = $this->productRepository->getById($childId); - - $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(SourceItemInterface::SKU, $child->getSku()) - ->create(); - $items = $this->sourceItemRepository->getList($searchCriteria)->getItems(); - $sourceItem = reset($items); - $sourceItem->setQuantity(0); - $sourceItem->setStatus(0); - - $this->sourceItemsSave->execute([$sourceItem]); - $childrenQty--; - } - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php b/app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php deleted file mode 100644 index 57846f1f1a222..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website.php +++ /dev/null @@ -1,106 +0,0 @@ -create(\Magento\Catalog\Api\ProductRepositoryInterface::class); -$simpleSku1 = $productRepository->get('SKU-1'); -$simpleSku2 = $productRepository->get('SKU-2'); -$simpleSku3 = $productRepository->get('SKU-3'); - -$website = Bootstrap::getObjectManager()->create(Website::class); -$website->load('eu_website', 'code'); -$websiteIds = [$website->getId()]; - -/** @var $product \Magento\Catalog\Model\Product */ -$product = $objectManager->create(\Magento\Catalog\Model\Product::class); -$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_BUNDLE) - ->setAttributeSetId(4) - ->setWebsiteIds($websiteIds) - ->setName('Bundle Product With All Children In Stock') - ->setSku('bundle-product-eu-website') - ->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH) - ->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) - ->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1]) - ->setPriceView(1) - ->setPriceType(1) - ->setPrice(10.0) - ->setShipmentType(0) - ->setBundleOptionsData( - [ - [ - 'title' => 'Option 1', - 'default_title' => 'Option 1', - 'type' => 'select', - 'required' => 0, - 'delete' => '', - ], - ] - )->setBundleSelectionsData( - [ - [ - [ - 'product_id' => $simpleSku1->getId(), - 'selection_qty' => 10, - 'selection_can_change_qty' => 0, - 'delete' => '', - 'option_id' => 1 - ], - [ - 'product_id' => $simpleSku2->getId(), - 'selection_qty' => 15, - 'selection_can_change_qty' => 0, - 'delete' => '', - 'option_id' => 1 - ], - [ - 'product_id' => $simpleSku3->getId(), - 'selection_qty' => 20, - 'selection_can_change_qty' => 0, - 'delete' => '', - 'option_id' => 1 - ], - ], - ] - ); - -if ($product->getBundleOptionsData()) { - $options = []; - foreach ($product->getBundleOptionsData() as $key => $optionData) { - if (!(bool)$optionData['delete']) { - $option = $objectManager->create(\Magento\Bundle\Api\Data\OptionInterfaceFactory::class) - ->create(['data' => $optionData]); - $option->setSku($product->getSku()); - $option->setOptionId(null); - - $links = []; - $bundleLinks = $product->getBundleSelectionsData(); - if (!empty($bundleLinks[$key])) { - foreach ($bundleLinks[$key] as $linkData) { - if (!(bool)$linkData['delete']) { - $link = $objectManager->create(\Magento\Bundle\Api\Data\LinkInterfaceFactory::class) - ->create(['data' => $linkData]); - $linkProduct = $productRepository->getById($linkData['product_id']); - $link->setSku($linkProduct->getSku()); - $link->setQty($linkData['selection_qty']); - $links[] = $link; - } - } - $option->setProductLinks($links); - $options[] = $option; - } - } - } - $extension = $product->getExtensionAttributes(); - $extension->setBundleProductOptions($options); - $product->setExtensionAttributes($extension); -} - -$productRepository->save($product, true); diff --git a/app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website_rollback.php b/app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website_rollback.php deleted file mode 100644 index 95ff0cb254767..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/Test/_files/bundle_product_eu_website_rollback.php +++ /dev/null @@ -1,26 +0,0 @@ -get(\Magento\Framework\Registry::class); - -$registry->unregister('isSecureArea'); -$registry->register('isSecureArea', true); - -/** @var $product \Magento\Catalog\Model\Product */ -$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager() - ->create(\Magento\Catalog\Api\ProductRepositoryInterface::class); - -try { - $product = $productRepository->get('bundle-product-eu-website'); - $productRepository->delete($product); -} catch (\Magento\Framework\Exception\NoSuchEntityException $exception) { - //Product already removed -} - -$registry->unregister('isSecureArea'); -$registry->register('isSecureArea', false); diff --git a/app/code/Magento/InventoryBundleIndexer/composer.json b/app/code/Magento/InventoryBundleIndexer/composer.json deleted file mode 100644 index 722275f9bbdf5..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/composer.json +++ /dev/null @@ -1,30 +0,0 @@ -{ - "name": "magento/module-inventory-bundle-indexer", - "description": "N/A", - "require": { - "php": "7.0.2|7.0.4|~7.0.6|~7.1.0", - "magento/module-inventory-indexer": "100.0.*", - "magento/module-inventory": "100.0.*", - "magento/module-inventory-api": "100.0.*", - "magento/module-catalog": "100.3.*", - "magento/framework": "100.3.*" - }, - "suggest": { - "magento/module-bundle": "100.3.*", - "magento/module-inventory-sales": "100.0.*" - }, - "type": "magento2-module", - "version": "100.0.0-dev", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "Magento\\InventoryBundleIndexer\\": "" - } - } -} diff --git a/app/code/Magento/InventoryBundleIndexer/etc/di.xml b/app/code/Magento/InventoryBundleIndexer/etc/di.xml deleted file mode 100644 index d26a65cd28cc5..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/etc/di.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - Magento\InventoryIndexer\Indexer\IndexHandler - - - - - - - - 2000 - - - diff --git a/app/code/Magento/InventoryBundleIndexer/etc/module.xml b/app/code/Magento/InventoryBundleIndexer/etc/module.xml deleted file mode 100644 index 978a956caaab5..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/etc/module.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - diff --git a/app/code/Magento/InventoryBundleIndexer/registration.php b/app/code/Magento/InventoryBundleIndexer/registration.php deleted file mode 100644 index 438ff4d5324fe..0000000000000 --- a/app/code/Magento/InventoryBundleIndexer/registration.php +++ /dev/null @@ -1,12 +0,0 @@ -=6.5.0" - }, "require-dev": { "container-interop/container-interop": "^1.1", "mongodb/mongodb": "^1.0.1", "php-mock/php-mock-phpunit": "^1.1.2 || ^2.0", - "phpunit/phpunit": "^5.7.5 || ^6.0.13", + "phpunit/phpunit": "^5.7.5 || >=6.0.13 <6.5.0", "zendframework/zend-cache": "^2.6.1", "zendframework/zend-coding-standard": "~1.0.0", "zendframework/zend-db": "^2.7", @@ -3770,7 +3767,7 @@ "session", "zf" ], - "time": "2018-01-31T17:38:47+00:00" + "time": "2018-02-22T16:33:54+00:00" }, { "name": "zendframework/zend-soap", @@ -4778,16 +4775,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.3", + "version": "1.7.5", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", "shasum": "" }, "require": { @@ -4799,7 +4796,7 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" }, "type": "library", "extra": { @@ -4837,7 +4834,7 @@ "spy", "stub" ], - "time": "2017-11-24T13:59:53+00:00" + "time": "2018-02-19T10:16:54+00:00" }, { "name": "phpunit/php-code-coverage", @@ -5933,16 +5930,16 @@ }, { "name": "symfony/config", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "72689b934d6c6ecf73eca874e98933bf055313c9" + "reference": "05e10567b529476a006b00746c5f538f1636810e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/72689b934d6c6ecf73eca874e98933bf055313c9", - "reference": "72689b934d6c6ecf73eca874e98933bf055313c9", + "url": "https://api.github.com/repos/symfony/config/zipball/05e10567b529476a006b00746c5f538f1636810e", + "reference": "05e10567b529476a006b00746c5f538f1636810e", "shasum": "" }, "require": { @@ -5955,6 +5952,7 @@ }, "require-dev": { "symfony/dependency-injection": "~3.3|~4.0", + "symfony/event-dispatcher": "~3.3|~4.0", "symfony/finder": "~3.3|~4.0", "symfony/yaml": "~3.0|~4.0" }, @@ -5991,20 +5989,20 @@ ], "description": "Symfony Config Component", "homepage": "https://symfony.com", - "time": "2018-01-21T19:05:02+00:00" + "time": "2018-02-14T10:03:57+00:00" }, { "name": "symfony/dependency-injection", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/dependency-injection.git", - "reference": "4b2717ee2499390e371e1fc7abaf886c1c83e83d" + "reference": "12e901abc1cb0d637a0e5abe9923471361d96b07" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/4b2717ee2499390e371e1fc7abaf886c1c83e83d", - "reference": "4b2717ee2499390e371e1fc7abaf886c1c83e83d", + "url": "https://api.github.com/repos/symfony/dependency-injection/zipball/12e901abc1cb0d637a0e5abe9923471361d96b07", + "reference": "12e901abc1cb0d637a0e5abe9923471361d96b07", "shasum": "" }, "require": { @@ -6062,7 +6060,7 @@ ], "description": "Symfony DependencyInjection Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:16:57+00:00" + "time": "2018-03-04T03:54:53+00:00" }, { "name": "symfony/polyfill-php54", @@ -6342,16 +6340,16 @@ }, { "name": "symfony/stopwatch", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", - "reference": "c865551df7c17e63fc1f09f763db04387f91ae4d" + "reference": "eb17cfa072cab26537ac37e9c4ece6c0361369af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/stopwatch/zipball/c865551df7c17e63fc1f09f763db04387f91ae4d", - "reference": "c865551df7c17e63fc1f09f763db04387f91ae4d", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/eb17cfa072cab26537ac37e9c4ece6c0361369af", + "reference": "eb17cfa072cab26537ac37e9c4ece6c0361369af", "shasum": "" }, "require": { @@ -6387,7 +6385,7 @@ ], "description": "Symfony Stopwatch Component", "homepage": "https://symfony.com", - "time": "2018-01-03T07:37:34+00:00" + "time": "2018-02-17T14:55:25+00:00" }, { "name": "theseer/fdomdocument", diff --git a/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/strict_type.txt b/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/strict_type.txt index f870e5b0bea28..0a96745f6b6cc 100644 --- a/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/strict_type.txt +++ b/dev/tests/static/testsuite/Magento/Test/Php/_files/whitelist/strict_type.txt @@ -2,7 +2,6 @@ app/code/Magento/Inventory app/code/Magento/InventoryApi app/code/Magento/InventoryBundle -app/code/Magento/InventoryBundleIndexer app/code/Magento/InventoryCatalog app/code/Magento/InventoryCatalogSearch app/code/Magento/InventoryConfigurableProduct From 9903fc8682443216ac1353e51ab04bf16b4313af Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 27 Mar 2018 16:59:25 +0300 Subject: [PATCH 2/5] MSI-757: Add Inventory Index invalidation when Source is enabled or disabled. --- .../Schema/CreateLegacyStockStatusView.php | 94 +++++++++++++++++++ .../Indexer/SourceItem/GetSourceItemIds.php | 55 +++++++++++ .../Indexer/SourceItem/SourceItemIndexer.php | 15 ++- .../Indexer/Stock/StockIndexer.php | 15 ++- .../ReindexAfterSourceItemsDeletePlugin.php | 10 +- .../ReindexAfterSourceItemsSavePlugin.php | 22 ++--- ...indexAfterStockSourceLinksDeletePlugin.php | 44 --------- ...ReindexAfterStockSourceLinksSavePlugin.php | 44 --------- ...ndexAroundStockSourceLinksDeletePlugin.php | 64 +++++++++++++ ...eindexAroundStockSourceLinksSavePlugin.php | 62 ++++++++++++ .../Magento/InventoryIndexer/composer.json | 1 + app/code/Magento/InventoryIndexer/etc/di.xml | 4 +- .../Magento/InventoryIndexer/etc/module.xml | 1 + 13 files changed, 315 insertions(+), 116 deletions(-) create mode 100644 app/code/Magento/InventoryCatalog/Setup/Patch/Schema/CreateLegacyStockStatusView.php create mode 100644 app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php delete mode 100644 app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksDeletePlugin.php delete mode 100644 app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksSavePlugin.php create mode 100644 app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksDeletePlugin.php create mode 100644 app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php diff --git a/app/code/Magento/InventoryCatalog/Setup/Patch/Schema/CreateLegacyStockStatusView.php b/app/code/Magento/InventoryCatalog/Setup/Patch/Schema/CreateLegacyStockStatusView.php new file mode 100644 index 0000000000000..8eff3691a5ce8 --- /dev/null +++ b/app/code/Magento/InventoryCatalog/Setup/Patch/Schema/CreateLegacyStockStatusView.php @@ -0,0 +1,94 @@ +schemaSetup = $schemaSetup; + $this->stockIndexTableNameResolver = $stockIndexTableNameResolver; + $this->defaultStockProvider = $defaultStockProvider; + } + + /** + * @inheritdoc + */ + public function getAliases() + { + return []; + } + + /** + * @inheritdoc + */ + public function apply() + { + $this->schemaSetup->startSetup(); + $defaultStockId = $this->defaultStockProvider->getId(); + $legacyView = $this->stockIndexTableNameResolver->execute($defaultStockId); + $cataloginventoryStockStatus = $this->schemaSetup->getTable('cataloginventory_stock_status'); + $catalogProductEntity = $this->schemaSetup->getTable('catalog_product_entity'); + $sql = "CREATE + VIEW {$legacyView} + AS + SELECT + css.product_id, + css.website_id, + css.stock_id, + css.qty AS quantity, + css.stock_status AS is_salable, + cpe.sku + FROM {$cataloginventoryStockStatus} AS css + INNER JOIN {$catalogProductEntity} AS cpe + ON css.product_id = cpe.entity_id;"; + $this->schemaSetup->getConnection()->query($sql); + $this->schemaSetup->endSetup(); + + return $this; + } + + /** + * @inheritdoc + */ + public static function getDependencies() + { + return []; + } +} diff --git a/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php b/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php new file mode 100644 index 0000000000000..020f2db1e02a6 --- /dev/null +++ b/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php @@ -0,0 +1,55 @@ +resourceConnection = $resourceConnection; + } + + /** + * @param SourceItemInterface[] $sourceItems + * @return array + */ + public function execute(array $sourceItems): array + { + $connection = $this->resourceConnection->getConnection(); + $select = $connection->select() + ->from( + $this->resourceConnection->getTableName(SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM), + [SourceItemResourceModel::ID_FIELD_NAME] + ); + foreach ($sourceItems as $sourceItem) { + $sku = $connection->quote($sourceItem->getSku()); + $sourceCode = $connection->quote($sourceItem->getSourceCode()); + $select->orWhere( + SourceItemInterface::SKU . " = {$sku} AND " . + SourceItemInterface::SOURCE_CODE ." = {$sourceCode}" + ); + } + + return $connection->fetchAll($select); + } +} diff --git a/app/code/Magento/InventoryIndexer/Indexer/SourceItem/SourceItemIndexer.php b/app/code/Magento/InventoryIndexer/Indexer/SourceItem/SourceItemIndexer.php index 1e391d7381e79..16391a16cad2f 100644 --- a/app/code/Magento/InventoryIndexer/Indexer/SourceItem/SourceItemIndexer.php +++ b/app/code/Magento/InventoryIndexer/Indexer/SourceItem/SourceItemIndexer.php @@ -12,6 +12,7 @@ use Magento\Framework\MultiDimensionalIndexer\IndexHandlerInterface; use Magento\Framework\MultiDimensionalIndexer\IndexNameBuilder; use Magento\Framework\MultiDimensionalIndexer\IndexStructureInterface; +use Magento\InventoryCatalog\Model\DefaultStockProvider; use Magento\InventoryIndexer\Indexer\InventoryIndexer; use Magento\InventoryIndexer\Indexer\Stock\StockIndexer; @@ -52,6 +53,11 @@ class SourceItemIndexer */ private $stockIndexer; + /** + * @var DefaultStockProvider + */ + private $defaultStockProvider; + /** * $indexStructure is reserved name for construct variable (in index internal mechanism) * @@ -61,6 +67,7 @@ class SourceItemIndexer * @param IndexDataBySkuListProvider $indexDataBySkuListProvider * @param IndexNameBuilder $indexNameBuilder * @param StockIndexer $stockIndexer + * @param DefaultStockProvider $defaultStockProvider */ public function __construct( GetSkuListInStock $getSkuListInStockToUpdate, @@ -68,7 +75,8 @@ public function __construct( IndexHandlerInterface $indexHandler, IndexDataBySkuListProvider $indexDataBySkuListProvider, IndexNameBuilder $indexNameBuilder, - StockIndexer $stockIndexer + StockIndexer $stockIndexer, + DefaultStockProvider $defaultStockProvider ) { $this->getSkuListInStock = $getSkuListInStockToUpdate; $this->indexStructure = $indexStructureHandler; @@ -76,6 +84,7 @@ public function __construct( $this->indexDataBySkuListProvider = $indexDataBySkuListProvider; $this->indexNameBuilder = $indexNameBuilder; $this->stockIndexer = $stockIndexer; + $this->defaultStockProvider = $defaultStockProvider; } /** @@ -105,6 +114,10 @@ public function executeList(array $sourceItemIds) foreach ($skuListInStockList as $skuListInStock) { $stockId = $skuListInStock->getStockId(); + if ($this->defaultStockProvider->getId() === $stockId) { + continue; + } + $skuList = $skuListInStock->getSkuList(); $mainIndexName = $this->indexNameBuilder diff --git a/app/code/Magento/InventoryIndexer/Indexer/Stock/StockIndexer.php b/app/code/Magento/InventoryIndexer/Indexer/Stock/StockIndexer.php index df64eea144c89..aca173fa4e419 100644 --- a/app/code/Magento/InventoryIndexer/Indexer/Stock/StockIndexer.php +++ b/app/code/Magento/InventoryIndexer/Indexer/Stock/StockIndexer.php @@ -13,6 +13,7 @@ use Magento\Framework\MultiDimensionalIndexer\IndexNameBuilder; use Magento\Framework\MultiDimensionalIndexer\IndexStructureInterface; use Magento\Framework\MultiDimensionalIndexer\IndexTableSwitcherInterface; +use Magento\InventoryCatalog\Model\DefaultStockProvider; use Magento\InventoryIndexer\Indexer\InventoryIndexer; /** @@ -53,6 +54,11 @@ class StockIndexer */ private $indexTableSwitcher; + /** + * @var DefaultStockProvider + */ + private $defaultStockProvider; + /** * $indexStructure is reserved name for construct variable in index internal mechanism * @@ -62,6 +68,7 @@ class StockIndexer * @param IndexNameBuilder $indexNameBuilder * @param IndexDataProviderByStockId $indexDataProviderByStockId * @param IndexTableSwitcherInterface $indexTableSwitcher + * @param DefaultStockProvider $defaultStockProvider */ public function __construct( GetAllAssignedStockIds $getAllAssignedStockIds, @@ -69,7 +76,8 @@ public function __construct( IndexHandlerInterface $indexHandler, IndexNameBuilder $indexNameBuilder, IndexDataProviderByStockId $indexDataProviderByStockId, - IndexTableSwitcherInterface $indexTableSwitcher + IndexTableSwitcherInterface $indexTableSwitcher, + DefaultStockProvider $defaultStockProvider ) { $this->getAllAssignedStockIds = $getAllAssignedStockIds; $this->indexStructure = $indexStructureHandler; @@ -77,6 +85,7 @@ public function __construct( $this->indexNameBuilder = $indexNameBuilder; $this->indexDataProviderByStockId = $indexDataProviderByStockId; $this->indexTableSwitcher = $indexTableSwitcher; + $this->defaultStockProvider = $defaultStockProvider; } /** @@ -104,6 +113,10 @@ public function executeRow(int $stockId) public function executeList(array $stockIds) { foreach ($stockIds as $stockId) { + if ($this->defaultStockProvider->getId() === (int)$stockId) { + continue; + } + $replicaIndexName = $this->indexNameBuilder ->setIndexId(InventoryIndexer::INDEXER_ID) ->addDimension('stock_', (string)$stockId) diff --git a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsDeletePlugin.php b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsDeletePlugin.php index 374777390297a..33275e2e3f5a5 100644 --- a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsDeletePlugin.php +++ b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsDeletePlugin.php @@ -9,7 +9,6 @@ use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\SourceItemsDeleteInterface; -use Magento\InventoryIndexer\Indexer\SourceItem\GetSourceItemId; use Magento\InventoryIndexer\Indexer\Source\SourceIndexer; /** @@ -17,23 +16,16 @@ */ class ReindexAfterSourceItemsDeletePlugin { - /** - * @var GetSourceItemId - */ - private $getSourceItemId; - /** * @var SourceIndexer */ private $sourceIndexer; /** - * @param GetSourceItemId $getSourceItemId * @param SourceIndexer $sourceIndexer */ - public function __construct(GetSourceItemId $getSourceItemId, SourceIndexer $sourceIndexer) + public function __construct(SourceIndexer $sourceIndexer) { - $this->getSourceItemId = $getSourceItemId; $this->sourceIndexer = $sourceIndexer; } diff --git a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsSavePlugin.php b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsSavePlugin.php index 3140d952be1b2..50be65d661e48 100644 --- a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsSavePlugin.php +++ b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterSourceItemsSavePlugin.php @@ -7,11 +7,9 @@ namespace Magento\InventoryIndexer\Plugin\InventoryApi; -use Magento\Framework\Indexer\IndexerInterface; -use Magento\Framework\Indexer\IndexerInterfaceFactory; use Magento\InventoryApi\Api\Data\SourceItemInterface; use Magento\InventoryApi\Api\SourceItemsSaveInterface; -use Magento\InventoryIndexer\Indexer\SourceItem\GetSourceItemId; +use Magento\InventoryIndexer\Indexer\SourceItem\GetSourceItemIds; use Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer; /** @@ -20,9 +18,9 @@ class ReindexAfterSourceItemsSavePlugin { /** - * @var GetSourceItemId + * @var GetSourceItemIds */ - private $getSourceItemId; + private $getSourceItemIds; /** * @var SourceItemIndexer @@ -30,12 +28,12 @@ class ReindexAfterSourceItemsSavePlugin private $sourceItemIndexer; /** - * @param GetSourceItemId $getSourceItemId + * @param GetSourceItemIds $getSourceItemIds * @param SourceItemIndexer $sourceItemIndexer */ - public function __construct(GetSourceItemId $getSourceItemId, SourceItemIndexer $sourceItemIndexer) + public function __construct(GetSourceItemIds $getSourceItemIds, SourceItemIndexer $sourceItemIndexer) { - $this->getSourceItemId = $getSourceItemId; + $this->getSourceItemIds = $getSourceItemIds; $this->sourceItemIndexer = $sourceItemIndexer; } @@ -51,13 +49,7 @@ public function afterExecute( $result, array $sourceItems ) { - - $sourceItemIds = []; - foreach ($sourceItems as $sourceItem) { - // TODO: replace on multi operation - $sourceItemIds[] = $this->getSourceItemId->execute($sourceItem->getSku(), $sourceItem->getSourceCode()); - } - + $sourceItemIds = $this->getSourceItemIds->execute($sourceItems); if (count($sourceItemIds)) { $this->sourceItemIndexer->executeList($sourceItemIds); } diff --git a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksDeletePlugin.php b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksDeletePlugin.php deleted file mode 100644 index 9492d6c98e9e8..0000000000000 --- a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksDeletePlugin.php +++ /dev/null @@ -1,44 +0,0 @@ -indexerRegistry = $indexerRegistry; - } - - /** - * @param StockSourceLinksDeleteInterface $subject - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterExecute(StockSourceLinksDeleteInterface $subject) - { - $indexer = $this->indexerRegistry->get(InventoryIndexer::INDEXER_ID); - if ($indexer->isValid()) { - $indexer->invalidate(); - } - } -} diff --git a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksSavePlugin.php b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksSavePlugin.php deleted file mode 100644 index 0fc14ddca082a..0000000000000 --- a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAfterStockSourceLinksSavePlugin.php +++ /dev/null @@ -1,44 +0,0 @@ -indexerRegistry = $indexerRegistry; - } - - /** - * @param StockSourceLinksSaveInterface $subject - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function afterExecute(StockSourceLinksSaveInterface $subject) - { - $indexer = $this->indexerRegistry->get(InventoryIndexer::INDEXER_ID); - if ($indexer->isValid()) { - $indexer->invalidate(); - } - } -} diff --git a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksDeletePlugin.php b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksDeletePlugin.php new file mode 100644 index 0000000000000..5c15c94671137 --- /dev/null +++ b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksDeletePlugin.php @@ -0,0 +1,64 @@ +indexerRegistry = $indexerRegistry; + $this->defaultStockProvider = $defaultStockProvider; + } + + /** + * We don't need to neither process Stock Source Links delete nor invalidate cache for Default Stock. + * + * @param StockSourceLinksDeleteInterface $subject + * @param callable $proceed + * @param array $links + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundExecute( + StockSourceLinksDeleteInterface $subject, + callable $proceed, + array $links + ) { + if ($this->defaultStockProvider->getId() !== reset($links)) { + $proceed($links); + $indexer = $this->indexerRegistry->get(InventoryIndexer::INDEXER_ID); + if ($indexer->isValid()) { + $indexer->invalidate(); + } + }; + } +} diff --git a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php new file mode 100644 index 0000000000000..4b7fa8e92fd63 --- /dev/null +++ b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php @@ -0,0 +1,62 @@ +indexerRegistry = $indexerRegistry; + $this->defaultStockProvider = $defaultStockProvider; + } + + /** + * We don't need to neither process Stock Source Links save nor invalidate cache for Default Stock. + * + * @param StockSourceLinksSaveInterface $subject + * @param callable $proceed + * @param array $links + */ + public function aroundExecute( + StockSourceLinksSaveInterface $subject, + callable $proceed, + array $links + ) { + if ($this->defaultStockProvider->getId() !== reset($links)) { + $proceed($links); + $indexer = $this->indexerRegistry->get(InventoryIndexer::INDEXER_ID); + if ($indexer->isValid()) { + $indexer->invalidate(); + } + } + } +} diff --git a/app/code/Magento/InventoryIndexer/composer.json b/app/code/Magento/InventoryIndexer/composer.json index ceb7e1d45d560..c30d563040066 100644 --- a/app/code/Magento/InventoryIndexer/composer.json +++ b/app/code/Magento/InventoryIndexer/composer.json @@ -6,6 +6,7 @@ "magento/framework": "100.3.*", "magento/module-inventory": "100.0.*", "magento/module-inventory-api": "100.0.*", + "magento/module-inventory-catalog": "100.0.*", "magento/module-inventory-sales": "100.0.*" }, "type": "magento2-module", diff --git a/app/code/Magento/InventoryIndexer/etc/di.xml b/app/code/Magento/InventoryIndexer/etc/di.xml index 1245d35f8db47..118d4b59e81d0 100644 --- a/app/code/Magento/InventoryIndexer/etc/di.xml +++ b/app/code/Magento/InventoryIndexer/etc/di.xml @@ -38,10 +38,10 @@ - + - + diff --git a/app/code/Magento/InventoryIndexer/etc/module.xml b/app/code/Magento/InventoryIndexer/etc/module.xml index 1b388765396ea..50d06a96da770 100644 --- a/app/code/Magento/InventoryIndexer/etc/module.xml +++ b/app/code/Magento/InventoryIndexer/etc/module.xml @@ -8,6 +8,7 @@ + From e318b5f6f2c4effd7dcf644ae6e5adf76d589ea7 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Tue, 27 Mar 2018 18:40:29 +0300 Subject: [PATCH 3/5] MSI-698: Adapt MSI to use Default Stock --- .../Indexer/SourceItem/GetSourceItemId.php | 51 ---------------- .../Indexer/SourceItem/GetSourceItemIds.php | 2 +- .../Indexer/SourceItemIndexerTest.php | 59 +++++++++++++++---- 3 files changed, 49 insertions(+), 63 deletions(-) delete mode 100644 app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemId.php diff --git a/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemId.php b/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemId.php deleted file mode 100644 index 250a11e769819..0000000000000 --- a/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemId.php +++ /dev/null @@ -1,51 +0,0 @@ -resourceConnection = $resourceConnection; - } - - /** - * @param string $sku - * @param string $sourceCode - * - * @return int - */ - public function execute(string $sku, string $sourceCode): int - { - $connection = $this->resourceConnection->getConnection(); - $select = $connection->select() - ->from( - $this->resourceConnection->getTableName(SourceItemResourceModel::TABLE_NAME_SOURCE_ITEM), - [SourceItemResourceModel::ID_FIELD_NAME] - ) - ->where(SourceItemInterface::SKU . ' = ?', $sku) - ->where(SourceItemInterface::SOURCE_CODE . ' = ?', $sourceCode); - - return (int)$connection->fetchOne($select); - } -} diff --git a/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php b/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php index 020f2db1e02a6..a5bab9e290dfe 100644 --- a/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php +++ b/app/code/Magento/InventoryIndexer/Indexer/SourceItem/GetSourceItemIds.php @@ -50,6 +50,6 @@ public function execute(array $sourceItems): array ); } - return $connection->fetchAll($select); + return $connection->fetchCol($select, SourceItemResourceModel::ID_FIELD_NAME); } } diff --git a/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php b/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php index 38c8fee38210b..d5219275df69e 100644 --- a/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php +++ b/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php @@ -7,7 +7,10 @@ namespace Magento\InventoryIndexer\Test\Integration\Indexer; -use Magento\InventoryIndexer\Indexer\SourceItem\GetSourceItemId; +use Magento\Framework\Api\SearchCriteriaBuilder; +use Magento\InventoryApi\Api\Data\SourceItemInterface; +use Magento\InventoryApi\Api\SourceItemRepositoryInterface; +use Magento\InventoryIndexer\Indexer\SourceItem\GetSourceItemIds; use Magento\InventoryIndexer\Indexer\SourceItem\SourceItemIndexer; use Magento\InventoryIndexer\Model\GetStockItemData; use Magento\InventorySales\Model\GetStockItemDataInterface; @@ -27,21 +30,33 @@ class SourceItemIndexerTest extends TestCase private $getStockItemData; /** - * @var GetSourceItemId + * @var GetSourceItemIds */ - private $getSourceItemId; + private $getSourceItemIds; /** * @var RemoveIndexData */ private $removeIndexData; + /** + * @var SourceItemRepositoryInterface + */ + private $sourceItemRepository; + + /** + * @var SearchCriteriaBuilder + */ + private $searchCriteriaBuilder; + + protected function setUp() { $this->sourceItemIndexer = Bootstrap::getObjectManager()->get(SourceItemIndexer::class); $this->getStockItemData = Bootstrap::getObjectManager()->get(GetStockItemData::class); - $this->getSourceItemId = Bootstrap::getObjectManager()->get(GetSourceItemId::class); - + $this->getSourceItemIds = Bootstrap::getObjectManager()->get(GetSourceItemIds::class); + $this->sourceItemRepository = Bootstrap::getObjectManager()->get(SourceItemRepositoryInterface::class); + $this->searchCriteriaBuilder = Bootstrap::getObjectManager()->get(SearchCriteriaBuilder::class); $this->removeIndexData = Bootstrap::getObjectManager()->get(RemoveIndexData::class); $this->removeIndexData->execute([10, 20, 30]); } @@ -51,7 +66,7 @@ protected function setUp() */ protected function tearDown() { - $this->removeIndexData->execute([10, 20, 30]); +// $this->removeIndexData->execute([10, 20, 30]); } /** @@ -72,7 +87,11 @@ protected function tearDown() */ public function testReindexRow(string $sku, int $stockId, $expectedData) { - $this->sourceItemIndexer->executeRow($this->getSourceItemId->execute('SKU-1', 'eu-1')); + $sourceItem = $this->getSourceItem('SKU-1', 'eu-1'); + $sourceItemIds = $this->getSourceItemIds->execute([$sourceItem]); + foreach ($sourceItemIds as $sourceItemId) { + $this->sourceItemIndexer->executeRow((int)$sourceItemId); + } $stockItemData = $this->getStockItemData->execute($sku, $stockId); self::assertEquals($expectedData, $stockItemData); @@ -111,10 +130,13 @@ public function reindexRowDataProvider(): array */ public function testReindexList(string $sku, int $stockId, $expectedData) { - $this->sourceItemIndexer->executeList([ - $this->getSourceItemId->execute('SKU-1', 'eu-1'), - $this->getSourceItemId->execute('SKU-2', 'us-1'), - ]); + $sourceItemIds = $this->getSourceItemIds->execute( + [ + $this->getSourceItem('SKU-1', 'eu-1'), + $this->getSourceItem('SKU-2', 'us-1'), + ] + ); + $this->sourceItemIndexer->executeList($sourceItemIds); $stockItemData = $this->getStockItemData->execute($sku, $stockId); self::assertEquals($expectedData, $stockItemData); @@ -178,4 +200,19 @@ public function reindexAllDataProvider(): array ['SKU-3', 30, [GetStockItemDataInterface::QUANTITY => 0, GetStockItemDataInterface::IS_SALABLE => 0]], ]; } + + /** + * @param $sku + * @param $sourceCode + * @return SourceItemInterface + */ + private function getSourceItem($sku, $sourceCode): SourceItemInterface + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(SourceItemInterface::SKU, $sku) + ->addFilter(SourceItemInterface::SOURCE_CODE, $sourceCode) + ->create(); + $sourceItems = $this->sourceItemRepository->getList($searchCriteria)->getItems(); + return reset($sourceItems); + } } From e6587be4fc8958a3d571440a7da3315bc9cd0849 Mon Sep 17 00:00:00 2001 From: serhii balko Date: Wed, 28 Mar 2018 11:20:05 +0300 Subject: [PATCH 4/5] MSI-757: Add Inventory Index invalidation when Source is enabled or disabled. --- .../InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php | 1 + .../Test/Integration/Indexer/SourceItemIndexerTest.php | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php index 4b7fa8e92fd63..bbf7a2f9be237 100644 --- a/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php +++ b/app/code/Magento/InventoryIndexer/Plugin/InventoryApi/ReindexAroundStockSourceLinksSavePlugin.php @@ -45,6 +45,7 @@ public function __construct( * @param StockSourceLinksSaveInterface $subject * @param callable $proceed * @param array $links + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function aroundExecute( StockSourceLinksSaveInterface $subject, diff --git a/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php b/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php index d5219275df69e..c187b62fade85 100644 --- a/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php +++ b/app/code/Magento/InventoryIndexer/Test/Integration/Indexer/SourceItemIndexerTest.php @@ -49,7 +49,6 @@ class SourceItemIndexerTest extends TestCase */ private $searchCriteriaBuilder; - protected function setUp() { $this->sourceItemIndexer = Bootstrap::getObjectManager()->get(SourceItemIndexer::class); From cb2d48e5accb197f6ce8474264133054c2ab8bb0 Mon Sep 17 00:00:00 2001 From: Valeriy Nayda Date: Wed, 28 Mar 2018 12:47:21 +0300 Subject: [PATCH 5/5] MSI-698: Adapt MSI to use Default Stock --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index 4cca9648e37e7..f55b8b5a62184 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "dd662441a7ea777644f30a687dccdf5a", + "content-hash": "f1b9e466df6fe6a95d02d747cd2ba4f1", "packages": [ { "name": "braintree/braintree_php",