Skip to content

Commit

Permalink
#518 Added the message if order items can’t be delivered by the curre…
Browse files Browse the repository at this point in the history
…nt algo
  • Loading branch information
Roman Glushko committed Feb 17, 2018
1 parent 74a08e4 commit adfa7f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -22,6 +23,11 @@
*/
class SourceSelection extends Template implements TabInterface
{
/**
* @var ShippingAlgorithmResultInterface
*/
private $shippingAlgorithmResult;

/**
* @var Registry
*/
Expand Down Expand Up @@ -57,16 +63,24 @@ 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
*
* @return SourceSelectionInterface[]
*/
public function getSourceSelections(): array
{
$order = $this->registry->registry('current_order');
$shippingAlgorithm = $this->shippingAlgorithmProvider->execute();
return $shippingAlgorithm->execute($order)->getSourceSelections();
return $this->getShippingAlgorithmResult()->getSourceSelections();
}

/**
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
?>
<?php foreach ($block->getSourceSelections() as $sourceSelection): ?>
<?php if (!$block->isShippable()) : ?>
<div><?php echo __('Order items could not be shipped by the current shipping algorithm.'); ?></div>
<?php endif; ?>
<?php foreach ($block->getSourceSelections() as $sourceSelection) : ?>
<table class="data-table admin__table-primary edit-order-table">
<div class="admin__page-section-item-title">
<span class="title"><?= $block->escapeHtml($this->getSourceName($sourceSelection->getSourceCode())) ?></span>
Expand All @@ -20,7 +23,7 @@
<th><span><?= $block->escapeHtml(__('Qty to Deduct')) ?></span></th>
</tr>
</thead>
<?php foreach ($sourceSelection->getSourceItemSelections() as $itemSelection): ?>
<?php foreach ($sourceSelection->getSourceItemSelections() as $itemSelection) : ?>
<tr>
<td><?= $block->escapeHtml($itemSelection->getSku()) ?></td>
<td><?= $block->escapeHtml($itemSelection->getQtyAvailable()) ?></td>
Expand Down

0 comments on commit adfa7f7

Please sign in to comment.