Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-sales
Model
Order
Validation
CanInvoice.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Sales\Model\Order\Validation
;
7
8
use
Magento\Sales\Api\Data\OrderInterface
;
9
use
Magento\Sales\Model\Order
;
10
use
Magento\Sales\Model\ValidatorInterface
;
11
15
class
CanInvoice
implements
ValidatorInterface
16
{
21
public
function
validate
(
$entity
)
22
{
23
$messages = [];
24
25
if
(!$this->isStateReadyForInvoice(
$entity
)) {
26
$messages[] =
__
(
'An invoice cannot be created when an order has a status of %1'
,
$entity
->getStatus());
27
}
elseif
(!$this->
canInvoice
(
$entity
)) {
28
$messages[] =
__
(
'The order does not allow an invoice to be created.'
);
29
}
30
31
return
$messages;
32
}
33
38
private
function
isStateReadyForInvoice(
OrderInterface
$order
)
39
{
40
if
(
$order
->getState() ===
Order::STATE_PAYMENT_REVIEW
||
41
$order
->getState() ===
Order::STATE_HOLDED
||
42
$order
->getState() ===
Order::STATE_CANCELED
||
43
$order
->getState() ===
Order::STATE_COMPLETE
||
44
$order
->getState() ===
Order::STATE_CLOSED
45
) {
46
return
false
;
47
};
48
49
return
true
;
50
}
51
56
private
function
canInvoice
(
OrderInterface
$order
)
57
{
59
foreach
(
$order
->getItems() as
$item
) {
60
if
(
$item
->getQtyToInvoice() > 0 && !
$item
->getLockedDoInvoice()) {
61
return
true
;
62
}
63
}
64
return
false
;
65
}
66
}
Magento\Sales\Model\Order\STATE_HOLDED
const STATE_HOLDED
Definition:
Order.php:73
elseif
elseif(isset( $params[ 'redirect_parent']))
Definition:
iframe.phtml:17
Magento\Sales\Model\Order
Magento\Sales\Model\Order\Validation\CanInvoice\validate
validate($entity)
Definition:
CanInvoice.php:21
$order
$order
Definition:
order.php:55
Magento\Sales\Model\Order\STATE_CLOSED
const STATE_CLOSED
Definition:
Order.php:69
__
__()
Definition:
__.php:13
$item
$item
Definition:
partial_invoice.php:27
Magento\Sales\Model\Order\Validation
Definition:
CanInvoice.php:6
Magento\Sales\Model\Order\STATE_COMPLETE
const STATE_COMPLETE
Definition:
Order.php:67
Magento\Sales\Api\Data\OrderInterface
Definition:
OrderInterface.php:17
Magento\Sales\Model\Order\STATE_CANCELED
const STATE_CANCELED
Definition:
Order.php:71
Magento\Sales\Model\ValidatorInterface
Definition:
ValidatorInterface.php:14
Magento\Sales\Model\Order\canInvoice
canInvoice()
Definition:
Order.php:592
$entity
$entity
Definition:
element.phtml:22
Magento\Sales\Model\Order\STATE_PAYMENT_REVIEW
const STATE_PAYMENT_REVIEW
Definition:
Order.php:75
Magento\Sales\Model\Order\Validation\CanInvoice
Definition:
CanInvoice.php:15