diff --git a/Inventory/Model/SourceRepository.php b/Inventory/Model/SourceRepository.php
index e6c3e6d42a68..050f6034d3ba 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;
+ }
}
diff --git a/InventoryAdminUi/Controller/Adminhtml/Source/MassDelete b/InventoryAdminUi/Controller/Adminhtml/Source/MassDelete
new file mode 100644
index 000000000000..aba59f8c7d68
--- /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));
+ }
+}
diff --git a/InventoryAdminUi/view/adminhtml/ui_component/inventory_source_listing.xml b/InventoryAdminUi/view/adminhtml/ui_component/inventory_source_listing.xml
index e5df8b68d7c7..4e1dfcced8c5 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
+
+
+
diff --git a/InventoryApi/Api/SourceRepositoryInterface.php b/InventoryApi/Api/SourceRepositoryInterface.php
index bd56b7094659..83171df843a2 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 Source Code. 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;
}