You are here

function commerce_order_status_update in Commerce Core 7

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_update 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. If missing or NULL, the value configured in "Order settings" is used.

$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 calls to commerce_order_status_update()
CommerceBaseTestCase::createDummyOrder in tests/commerce_base.test
Create a dummy order in a given status.
commerce_cart_checkout_form_cancel_submit in 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 modules/cart/commerce_cart.module
Submit handler to show the shopping cart updated message.
commerce_checkout_form_back_submit in modules/checkout/includes/commerce_checkout.pages.inc
Special submit handler for the back button to avoid processing orders.
commerce_checkout_form_cancel_submit in modules/checkout/includes/commerce_checkout.pages.inc
Special submit handler for the cancel button to avoid processing orders.

... See full list

File

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

Code

function commerce_order_status_update($order, $name, $skip_save = FALSE, $revision = NULL, $log = '') {
  if (!isset($revision)) {
    $revision = variable_get('commerce_order_auto_revision', TRUE);
  }

  // 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;
}