diff --git a/app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php b/app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php new file mode 100644 index 000000000000..2f2f922aaef0 --- /dev/null +++ b/app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php @@ -0,0 +1,138 @@ +registry = $registry; + $this->searchCriteriaBuilder = $searchCriteriaBuilder; + $this->sourceItemRepository = $sourceItemRepository; + $this->sourceRepository = $sourceRepository; + } + + /** + * Getting source items for order + * + * @return array + */ + public function getSourceItemsData() + { + $order = $this->registry->registry('current_order'); + + $sourceItemsData = []; + foreach ($order->getAllVisibleItems() as $orderItem) { + $sourceItems = $this->getSourceItemsBySku($orderItem->getSku()); + + foreach ($sourceItems as $sourceItem) { + $sourceName = $this->sourceRepository->get((int)$sourceItem->getSourceId())->getName(); + $sourceItemsData[$sourceName][] = [ + 'sku' => $sourceItem->getSku(), + 'qty' => $sourceItem->getQuantity(), + ]; + } + } + return $sourceItemsData; + } + + /** + * @param string $sku + * @return SourceItemInterface[] + */ + private function getSourceItemsBySku(string $sku): array + { + $searchCriteria = $this->searchCriteriaBuilder + ->addFilter(SourceItemInterface::SKU, $sku) + ->create(); + + $sourceItemSearchResult = $this->sourceItemRepository->getList($searchCriteria); + return $sourceItemSearchResult->getItems(); + } + + /** + * @inheritdoc + */ + public function getTabLabel() + { + return __('Source Delivery'); + } + + /** + * @inheritdoc + */ + public function getTabTitle() + { + return __('Source Delivery'); + } + + /** + * @inheritdoc + */ + public function canShowTab() + { + return true; + } + + /** + * @inheritdoc + */ + public function isHidden() + { + return false; + } +} diff --git a/app/code/Magento/InventorySales/view/adminhtml/layout/sales_order_view.xml b/app/code/Magento/InventorySales/view/adminhtml/layout/sales_order_view.xml new file mode 100644 index 000000000000..1ee6a762fe80 --- /dev/null +++ b/app/code/Magento/InventorySales/view/adminhtml/layout/sales_order_view.xml @@ -0,0 +1,18 @@ + + + + + + + + order_sources + order_tab_sources + + + + diff --git a/app/code/Magento/InventorySales/view/adminhtml/templates/order/view/tab/sources.phtml b/app/code/Magento/InventorySales/view/adminhtml/templates/order/view/tab/sources.phtml new file mode 100644 index 000000000000..5ab633e745b4 --- /dev/null +++ b/app/code/Magento/InventorySales/view/adminhtml/templates/order/view/tab/sources.phtml @@ -0,0 +1,29 @@ + +getSourceItemsData() as $sourceName => $sourceItems): ?> + +
+ escapeHtml($sourceName) ?> +
+ + + + + + + + + + + + +
escapeHtml(__('Sku')) ?>escapeHtml(__('Qty')) ?>
escapeHtml($sourceItem['sku']) ?>escapeHtml($sourceItem['qty']) ?>
+