You are here

protected function RecurringJobTypeBase::updateSubscriptions in Commerce Recurring Framework 8

Updates the recurring order's subscriptions to the new state.

Parameters

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

string $new_state_id: The new state.

1 call to RecurringJobTypeBase::updateSubscriptions()
RecurringJobTypeBase::handleFailedOrder in src/Plugin/AdvancedQueue/JobType/RecurringJobTypeBase.php
Handles an order whose payment has definitively failed.

File

src/Plugin/AdvancedQueue/JobType/RecurringJobTypeBase.php, line 147

Class

RecurringJobTypeBase
Provides a base class for recurring job types.

Namespace

Drupal\commerce_recurring\Plugin\AdvancedQueue\JobType

Code

protected function updateSubscriptions(OrderInterface $order, $new_state_id) {
  $subscriptions = $this->recurringOrderManager
    ->collectSubscriptions($order);
  foreach ($subscriptions as $subscription) {
    if ($subscription
      ->getState()
      ->getId() != 'active') {

      // The subscriptions are expected to be active, if one isn't, it
      // might have been canceled in the meantime.
      continue;
    }
    $subscription
      ->setState($new_state_id);
    $subscription
      ->save();
  }
}