From 0e550b01d2fe540e72952c3d73e30fda0eec892f Mon Sep 17 00:00:00 2001 From: "Strafella.Gianluca" Date: Tue, 13 Jul 2021 09:54:47 +0200 Subject: [PATCH 01/12] - Disable observer `deduct_source_item_quantity_on_refund` that deducts stock from credit memo save - Add a custom observer, to return stock on order credit memo creation, when flag "Back in stock" is ON, in credit memo creation. --- ...toreSourceItemQuantityOnRefundObserver.php | 255 ++++++++++++++++++ src/etc/events.xml | 8 + 2 files changed, 263 insertions(+) create mode 100644 src/Observer/RestoreSourceItemQuantityOnRefundObserver.php diff --git a/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php new file mode 100644 index 0000000..22fa63c --- /dev/null +++ b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php @@ -0,0 +1,255 @@ +getSkuFromOrderItem = $getSkuFromOrderItem; + + + $this->isSourceItemManagementAllowedForProductType = $isSourceItemManagementAllowedForProductType; + $this->getProductTypesBySkus = $getProductTypesBySkus; + $this->orderRepository = $orderRepository; + $this->defaultSourceProvider = $defaultSourceProvider; + $this->getSourcesAssignedToStockOrderedByPriority = $getSourcesAssignedToStockOrderedByPriority; + $this->stockByWebsiteIdResolver = $stockByWebsiteIdResolver; + + $this->sourceDeductionRequestFactory = $sourceDeductionRequestFactory; + $this->salesEventExtensionFactory = $salesEventExtensionFactory; + $this->getSalesChannelForOrder = $getSalesChannelForOrder; + $this->sourceDeductionService = $sourceDeductionService; + $this->getSourceItemsBySku = $getSourceItemsBySku; + $this->salesEventFactory = $salesEventFactory; + $this->itemToDeductFactory = $itemToDeductFactory; + } + + + public function execute(Observer $observer) + { + /* @var $creditMemo \Magento\Sales\Model\Order\Creditmemo */ + $creditMemo = $observer->getEvent()->getCreditmemo(); + $order = $this->orderRepository->get($creditMemo->getOrderId()); + $websiteId = (int)$order->getStore()->getWebsiteId(); + $salesChannel = $this->getSalesChannelForOrder->execute($order); + + $items = $returnToStockItems = []; + foreach ($creditMemo->getItems() as $item) { + $orderItem = $item->getOrderItem(); + $itemSku = $this->getSkuFromOrderItem->execute($orderItem); + + if ($this->isValidItem($itemSku, $orderItem->getProductType()) && $item->getBackToStock()) { + $returnToStockItems[] = $item->getOrderItemId(); + $qty = $item->getQty(); + $stockId = (int)$this->stockByWebsiteIdResolver->execute($websiteId)->getStockId(); + $sourceCode = $this->getSourceCodeWithHighestPriorityBySku((string)$itemSku, $stockId); + $items[$sourceCode][] = $this->itemToDeductFactory->create([ + 'sku' => $itemSku, + 'qty' => -$qty + ]); + } + } + + /** @var SalesEventExtensionInterface */ + $salesEventExtension = $this->salesEventExtensionFactory->create([ + 'data' => ['objectIncrementId' => (string)$order->getIncrementId()] + ]); + /** @var SalesEventInterface $salesEvent */ + $salesEvent = $this->salesEventFactory->create([ + 'type' => SalesEventInterface::EVENT_CREDITMEMO_CREATED, + 'objectType' => SalesEventInterface::OBJECT_TYPE_ORDER, + 'objectId' => (string)$order->getEntityId() + ]); + $salesEvent->setExtensionAttributes($salesEventExtension); + + foreach ($items as $sourceCode => $items) { + $sourceDeductionRequest = $this->sourceDeductionRequestFactory->create([ + 'sourceCode' => $sourceCode, + 'items' => $items, + 'salesChannel' => $salesChannel, + 'salesEvent' => $salesEvent + ]); + $this->sourceDeductionService->execute($sourceDeductionRequest); + } + } + + /** + * Verify is item valid for return qty to stock. + * + * @param string $sku + * @param string|null $typeId + * + * @return bool + */ + private function isValidItem(string $sku, ?string $typeId): bool + { + // https://github.com/magento-engcom/msi/issues/1761 + // If product type located in table sales_order_item is "grouped" replace it with "simple" + if ($typeId === 'grouped') { + $typeId = 'simple'; + } + + $productType = $typeId ?: $this->getProductTypesBySkus->execute( + [$sku] + )[$sku]; + + return $this->isSourceItemManagementAllowedForProductType->execute($productType); + } + + /** + * Returns source code with highest priority by sku + * + * @param string $sku + * @param int $stockId + * + * @return string + */ + private function getSourceCodeWithHighestPriorityBySku(string $sku, int $stockId): string + { + $sourceCode = $this->defaultSourceProvider->getCode(); + try { + $availableSourcesForProduct = $this->getSourceItemsBySku->execute($sku); + $assignedSourcesToStock = $this->getSourcesAssignedToStockOrderedByPriority->execute($stockId); + foreach ($assignedSourcesToStock as $assignedSource) { + foreach ($availableSourcesForProduct as $availableSource) { + if ($assignedSource->getSourceCode() == $availableSource->getSourceCode()) { + $sourceCode = $assignedSource->getSourceCode(); + break 2; + } + } + } + } catch (LocalizedException $e) { + //Use Default Source if the source can't be resolved + return $sourceCode; + } + + return $sourceCode; + } +} diff --git a/src/etc/events.xml b/src/etc/events.xml index fdfa59f..cf16d62 100644 --- a/src/etc/events.xml +++ b/src/etc/events.xml @@ -4,6 +4,14 @@ + + + + + + + + From ff7d89fef41a361438a3ef8883e0090f35b60b70 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 13:13:24 +0100 Subject: [PATCH 02/12] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index acabf2a..1d108c5 100644 --- a/README.md +++ b/README.md @@ -24,3 +24,4 @@ This module will: * Make sure to truncate any existing reservations after installing this module, see https://github.com/AmpersandHQ/magento2-disable-stock-reservation/issues/41 * Both the `inventory` and `cataloginventory_stock` should be on the same mode (`Update on Save` or `Schedule`) for this module to work as expected. If you are running this on `Schedule` you should have crons activated. + From 9e4fdd0573ac9923200b943a94d3b976ab1535c2 Mon Sep 17 00:00:00 2001 From: Omokwale Sharon Date: Tue, 4 Oct 2022 13:59:29 +0100 Subject: [PATCH 03/12] Debug 2.3 and 2.4 cross compatability workaround --- .../GetSalesChannelForOrder.php | 59 +++++++++++++++++++ ...toreSourceItemQuantityOnRefundObserver.php | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 src/Model/ReturnProcessor/GetSalesChannelForOrder.php diff --git a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php new file mode 100644 index 0000000..fd162e9 --- /dev/null +++ b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php @@ -0,0 +1,59 @@ +websiteRepository = $websiteRepository; + $this->salesChannelFactory = $salesChannelFactory; + } + + /** + * Return sales channel for order + * + * @param OrderInterface $order + * @return SalesChannelInterface + */ + public function execute(OrderInterface $order): SalesChannelInterface + { + $websiteId = (int)$order->getStore()->getWebsiteId(); + $websiteCode = $this->websiteRepository->getById($websiteId)->getCode(); + + return $this->salesChannelFactory->create([ + 'data' => [ + 'type' => SalesChannelInterface::TYPE_WEBSITE, + 'code' => $websiteCode + ] + ]); + } +} + + diff --git a/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php index 22fa63c..ce1b847 100644 --- a/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php +++ b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php @@ -2,6 +2,7 @@ namespace Ampersand\DisableStockReservation\Observer; +use Ampersand\DisableStockReservation\Model\ReturnProcessor\GetSalesChannelForOrder; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Exception\LocalizedException; @@ -10,7 +11,6 @@ use Magento\InventoryCatalogApi\Api\DefaultSourceProviderInterface; use Magento\InventoryCatalogApi\Model\GetProductTypesBySkusInterface; use Magento\InventoryConfigurationApi\Model\IsSourceItemManagementAllowedForProductTypeInterface; -use Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder; use Magento\InventorySalesApi\Api\Data\SalesEventExtensionFactory; use Magento\InventorySalesApi\Api\Data\SalesEventExtensionInterface; use Magento\InventorySalesApi\Api\Data\SalesEventInterface; From 80e8ecf8b9251d7878cba01f920aab891c7d6d24 Mon Sep 17 00:00:00 2001 From: Omokwale Sharon Date: Tue, 4 Oct 2022 14:00:43 +0100 Subject: [PATCH 04/12] Fix code styling --- src/Model/ReturnProcessor/GetSalesChannelForOrder.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php index fd162e9..b71e05a 100644 --- a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php +++ b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php @@ -55,5 +55,3 @@ public function execute(OrderInterface $order): SalesChannelInterface ]); } } - - From aaf71c010f0a0728be83f4738243ab339ba3f8d3 Mon Sep 17 00:00:00 2001 From: Omokwale Sharon Date: Tue, 4 Oct 2022 14:07:00 +0100 Subject: [PATCH 05/12] fix code styling --- src/Model/ReturnProcessor/GetSalesChannelForOrder.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php index b71e05a..9a94f4a 100644 --- a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php +++ b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php @@ -8,7 +8,9 @@ use Magento\Store\Api\WebsiteRepositoryInterface; if (\class_exists(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class)) { - class GetSalesChannelForOrder extends \Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder {} + class GetSalesChannelForOrder extends \Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder + { + } return; } From a3424f8327742478276858a55a8ef857f196121c Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 15:13:43 +0100 Subject: [PATCH 06/12] Use objectmanager for 2.3/2.4 compat workaround --- .../GetSalesChannelForOrder.php | 7 ----- ...toreSourceItemQuantityOnRefundObserver.php | 27 ++++++++++++++++++- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php index 9a94f4a..f2b64a3 100644 --- a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php +++ b/src/Model/ReturnProcessor/GetSalesChannelForOrder.php @@ -7,13 +7,6 @@ use Magento\Sales\Api\Data\OrderInterface; use Magento\Store\Api\WebsiteRepositoryInterface; -if (\class_exists(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class)) { - class GetSalesChannelForOrder extends \Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder - { - } - return; -} - class GetSalesChannelForOrder { /** diff --git a/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php index ce1b847..514e161 100644 --- a/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php +++ b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php @@ -144,7 +144,7 @@ public function __construct( $this->sourceDeductionRequestFactory = $sourceDeductionRequestFactory; $this->salesEventExtensionFactory = $salesEventExtensionFactory; - $this->getSalesChannelForOrder = $getSalesChannelForOrder; + $this->getSalesChannelForOrder = $this->setGetSalesChannelForOrder($getSalesChannelForOrder); $this->sourceDeductionService = $sourceDeductionService; $this->getSourceItemsBySku = $getSourceItemsBySku; $this->salesEventFactory = $salesEventFactory; @@ -252,4 +252,29 @@ private function getSourceCodeWithHighestPriorityBySku(string $sku, int $stockId return $sourceCode; } + + /** + * A 2.3 and 2.4 compatability workaround + * + * If we are on a 2.3 instance this will use Model\ReturnProcessor\GetSalesChannelForOrder which is a copy of the + * file which is available in magento 2.4 + * + * If we are on a 2.4 instance, just use that file in any case. + * + * This is to provide a little more support for 2.3, it is only just EOL and there will still be projects existing + * on it for some time. + * + * @param GetSalesChannelForOrder $getSalesChannelForOrder + * @return GetSalesChannelForOrder|\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder + */ + private function setGetSalesChannelForOrder(GetSalesChannelForOrder $getSalesChannelForOrder) + { + // phpcs:disable + if (\class_exists(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class)) { + $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); + return $objectManager->get(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class); + } + // phpcs:enable + return $getSalesChannelForOrder; + } } From 8a6a19cc53801d7eabe80f23e49f2a44167e7839 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 15:42:35 +0100 Subject: [PATCH 07/12] Use a factory to 2.3/2.4 compat --- ...toreSourceItemQuantityOnRefundObserver.php | 37 +++-------------- .../GetSalesChannelForOrder.php | 2 +- .../GetSalesChannelForOrderFactory.php | 40 +++++++++++++++++++ 3 files changed, 47 insertions(+), 32 deletions(-) rename src/{Model => }/ReturnProcessor/GetSalesChannelForOrder.php (95%) create mode 100644 src/ReturnProcessor/GetSalesChannelForOrderFactory.php diff --git a/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php index 514e161..c0affe9 100644 --- a/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php +++ b/src/Observer/RestoreSourceItemQuantityOnRefundObserver.php @@ -2,7 +2,8 @@ namespace Ampersand\DisableStockReservation\Observer; -use Ampersand\DisableStockReservation\Model\ReturnProcessor\GetSalesChannelForOrder; +use Ampersand\DisableStockReservation\ReturnProcessor\GetSalesChannelForOrder; +use Ampersand\DisableStockReservation\ReturnProcessor\GetSalesChannelForOrderFactory; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; use Magento\Framework\Exception\LocalizedException; @@ -72,11 +73,10 @@ class RestoreSourceItemQuantityOnRefundObserver implements ObserverInterface private $salesEventExtensionFactory; /** - * @var GetSalesChannelForOrder + * @var GetSalesChannelForOrder|\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder */ private $getSalesChannelForOrder; - /** * @var SourceDeductionService */ @@ -110,7 +110,7 @@ class RestoreSourceItemQuantityOnRefundObserver implements ObserverInterface * @param StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver * @param SourceDeductionRequestFactory $sourceDeductionRequestFactory * @param SalesEventExtensionFactory $salesEventExtensionFactory - * @param GetSalesChannelForOrder $getSalesChannelForOrder + * @param GetSalesChannelForOrderFactory $getSalesChannelForOrderFactory * @param SourceDeductionService $sourceDeductionService * @param GetSourceItemsBySkuInterface $getSourceItemsBySku * @param SalesEventInterfaceFactory $salesEventFactory @@ -126,7 +126,7 @@ public function __construct( StockByWebsiteIdResolverInterface $stockByWebsiteIdResolver, SourceDeductionRequestFactory $sourceDeductionRequestFactory, SalesEventExtensionFactory $salesEventExtensionFactory, - GetSalesChannelForOrder $getSalesChannelForOrder, + GetSalesChannelForOrderFactory $getSalesChannelForOrderFactory, SourceDeductionService $sourceDeductionService, GetSourceItemsBySkuInterface $getSourceItemsBySku, SalesEventInterfaceFactory $salesEventFactory, @@ -144,7 +144,7 @@ public function __construct( $this->sourceDeductionRequestFactory = $sourceDeductionRequestFactory; $this->salesEventExtensionFactory = $salesEventExtensionFactory; - $this->getSalesChannelForOrder = $this->setGetSalesChannelForOrder($getSalesChannelForOrder); + $this->getSalesChannelForOrder = $getSalesChannelForOrderFactory->create(); $this->sourceDeductionService = $sourceDeductionService; $this->getSourceItemsBySku = $getSourceItemsBySku; $this->salesEventFactory = $salesEventFactory; @@ -252,29 +252,4 @@ private function getSourceCodeWithHighestPriorityBySku(string $sku, int $stockId return $sourceCode; } - - /** - * A 2.3 and 2.4 compatability workaround - * - * If we are on a 2.3 instance this will use Model\ReturnProcessor\GetSalesChannelForOrder which is a copy of the - * file which is available in magento 2.4 - * - * If we are on a 2.4 instance, just use that file in any case. - * - * This is to provide a little more support for 2.3, it is only just EOL and there will still be projects existing - * on it for some time. - * - * @param GetSalesChannelForOrder $getSalesChannelForOrder - * @return GetSalesChannelForOrder|\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder - */ - private function setGetSalesChannelForOrder(GetSalesChannelForOrder $getSalesChannelForOrder) - { - // phpcs:disable - if (\class_exists(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class)) { - $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); - return $objectManager->get(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class); - } - // phpcs:enable - return $getSalesChannelForOrder; - } } diff --git a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php b/src/ReturnProcessor/GetSalesChannelForOrder.php similarity index 95% rename from src/Model/ReturnProcessor/GetSalesChannelForOrder.php rename to src/ReturnProcessor/GetSalesChannelForOrder.php index f2b64a3..8f0b008 100644 --- a/src/Model/ReturnProcessor/GetSalesChannelForOrder.php +++ b/src/ReturnProcessor/GetSalesChannelForOrder.php @@ -1,6 +1,6 @@ objectManager = $objectManager; + } + + /** + * For magento 2.4 return the core provided class + * For magento 2.3 return the workaround copy of that class + * + * @return GetSalesChannelForOrder|\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder|mixed + */ + public function create() + { + if (\class_exists(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class)) { + return $this->objectManager->create( + \Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class + ); + } + return $this->objectManager->create( + GetSalesChannelForOrder::class + ); + } +} \ No newline at end of file From da56c58251c6cb3735712b71d80836f7fffc2ba8 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 15:43:58 +0100 Subject: [PATCH 08/12] fix code style --- src/ReturnProcessor/GetSalesChannelForOrderFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ReturnProcessor/GetSalesChannelForOrderFactory.php b/src/ReturnProcessor/GetSalesChannelForOrderFactory.php index 4b87ae5..eec3ffd 100644 --- a/src/ReturnProcessor/GetSalesChannelForOrderFactory.php +++ b/src/ReturnProcessor/GetSalesChannelForOrderFactory.php @@ -37,4 +37,4 @@ public function create() GetSalesChannelForOrder::class ); } -} \ No newline at end of file +} From 83c3ec1a5c1a3bebb01ecd09f07d1cc1e9b99b84 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 15:45:32 +0100 Subject: [PATCH 09/12] Undo readme.md change --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 938acd3..5eee73c 100644 --- a/README.md +++ b/README.md @@ -24,4 +24,3 @@ This module will: * Make sure to truncate any existing reservations after installing this module, see https://github.com/AmpersandHQ/magento2-disable-stock-reservation/issues/41 * Both the `inventory` and `cataloginventory_stock` should be on the same mode (`Update on Save` or `Schedule`) for this module to work as expected. If you are running this on `Schedule` you should have crons activated. - From 6c78c9889177d2ffc4f886723263fb3815c6a2e0 Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 15:50:29 +0100 Subject: [PATCH 10/12] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 5eee73c..bf201e9 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,9 @@ This module will: * Trigger stock deductions on order placement. See `inventory_sales_source_deduction_processor` plugin on `Magento\Sales\Model\Service\OrderService`. * Prevent stock deductions on order shipment. See disabled `inventory_sales_source_deduction_processor` observer on `sales_order_shipment_save_after` event. * Replenish stock for cancelled order items. See `inventory` observer on `sales_order_item_cancel` event. +* Replenish stock when a credit memo is issued. See `src/Observer/RestoreSourceItemQuantityOnRefundObserver.php` + * Requires that "Back to stock" is checked or "Automatically Return Credit Memo Item to Stock" is configured + * https://docs.magento.com/user-guide/configuration/catalog/inventory.html#product-stock-options ## Additional Notes From 7ad07450aef69cb6bdb59bf9c912793fd501260b Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 15:52:46 +0100 Subject: [PATCH 11/12] Fix travis badge url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index bf201e9..36a6bff 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # AmpersandHQ/magento2-disable-stock-reservation -[![Build Status](https://travis-ci.com/AmpersandHQ/magento2-disable-stock-reservation.svg?branch=master)](https://travis-ci.com/AmpersandHQ/magento2-disable-stock-reservation) +[![Build Status](https://app.travis-ci.com/AmpersandHQ/magento2-disable-stock-reservation.svg?branch=master)](https://app.travis-ci.com/AmpersandHQ/magento2-disable-stock-reservation) This module disables the inventory reservation logic introduced as part of MSI in Magento 2.3.3 - see https://github.com/magento/inventory/issues/2269 for more information about the way MSI was implemented, and the issues From 58d463317c57d7c74cd447abfe07282ad581705f Mon Sep 17 00:00:00 2001 From: Luke Rodgers Date: Tue, 4 Oct 2022 16:40:56 +0100 Subject: [PATCH 12/12] Fix comment and imports --- .../GetSalesChannelForOrderFactory.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/ReturnProcessor/GetSalesChannelForOrderFactory.php b/src/ReturnProcessor/GetSalesChannelForOrderFactory.php index eec3ffd..318efd5 100644 --- a/src/ReturnProcessor/GetSalesChannelForOrderFactory.php +++ b/src/ReturnProcessor/GetSalesChannelForOrderFactory.php @@ -3,6 +3,7 @@ namespace Ampersand\DisableStockReservation\ReturnProcessor; use Magento\Framework\ObjectManagerInterface; +use Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder as GetSalesChannelForOrder24; class GetSalesChannelForOrderFactory { @@ -12,7 +13,7 @@ class GetSalesChannelForOrderFactory private $objectManager; /** - * ResponseFactory constructor. + * constructor. */ public function __construct( ObjectManagerInterface $objectManager @@ -24,14 +25,12 @@ public function __construct( * For magento 2.4 return the core provided class * For magento 2.3 return the workaround copy of that class * - * @return GetSalesChannelForOrder|\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder|mixed + * @return GetSalesChannelForOrder|GetSalesChannelForOrder24|mixed */ public function create() { - if (\class_exists(\Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class)) { - return $this->objectManager->create( - \Magento\InventorySales\Model\ReturnProcessor\GetSalesChannelForOrder::class - ); + if (\class_exists(GetSalesChannelForOrder24::class)) { + return $this->objectManager->create(GetSalesChannelForOrder24::class); } return $this->objectManager->create( GetSalesChannelForOrder::class