4b86bebf by Hoang Bien

Update for new requirement: "chỉ cần 1 sp nào đó ko đủ số lượng" 18 May 2018

1 parent 36967cf6
1 .vscode 1 .vscode
2 .history 2 .history
3 /nbproject/private/
...\ No newline at end of file ...\ No newline at end of file
......
...@@ -32,11 +32,16 @@ class DefaultRenderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\Defa ...@@ -32,11 +32,16 @@ class DefaultRenderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\Defa
32 parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data); 32 parent::__construct($context, $stockRegistry, $stockConfiguration, $registry, $data);
33 } 33 }
34 34
35 public function getErrorOutStock($productId) { 35 public function getErrorOutStock($item) {
36 $productId = $item->getProductId();
36 $_productStock = $this->_stockItemRepository->get($productId); 37 $_productStock = $this->_stockItemRepository->get($productId);
38 $qtySelected = intval($item->getQty());
39 $qtyProduct = $_productStock->getQty();
37 $html = ''; 40 $html = '';
38 if(!$_productStock->getIsInStock()) { 41 if(!$_productStock->getIsInStock()) {
39 $html = '<div class="message message-error error"><div data-ui-id="messages-message-error">This product is out of stock</div></div>'; 42 $html = '<div class="message message-error error"><div data-ui-id="messages-message-error">This product is out of stock.</div></div>';
43 }elseif($qtySelected > $qtyProduct){
44 $html = '<div class="message message-error error"><div data-ui-id="messages-message-error">This product doesn\'t have enough quantity.</div></div>';
40 } 45 }
41 return $html; 46 return $html;
42 } 47 }
......
...@@ -101,8 +101,11 @@ class Save extends \Magento\Sales\Controller\Adminhtml\Order\Invoice\Save { ...@@ -101,8 +101,11 @@ class Save extends \Magento\Sales\Controller\Adminhtml\Order\Invoice\Save {
101 $invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems); 101 $invoice = $this->invoiceService->prepareInvoice($order, $invoiceItems);
102 foreach ($invoice->getAllItems() as $item) { 102 foreach ($invoice->getAllItems() as $item) {
103 $_productStock = $this->_stockItemRepository->get($item->getProductId()); 103 $_productStock = $this->_stockItemRepository->get($item->getProductId());
104 if(!$_productStock->getIsInStock()) { 104 $qtySelected = intval($item->getQty());
105 $this->messageManager->addError(__('Some of the products are out of stock!')); 105 $qtyProduct = $_productStock->getQty();
106 if(!$_productStock->getIsInStock() || ($qtySelected > $qtyProduct)) {
107 //$this->messageManager->addError(__('Some of the products are out of stock!'));
108 $this->messageManager->addError(__('Some products do not have enough quantity to create invoice!'));
106 return $resultRedirect->setPath('sales/order_invoice/new/*', ['order_id' => $order->getId()]); 109 return $resultRedirect->setPath('sales/order_invoice/new/*', ['order_id' => $order->getId()]);
107 } 110 }
108 } 111 }
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
11 <?php $_item = $block->getItem() ?> 11 <?php $_item = $block->getItem() ?>
12 <?php $block->setPriceDataObject($_item)?> 12 <?php $block->setPriceDataObject($_item)?>
13 <td class="col-product"><?= $block->getColumnHtml($_item, 'name') ?> 13 <td class="col-product"><?= $block->getColumnHtml($_item, 'name') ?>
14 <?= $block->getErrorOutStock($_item->getProductId()) ?> 14 <?= $block->getErrorOutStock($_item) ?>
15 </td> 15 </td>
16 <td class="col-price"> 16 <td class="col-price">
17 <?= $block->getColumnHtml($_item, 'price') ?> 17 <?= $block->getColumnHtml($_item, 'price') ?>
......