You are here

function uc_cart_cron in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 uc_cart/uc_cart.module \uc_cart_cron()
  2. 5 uc_cart/uc_cart.module \uc_cart_cron()
  3. 6.2 uc_cart/uc_cart.module \uc_cart_cron()

Implements hook_cron().

File

uc_cart/uc_cart.module, line 220

Code

function uc_cart_cron() {

  // Empty anonymous carts.
  $time = strtotime(variable_get('uc_cart_anon_duration', '4') . ' ' . variable_get('uc_cart_anon_unit', 'hours') . ' ago');
  $result = db_query("SELECT DISTINCT cart_id FROM {uc_cart_products} WHERE changed <= :changed", array(
    ':changed' => $time,
  ));
  foreach ($result as $row) {
    if (strlen($row->cart_id) >= 22) {
      uc_cart_empty($row->cart_id);
    }
  }

  // Empty authenticated carts.
  $time = strtotime(variable_get('uc_cart_auth_duration', '1') . ' ' . variable_get('uc_cart_auth_unit', 'years') . ' ago');
  $result = db_query("SELECT DISTINCT cart_id FROM {uc_cart_products} WHERE changed <= :changed", array(
    ':changed' => $time,
  ));
  foreach ($result as $row) {
    if (strlen($row->cart_id) < 22) {
      uc_cart_empty($row->cart_id);
    }
  }

  // Update status of abandoned orders.
  $result = db_query("SELECT order_id FROM {uc_orders} WHERE order_status = :status AND modified < :time", array(
    ':status' => 'in_checkout',
    ':time' => REQUEST_TIME - UC_CART_ORDER_TIMEOUT,
  ))
    ->fetchCol();
  foreach ($result as $order_id) {
    uc_order_update_status($order_id, 'abandoned');
  }
}