You are here

public function Subscription::getCurrentOrder in Commerce Recurring Framework 8

Gets the current draft recurring order.

Return value

\Drupal\commerce_order\Entity\OrderInterface|null The current draft recurring order, or NULL if none found.

Overrides SubscriptionInterface::getCurrentOrder

2 calls to Subscription::getCurrentOrder()
Subscription::getCurrentBillingPeriod in src/Entity/Subscription.php
Gets the billing period value object for the current order.
Subscription::postSave in src/Entity/Subscription.php
Acts on a saved entity before the insert or update hook is invoked.

File

src/Entity/Subscription.php, line 313

Class

Subscription
Defines the subscription entity.

Namespace

Drupal\commerce_recurring\Entity

Code

public function getCurrentOrder() {
  $order_ids = $this
    ->getOrderIds();
  if (empty($order_ids)) {
    return NULL;
  }
  $order_storage = $this
    ->entityTypeManager()
    ->getStorage('commerce_order');
  $order_ids = $order_storage
    ->getQuery()
    ->condition('type', 'recurring')
    ->condition('order_id', $order_ids, 'IN')
    ->condition('state', 'draft')
    ->sort('order_id', 'DESC')
    ->accessCheck(FALSE)
    ->range(0, 1)
    ->execute();
  if (!$order_ids) {
    return NULL;
  }
  return $order_storage
    ->load(key($order_ids));
}