diff --git a/uc_cart/uc_cart.module b/uc_cart/uc_cart.module index 523a6f1..50478c9 100644 --- a/uc_cart/uc_cart.module +++ b/uc_cart/uc_cart.module @@ -218,6 +218,13 @@ function uc_cart_cron() { 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 - 600))->fetchCol(); + foreach ($result as $order_id) { + uc_order_update_status($order_id, 'abandoned'); + } } /** diff --git a/uc_cart/uc_cart.pages.inc b/uc_cart/uc_cart.pages.inc index f7b43f3..bd00f7d 100644 --- a/uc_cart/uc_cart.pages.inc +++ b/uc_cart/uc_cart.pages.inc @@ -114,6 +114,9 @@ function uc_cart_checkout_form($form, &$form_state) { // If there hasn't been activity on the checkout page for 20 minutes, clear // order details and prevent identity theft. if (!$order || uc_order_status_data($order->order_status, 'state') != 'in_checkout' || $order->modified < REQUEST_TIME - 600 || ($user->uid > 0 && $user->uid != $order->uid)) { + if ($order && $order->status == 'in_checkout' && $order->modified < REQUEST_TIME - 600) { + uc_order_update_status($order->order_id, 'abandoned'); + } $order = uc_order_new($user->uid); $_SESSION['cart_order'] = $order->order_id; } diff --git a/uc_order/uc_order.install b/uc_order/uc_order.install index ce689c1..72f83e3 100644 --- a/uc_order/uc_order.install +++ b/uc_order/uc_order.install @@ -617,6 +617,13 @@ function uc_order_install() { $values = array( array( + 'order_status_id' => 'abandoned', + 'title' => $t('Abandoned'), + 'state' => 'canceled', + 'weight' => -30, + 'locked' => 1, + ), + array( 'order_status_id' => 'canceled', 'title' => $t('Canceled'), 'state' => 'canceled', @@ -803,3 +810,18 @@ function uc_order_update_7004(&$sandbox) { $sandbox['#finished'] = 1; } } + +/** + * Add 'abandoned' order status. + */ +function uc_order_update_7004() { + db_merge('uc_order_statuses') + ->key(array('order_status_id' => 'abandoned')) + ->fields(array( + 'title' => t('Abandoned'), + 'state' => 'canceled', + 'weight' => -30, + 'locked' => 1, + )) + ->execute(); +}