You are here

public function ShippingOrderManager::isShippable in Commerce Shipping 8.2

Determines whether the order is shippable.

Parameters

\Drupal\commerce_order\Entity\OrderInterface $order: The order.

Return value

bool TRUE if the order is shippable, FALSE otherwise.

Overrides ShippingOrderManagerInterface::isShippable

File

src/ShippingOrderManager.php, line 87

Class

ShippingOrderManager

Namespace

Drupal\commerce_shipping

Code

public function isShippable(OrderInterface $order) {
  if (!$order
    ->hasField('shipments')) {
    return FALSE;
  }

  // The order must contain at least one shippable purchasable entity.
  foreach ($order
    ->getItems() as $order_item) {
    $purchased_entity = $order_item
      ->getPurchasedEntity();
    if ($purchased_entity && $purchased_entity
      ->hasField('weight')) {
      return TRUE;
    }
  }
  return FALSE;
}