Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Vo Van Khoa
/
M2OverrideCreateInvoice
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
3fcb9a31
authored
2018-05-19 08:43:20 +0700
by
Vo Van Khoa
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge
2 parents
d7fee7b4
4b86bebf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
5 deletions
.gitignore
app/code/FGCT/OverrideCreateInvoice/Block/Adminhtml/Items/Renderer/DefaultRenderer.php
app/code/FGCT/OverrideCreateInvoice/Controller/Adminhtml/Order/Invoice/Save.php
app/code/FGCT/OverrideCreateInvoice/view/adminhtml/templates/order/invoice/create/items/renderer/default.phtml
.gitignore
View file @
3fcb9a3
.vscode
.history
/nbproject/private/
...
...
app/code/FGCT/OverrideCreateInvoice/Block/Adminhtml/Items/Renderer/DefaultRenderer.php
View file @
3fcb9a3
...
...
@@ -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
;
}
...
...
app/code/FGCT/OverrideCreateInvoice/Controller/Adminhtml/Order/Invoice/Save.php
View file @
3fcb9a3
...
...
@@ -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
()]);
}
}
...
...
app/code/FGCT/OverrideCreateInvoice/view/adminhtml/templates/order/invoice/create/items/renderer/default.phtml
View file @
3fcb9a3
...
...
@@ -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'
)
?>
...
...
Please
register
or
sign in
to post a comment