You are here

function uc_order_update_status in Ubercart 5

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

Update 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.

4 calls to uc_order_update_status()
uc_cart_complete_sale in uc_cart/uc_cart.module
Completes a sale, including adjusting order status and creating user account.
uc_order_action_update_status in uc_order/uc_order_workflow.inc
uc_order_view_update_form_submit in uc_order/uc_order_order_pane.inc
uc_paypal_ipn in payment/uc_paypal/uc_paypal.module

File

uc_order/uc_order.module, line 2718

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 false if any module says the update is not good to go.
    $return = module_invoke_all('order', 'can_update', $order, $status);
    for ($i = 0; $i < count($return); $i++) {
      if ($return[$i] === FALSE) {
        return FALSE;
      }
    }

    // Otherwise perform the update and log the changes.
    db_query("UPDATE {uc_orders} SET order_status = '%s', modified = %d WHERE order_id = %d", $status, time(), $order_id);
    module_invoke_all('order', '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);
    workflow_ng_invoke_event('order_status_update', $order, $updated);
    return TRUE;
  }

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