Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CanShip.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class CanShip implements ValidatorInterface
16 {
21  public function validate($entity)
22  {
23  $messages = [];
24  if (!$this->isStateReadyForShipment($entity)) {
25  $messages[] = __('A shipment cannot be created when an order has a status of %1', $entity->getStatus());
26  } elseif (!$this->canShip($entity)) {
27  $messages[] = __('The order does not allow a shipment to be created.');
28  }
29 
30  return $messages;
31  }
32 
37  private function isStateReadyForShipment(OrderInterface $order)
38  {
39  if ($order->getState() === Order::STATE_PAYMENT_REVIEW ||
40  $order->getState() === Order::STATE_HOLDED ||
41  $order->getIsVirtual() ||
42  $order->getState() === Order::STATE_CANCELED
43  ) {
44  return false;
45  }
46 
47  return true;
48  }
49 
54  private function canShip(OrderInterface $order)
55  {
57  foreach ($order->getItems() as $item) {
58  if ($item->getQtyToShip() > 0 && !$item->getIsVirtual() && !$item->getLockedDoShip()) {
59  return true;
60  }
61  }
62 
63  return false;
64  }
65 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$order
Definition: order.php:55
__()
Definition: __.php:13
$entity
Definition: element.phtml:22