From 550ab531f9e3864463682bffedc5bfd304e8c02e Mon Sep 17 00:00:00 2001 From: Ejaz Alam Date: Fri, 26 Jul 2024 10:41:34 +0100 Subject: [PATCH 1/5] add the mass action to delete the source --- .../ui_component/inventory_source_listing.xml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/InventoryAdminUi/view/adminhtml/ui_component/inventory_source_listing.xml b/InventoryAdminUi/view/adminhtml/ui_component/inventory_source_listing.xml index e5df8b68d7c..4e1dfcced8c 100644 --- a/InventoryAdminUi/view/adminhtml/ui_component/inventory_source_listing.xml +++ b/InventoryAdminUi/view/adminhtml/ui_component/inventory_source_listing.xml @@ -82,6 +82,17 @@ + + + + Are you sure you want to delete selected source? + Delete items + + + delete + + + From 070d59661f80727c35e6716c37c76699b2f8637c Mon Sep 17 00:00:00 2001 From: Ejaz Alam Date: Fri, 26 Jul 2024 11:56:26 +0100 Subject: [PATCH 2/5] add an interface function to delet source by source code --- InventoryApi/Api/SourceRepositoryInterface.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/InventoryApi/Api/SourceRepositoryInterface.php b/InventoryApi/Api/SourceRepositoryInterface.php index bd56b709465..b55c5a394b9 100644 --- a/InventoryApi/Api/SourceRepositoryInterface.php +++ b/InventoryApi/Api/SourceRepositoryInterface.php @@ -58,4 +58,14 @@ public function get(string $sourceCode): \Magento\InventoryApi\Api\Data\SourceIn public function getList( \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null ): \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; + + /** + * Delete the Source by sourceId. If Source is not found do nothing + * + * @param SourceInterface $sourceCode + * @return bool + * @throws \Magento\Framework\Exception\NoSuchEntityException + * @throws \Magento\Framework\Exception\CouldNotDeleteException + */ + public function deleteBySourceCode(SourceInterface $source): bool; } From 10fb5ae9d6d907d4a017a4dcf4a8c621f657e941 Mon Sep 17 00:00:00 2001 From: Ejaz Alam Date: Fri, 26 Jul 2024 11:58:13 +0100 Subject: [PATCH 3/5] add concrete method for delete source by source code --- Inventory/Model/SourceRepository.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Inventory/Model/SourceRepository.php b/Inventory/Model/SourceRepository.php index e6c3e6d42a6..050f6034d3b 100644 --- a/Inventory/Model/SourceRepository.php +++ b/Inventory/Model/SourceRepository.php @@ -73,4 +73,17 @@ public function getList(SearchCriteriaInterface $searchCriteria = null): SourceS { return $this->commandGetList->execute($searchCriteria); } + + /** + * @inheritdoc + */ + public function deleteBySourceCode(SourceInterface $source): bool + { + try { + $this->sourceResource->delete($source); + } catch (\Exception $exception) { + throw new CouldNotDeleteException(__($exception->getMessage())); + } + return true; + } } From 93c5b2bb533a38afdd6c841cfcfa4336dafd34ce Mon Sep 17 00:00:00 2001 From: Ejaz Alam Date: Fri, 26 Jul 2024 12:00:20 +0100 Subject: [PATCH 4/5] add massDelete to delete source --- .../Controller/Adminhtml/Source/MassDelete | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 InventoryAdminUi/Controller/Adminhtml/Source/MassDelete diff --git a/InventoryAdminUi/Controller/Adminhtml/Source/MassDelete b/InventoryAdminUi/Controller/Adminhtml/Source/MassDelete new file mode 100644 index 00000000000..aba59f8c7d6 --- /dev/null +++ b/InventoryAdminUi/Controller/Adminhtml/Source/MassDelete @@ -0,0 +1,115 @@ +massActionFilter = $massActionFilter; + $this->sourceCollectionFactory = $sourceCollectionFactory; + $this->sourceFactory = $sourceFactory; + $this->sourceRepository = $sourceRepository; + $this->defaultSourceProvider = $defaultSourceProvider; + $this->sourceItemsDelete = $sourceItemsDelete; + } + + + /** + * @throws NoSuchEntityException + * @throws CouldNotDeleteException + * @throws LocalizedException + */ + public function execute(): ResultInterface + { + $resultRedirect = $this->resultRedirectFactory->create(); + $resultRedirect->setPath('inventory/source/index'); + $request = $this->getRequest(); + if (!$request->isPost()) { + $this->messageManager->addErrorMessage(__('Wrong request.')); + return $resultRedirect; + } + $sourceCollection = $this->sourceCollectionFactory->create(); + $this->massActionFilter->getCollection($sourceCollection); + $this->deleteSources($sourceCollection); + + return $resultRedirect; + } + + + /** + * @throws NoSuchEntityException + * @throws CouldNotDeleteException + */ + public function deleteSources(Collection $sourceCollection): void + { + $size = $sourceCollection->getSize(); + foreach ($sourceCollection as $source) { + $this->sourceRepository->deleteBySourceCode($source); + } + $this->messageManager->addSuccessMessage(__('A total of %1 record(s) have been deleted.', $size)); + } +} From f0335c6d216f684bf4d0d41fba2f0b6c0607f7b1 Mon Sep 17 00:00:00 2001 From: Ejaz Alam Date: Fri, 26 Jul 2024 12:08:16 +0100 Subject: [PATCH 5/5] Update SourceRepositoryInterface.php --- InventoryApi/Api/SourceRepositoryInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InventoryApi/Api/SourceRepositoryInterface.php b/InventoryApi/Api/SourceRepositoryInterface.php index b55c5a394b9..83171df843a 100644 --- a/InventoryApi/Api/SourceRepositoryInterface.php +++ b/InventoryApi/Api/SourceRepositoryInterface.php @@ -60,7 +60,7 @@ public function getList( ): \Magento\InventoryApi\Api\Data\SourceSearchResultsInterface; /** - * Delete the Source by sourceId. If Source is not found do nothing + * Delete the Source by Source Code. If Source is not found do nothing * * @param SourceInterface $sourceCode * @return bool