3fcb9a31 by Vo Van Khoa

Merge

2 parents d7fee7b4 4b86bebf
.vscode
.history
/nbproject/private/
......
......@@ -32,11 +32,16 @@ class DefaultRenderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\Defa
parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data);
}
public function getErrorOutStock($productId) {
public function getErrorOutStock($item) {
$productId = $item->getProductId();
$_productStock = $this->_stockItemRepository->get($productId);
$qtySelected = intval($item->getQty());
$qtyProduct = $_productStock->getQty();
$html = '';
if(!$_productStock->getIsInStock()) {
$html = '<div class="message message-error error"><div data-ui-id="messages-message-error">This product is out of stock</div></div>';
$html = '<div class="message message-error error"><div data-ui-id="messages-message-error">This product is out of stock.</div></div>';
}elseif($qtySelected > $qtyProduct){
$html = '<div class="message message-error error"><div data-ui-id="messages-message-error">This product doesn\'t have enough quantity.</div></div>';
}
return $html;
}
......
......@@ -101,8 +101,11 @@ class Save extends \Magento\Sales\Controller\Adminhtml\Order\Invoice\Save {
$invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);
foreach ($invoice->getAllItems() as $item) {
$_productStock = $this->_stockItemRepository->get($item->getProductId());
if(!$_productStock->getIsInStock()) {
$this->messageManager->addError(__('Some of the products are out of stock!'));
$qtySelected = intval($item->getQty());
$qtyProduct = $_productStock->getQty();
if(!$_productStock->getIsInStock() || ($qtySelected > $qtyProduct)) {
//$this->messageManager->addError(__('Some of the products are out of stock!'));
$this->messageManager->addError(__('Some products do not have enough quantity to create invoice!'));
return $resultRedirect->setPath('sales/order_invoice/new/*', ['order_id' => $order->getId()]);
}
}
......
......@@ -11,7 +11,7 @@
<?php $_item = $block->getItem() ?>
<?php $block->setPriceDataObject($_item)?>
<td class="col-product"><?= $block->getColumnHtml($_item, 'name') ?>
<?= $block->getErrorOutStock($_item->getProductId()) ?>
<?= $block->getErrorOutStock($_item) ?>
</td>
<td class="col-price">
<?= $block->getColumnHtml($_item, 'price') ?>
......