Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CanInvoice.php
Go to the documentation of this file.
1 <?php
7 
11 
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 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$order
Definition: order.php:55
__()
Definition: __.php:13
$entity
Definition: element.phtml:22