commerce_order_status_update

DC commerce_order.module commerce_order_status_update($order, $name, $skip_save = FALSE, $revision = TRUE, $log = '')

Updates the status of an order to the specified status.

While there is no explicit Rules event or hook devoted to an order status being updated, you can use the commerce_order_updated event / hook to check for a changed order status by comparing $order->original->status to the $order->status. If they are different, this will alert you that the order status for the given order was just changed.

Parameters

$order: The fully loaded order object to update.

$name: The machine readable name string of the status to update to.

$skip_save: TRUE to skip saving the order after updating the status; used when the order would be saved elsewhere after the update.

$revision: TRUE or FALSE indicating whether or not a new revision should be created for the order if it is saved as part of the status update. Defaults to TRUE.

$log: If a new revision is created for the update, the log message that will be used for the revision.

Return value

The updated order.

▾ 12 functions call commerce_order_status_update()

CommerceBaseTestCase::createDummyOrder in sites/all/modules/commerce/tests/commerce_base.test
Create a dummy order in a given status.
commerce_cart_checkout_form_cancel_submit in sites/all/modules/commerce/modules/cart/commerce_cart.module
Submit handler to take back the order to cart status on cancel in checkout.
commerce_cart_line_item_views_form_submit in sites/all/modules/commerce/modules/cart/commerce_cart.module
Submit handler to show the shopping cart updated message.
commerce_checkout_form_back_submit in sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc
Special submit handler for the back button to avoid processing orders.
commerce_checkout_form_cancel_submit in sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc
Special submit handler for the cancel button to avoid processing orders.
commerce_checkout_form_submit in sites/all/modules/commerce/modules/checkout/includes/commerce_checkout.pages.inc
Submit handler for the continue button of the checkout form.
commerce_checkout_line_item_views_form_submit in sites/all/modules/commerce/modules/checkout/commerce_checkout.module
Submit handler used to redirect to the checkout page.
commerce_order_order_form_submit in sites/all/modules/commerce/modules/order/includes/commerce_order.forms.inc
Submit callback for commerce_order_order_form().
commerce_order_rules_update_state in sites/all/modules/commerce/modules/order/commerce_order.rules.inc
Rules action: updates an order's status to the default status of the given order state.
commerce_order_rules_update_status in sites/all/modules/commerce/modules/order/commerce_order.rules.inc
Rules action: updates an order's status using the Order API.
commerce_payment_redirect_pane_next_page in sites/all/modules/commerce/modules/payment/commerce_payment.module
Moves an order ahead to the next page via an order update and redirect.
commerce_payment_redirect_pane_previous_page in sites/all/modules/commerce/modules/payment/commerce_payment.module
Moves an order back to the previous page via an order update and redirect.

File

sites/all/modules/commerce/modules/order/commerce_order.module, line 1275
Defines the core Commerce order entity and API functions to manage orders and interact with them.

Code

<?php
function commerce_order_status_update($order, $name, $skip_save = FALSE, $revision = TRUE, $log = '') {
  // Do not update the status if the order is already at it.
  if ($order->status != $name) {
    $order->status = $name;

    if (!$skip_save) {
      // If the status update should create a new revision, update the order
      // object to reflect this and include a log message.
      if ($revision) {
        $order->revision = TRUE;
        $order->log = $log;
      }

      commerce_order_save($order);
    }
  }

  return $order;
}
?>