From ce503e847ace083d274b82e2d1993fa0733e80c3 Mon Sep 17 00:00:00 2001 From: Waleed Date: Tue, 18 Apr 2023 09:47:30 +0200 Subject: [PATCH] Adds Plugin to ensure shipment can be sent with qty is 0, solves issue #69 and #108 --- ...nStockSourceItemsBySkusAndSortedSource.php | 60 +++++++++++++++++++ .../Model/Order/IsFulfillablePlugin.php | 11 ++++ .../SourceSelectionDataProviderPlugin.php | 19 ++++++ src/etc/di.xml | 14 +++++ 4 files changed, 104 insertions(+) create mode 100644 src/Model/InventoryApi/GetInStockSourceItemsBySkusAndSortedSource.php create mode 100644 src/Plugin/InventoryInStorePickupSales/Model/Order/IsFulfillablePlugin.php create mode 100644 src/Plugin/InventoryShippingAdminUi/Ui/DataProvider/SourceSelectionDataProviderPlugin.php diff --git a/src/Model/InventoryApi/GetInStockSourceItemsBySkusAndSortedSource.php b/src/Model/InventoryApi/GetInStockSourceItemsBySkusAndSortedSource.php new file mode 100644 index 0000000..b309d15 --- /dev/null +++ b/src/Model/InventoryApi/GetInStockSourceItemsBySkusAndSortedSource.php @@ -0,0 +1,60 @@ +sourceItemRepository = $sourceItemRepository; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + } + + /** + * Retrieve source items for a defined set of SKUs and sorted source codes + * + * @param array $skus + * @param array $sortedSourceCodes + * @return SourceItemInterface[] + */ + public function execute(array $skus, array $sortedSourceCodes): array + { + $skus = array_map('strval', $skus); + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(SourceItemInterface::SKU, $skus, 'in') + ->addFilter(SourceItemInterface::SOURCE_CODE, $sortedSourceCodes, 'in') + //->addFilter(SourceItemInterface::STATUS, SourceItemInterface::STATUS_IN_STOCK) + ->create(); + + $items = $this->sourceItemRepository->getList($searchCriteria)->getItems(); + + $itemsSorting = []; + foreach ($items as $item) { + $itemsSorting[] = array_search($item->getSourceCode(), $sortedSourceCodes, true); + } + + array_multisort($itemsSorting, SORT_NUMERIC, SORT_ASC, $items); + return $items; + } +} \ No newline at end of file diff --git a/src/Plugin/InventoryInStorePickupSales/Model/Order/IsFulfillablePlugin.php b/src/Plugin/InventoryInStorePickupSales/Model/Order/IsFulfillablePlugin.php new file mode 100644 index 0000000..2349003 --- /dev/null +++ b/src/Plugin/InventoryInStorePickupSales/Model/Order/IsFulfillablePlugin.php @@ -0,0 +1,11 @@ + + + + + + + + + + + + +