From adfa7f782673789bc1b0dedb0f6210a00145aa38 Mon Sep 17 00:00:00 2001 From: Roman Glushko Date: Sat, 17 Feb 2018 16:28:42 +0200 Subject: [PATCH] =?UTF-8?q?#518=20Added=20the=20message=20if=20order=20ite?= =?UTF-8?q?ms=20can=E2=80=99t=20be=20delivered=20by=20the=20current=20algo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Order/View/Tab/SourceSelection.php | 35 +++++++++++++++++-- .../order/view/tab/source_selection.phtml | 9 +++-- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/InventoryShipping/Block/Adminhtml/Order/View/Tab/SourceSelection.php b/app/code/Magento/InventoryShipping/Block/Adminhtml/Order/View/Tab/SourceSelection.php index ae253a3a269f..24c41e0dccd5 100755 --- a/app/code/Magento/InventoryShipping/Block/Adminhtml/Order/View/Tab/SourceSelection.php +++ b/app/code/Magento/InventoryShipping/Block/Adminhtml/Order/View/Tab/SourceSelection.php @@ -13,6 +13,7 @@ use Magento\Framework\Registry; use Magento\InventoryApi\Api\SourceRepositoryInterface; use Magento\InventoryShipping\Model\ShippingAlgorithmProviderInterface; +use Magento\InventoryShipping\Model\ShippingAlgorithmResult\ShippingAlgorithmResultInterface; use Magento\InventoryShipping\Model\ShippingAlgorithmResult\SourceSelectionInterface; /** @@ -22,6 +23,11 @@ */ class SourceSelection extends Template implements TabInterface { + /** + * @var ShippingAlgorithmResultInterface + */ + private $shippingAlgorithmResult; + /** * @var Registry */ @@ -57,6 +63,16 @@ public function __construct( $this->sourceRepository = $sourceRepository; } + /** + * Check if order items can be shipped by the current shipping algorithm + * + * @return bool + */ + public function isShippable() + { + return $this->getShippingAlgorithmResult()->isShippable(); + } + /** * Get source selections for order * @@ -64,9 +80,7 @@ public function __construct( */ public function getSourceSelections(): array { - $order = $this->registry->registry('current_order'); - $shippingAlgorithm = $this->shippingAlgorithmProvider->execute(); - return $shippingAlgorithm->execute($order)->getSourceSelections(); + return $this->getShippingAlgorithmResult()->getSourceSelections(); } /** @@ -112,4 +126,19 @@ public function isHidden() { return false; } + + /** + * @return ShippingAlgorithmResultInterface + */ + private function getShippingAlgorithmResult() + { + if (null === $this->shippingAlgorithmResult) { + $order = $this->registry->registry('current_order'); + $shippingAlgorithm = $this->shippingAlgorithmProvider->execute(); + + $this->shippingAlgorithmResult = $shippingAlgorithm->execute($order); + } + + return $this->shippingAlgorithmResult; + } } diff --git a/app/code/Magento/InventoryShipping/view/adminhtml/templates/order/view/tab/source_selection.phtml b/app/code/Magento/InventoryShipping/view/adminhtml/templates/order/view/tab/source_selection.phtml index 3cdd787153b4..3c89cc385226 100644 --- a/app/code/Magento/InventoryShipping/view/adminhtml/templates/order/view/tab/source_selection.phtml +++ b/app/code/Magento/InventoryShipping/view/adminhtml/templates/order/view/tab/source_selection.phtml @@ -6,9 +6,12 @@ // @codingStandardsIgnoreFile -/** @var \Magento\InventoryShipping\Block\Adminhtml\Order\View\Tab\SourceSelection $block */ +/** @var Magento\InventoryShipping\Block\Adminhtml\Order\View\Tab\SourceSelection $block */ ?> -getSourceSelections() as $sourceSelection): ?> +isShippable()) : ?> +
+ +getSourceSelections() as $sourceSelection) : ?>
escapeHtml($this->getSourceName($sourceSelection->getSourceCode())) ?> @@ -20,7 +23,7 @@
- getSourceItemSelections() as $itemSelection): ?> + getSourceItemSelections() as $itemSelection) : ?>
escapeHtml(__('Qty to Deduct')) ?>
escapeHtml($itemSelection->getSku()) ?> escapeHtml($itemSelection->getQtyAvailable()) ?>