You are here

public function Order::getSubtotalPrice in Commerce Core 8.2

Gets the order subtotal price.

Represents a sum of all order item totals.

Return value

\Drupal\commerce_price\Price|null The order subtotal price, or NULL.

Overrides OrderInterface::getSubtotalPrice

File

modules/order/src/Entity/Order.php, line 423

Class

Order
Defines the order entity class.

Namespace

Drupal\commerce_order\Entity

Code

public function getSubtotalPrice() {

  /** @var \Drupal\commerce_price\Price $subtotal_price */
  $subtotal_price = NULL;
  foreach ($this
    ->getItems() as $order_item) {
    if ($order_item_total = $order_item
      ->getTotalPrice()) {
      $subtotal_price = $subtotal_price ? $subtotal_price
        ->add($order_item_total) : $order_item_total;
    }
  }
  return $subtotal_price;
}