You are here

public function Cron::run in Commerce Core 8.2

Runs the cron.

Overrides CronInterface::run

File

modules/cart/src/Cron.php, line 57

Class

Cron
Default cron implementation.

Namespace

Drupal\commerce_cart

Code

public function run() {

  /** @var \Drupal\commerce_order\Entity\OrderTypeInterface[] $order_types */
  $order_types = $this->orderTypeStorage
    ->loadMultiple();
  foreach ($order_types as $order_type) {
    $cart_expiration = $order_type
      ->getThirdPartySetting('commerce_cart', 'cart_expiration');
    if (empty($cart_expiration)) {
      continue;
    }
    $interval = new Interval($cart_expiration['number'], $cart_expiration['unit']);
    $all_order_ids = $this
      ->getOrderIds($order_type
      ->id(), $interval);
    foreach (array_chunk($all_order_ids, 50) as $order_ids) {
      $this->queue
        ->createItem($order_ids);
    }
  }
}