-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Source Delivery awareness to Order page #315
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ac33fcf
Add Source Delivery awareness to Order page
f624e51
code review changes
ceab796
Added shipping algorithm interfaces
VitaliyBoyko b7813a8
Merge branches '309-add-source-to-order-page' and 'develop' of https:…
VitaliyBoyko e64e73c
Fixed static checks
VitaliyBoyko 73ff71c
Fixed static test dependency issue
VitaliyBoyko ff04725
Fixed static checks
VitaliyBoyko 4359bc6
MSI: Add Source Delivery awareness to Order page #309
e34ab71
Merge remote-tracking branch 'origin/develop' into 309-add-source-to-…
a4e374a
MSI: Add Source Delivery awareness to Order page #309
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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; ?> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls add also strict type declare(strict_types=1);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed