You are here

function uc_order_update_status in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_order/uc_order.module \uc_order_update_status()
  2. 6.2 uc_order/uc_order.module \uc_order_update_status()

Updates an order's status as long as no one objects.

Parameters

$order_id: The ID of the order to be updated.

$status: The new status ID we want to move the order to.

Return value

TRUE or FALSE depending on the success of the update.

10 calls to uc_order_update_status()
UbercartTaxesTestCase::testStoredTaxDisplay in uc_taxes/tests/uc_taxes.test
uc_2checkout_process_notification in payment/uc_2checkout/uc_2checkout.pages.inc
React on status changes from 2CO.
uc_cart_checkout in uc_cart/uc_cart.pages.inc
Displays the cart checkout page built of checkout panes from enabled modules.
uc_cart_complete_sale in uc_cart/uc_cart.module
Completes a sale, including adjusting order status and creating user account.
uc_cart_cron in uc_cart/uc_cart.module
Implements hook_cron().

... See full list

1 string reference to 'uc_order_update_status'
uc_payment_default_rules_configuration in payment/uc_payment/uc_payment.rules_defaults.inc
Implements hook_default_rules_configuration().

File

uc_order/uc_order.module, line 1504

Code

function uc_order_update_status($order_id, $status) {

  // Return FALSE if an invalid $status is specified.
  if (uc_order_status_data($status, 'id') == NULL) {
    return FALSE;
  }
  $order = uc_order_load($order_id);

  // Attempt the update if the order exists.
  if ($order !== FALSE) {

    // Return TRUE if the order status is already set.
    if ($order->order_status == $status) {
      return TRUE;
    }

    // Return FALSE if any module says the update is not good to go.
    foreach (module_implements('uc_order') as $module) {
      $function = $module . '_uc_order';

      // $order must be passed by reference.
      if (function_exists($function) && $function('can_update', $order, $status) === FALSE) {
        return FALSE;
      }
    }

    // Otherwise perform the update and log the changes.
    db_update('uc_orders')
      ->fields(array(
      'order_status' => $status,
      'modified' => REQUEST_TIME,
    ))
      ->condition('order_id', $order_id)
      ->execute();
    uc_order_module_invoke('update', $order, $status);
    $change = array(
      t('Order status') => array(
        'old' => uc_order_status_data($order->order_status, 'title'),
        'new' => uc_order_status_data($status, 'title'),
      ),
    );
    uc_order_log_changes($order->order_id, $change);
    $updated = uc_order_load($order_id, TRUE);
    rules_invoke_event('uc_order_status_update', $order, $updated);
    return TRUE;
  }

  // Return FALSE if the order didn't exist.
  return FALSE;
}