-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #315 from magento-engcom/309-add-source-to-order-page
Add Source Delivery awareness to Order page
- Loading branch information
Showing
3 changed files
with
185 additions
and
0 deletions.
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
app/code/Magento/InventorySales/Block/Adminhtml/Order/View/Tab/Sources.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventorySales\Block\Adminhtml\Order\View\Tab; | ||
|
||
use Magento\Backend\Block\Template; | ||
use Magento\Backend\Block\Template\Context; | ||
use Magento\Backend\Block\Widget\Tab\TabInterface; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\Framework\Registry; | ||
use Magento\InventoryApi\Api\Data\SourceItemInterface; | ||
use Magento\InventoryApi\Api\SourceItemRepositoryInterface; | ||
use Magento\InventoryApi\Api\SourceRepositoryInterface; | ||
|
||
/** | ||
* Tab for source items display on the order editing page | ||
* | ||
* @api | ||
*/ | ||
class Sources extends Template implements TabInterface | ||
{ | ||
/** | ||
* @var Registry | ||
*/ | ||
private $registry; | ||
|
||
/** | ||
* @var SearchCriteriaBuilder | ||
*/ | ||
private $searchCriteriaBuilder; | ||
|
||
/** | ||
* @var SourceItemRepositoryInterface | ||
*/ | ||
private $sourceItemRepository; | ||
|
||
/** | ||
* @var SourceRepositoryInterface | ||
*/ | ||
private $sourceRepository; | ||
|
||
/** | ||
* @param Context $context | ||
* @param Registry $registry | ||
* @param SearchCriteriaBuilder $searchCriteriaBuilder | ||
* @param SourceItemRepositoryInterface $sourceItemRepository | ||
* @param SourceRepositoryInterface $sourceRepository | ||
* @param array $data | ||
*/ | ||
public function __construct( | ||
Context $context, | ||
Registry $registry, | ||
SearchCriteriaBuilder $searchCriteriaBuilder, | ||
SourceItemRepositoryInterface $sourceItemRepository, | ||
SourceRepositoryInterface $sourceRepository, | ||
array $data = [] | ||
) { | ||
parent::__construct($context, $data); | ||
$this->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; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
app/code/Magento/InventorySales/view/adminhtml/layout/sales_order_view.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="sales_order_tabs"> | ||
<block class="Magento\InventorySales\Block\Adminhtml\Order\View\Tab\Sources" name="order_tab_sources" template="Magento_InventorySales::order/view/tab/sources.phtml"/> | ||
<action method="addTab"> | ||
<argument name="name" xsi:type="string">order_sources</argument> | ||
<argument name="block" xsi:type="string">order_tab_sources</argument> | ||
</action> | ||
</referenceBlock> | ||
</body> | ||
</page> |
29 changes: 29 additions & 0 deletions
29
app/code/Magento/InventorySales/view/adminhtml/templates/order/view/tab/sources.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
// @codingStandardsIgnoreFile | ||
|
||
/** @var \Magento\InventorySales\Block\Adminhtml\Order\View\Tab\Sources $block */ | ||
?> | ||
<?php foreach ($block->getSourceItemsData() as $sourceName => $sourceItems): ?> | ||
<table class="data-table admin__table-primary edit-order-table"> | ||
<div class="admin__page-section-item-title"> | ||
<span class="title"><?= $block->escapeHtml($sourceName) ?></span> | ||
</div> | ||
<thead> | ||
<tr class="headings"> | ||
<th><span><?= $block->escapeHtml(__('Sku')) ?></span></th> | ||
<th><span><?= $block->escapeHtml(__('Qty')) ?></span></th> | ||
</tr> | ||
</thead> | ||
<?php foreach ($sourceItems as $sourceItem): ?> | ||
<tr> | ||
<td><?= $block->escapeHtml($sourceItem['sku']) ?></td> | ||
<td><?= $block->escapeHtml($sourceItem['qty']) ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</table> | ||
<?php endforeach; ?> |