You are here

function hook_uc_order in Ubercart 7.3

Performs actions on orders.

An order in Ubercart represents a single transaction. Orders are created during the checkout process where they sit in the database with a status of "In checkout". When a customer completes checkout, the order's status gets updated to show that the sale has gone through. Once an order is created, and even during its creation, it may be acted on by any module to connect extra information to an order. Every time an action occurs to an order, hook_uc_order() gets invoked to let your modules know what's happening and make stuff happen.

Parameters

$op: The action being performed.

$order: This is the order object.

$arg2: This is variable and is based on the value of $op:

  • new: Called when an order is created. $order is a reference to the new order object, so modules may add to or modify the order at creation.
  • presave: Before an order object is saved, the hook gets invoked with this op to let other modules alter order data before it is written to the database. $order is a reference to the order object.
  • save: When an order object is being saved, the hook gets invoked with this op to let other modules do any necessary saving. $order is a reference to the order object.
  • load: Called when an order is loaded after the order and product data has been loaded from the database. Passes $order as the reference to the order object, so modules may add to or modify the order object when it's loaded.
  • submit: When a sale is being completed and the customer has clicked the Submit order button from the checkout screen, the hook is invoked with this op. This gives modules a chance to determine whether or not the order should be allowed. An example use of this is the credit module attempting to process payments when an order is submitted and returning a failure message if the payment failed. To prevent an order from passing through, you must return an array resembling the following one with the failure message:
return array(
  array(
    'pass' => FALSE,
    'message' => t('We were unable to process your credit card.'),
  ),
);
  • can_update: Called before an order's status is changed to make sure the order can be updated. $order is the order object with the old order status ID ($order->order_status), and $arg2 is simply the new order status ID. Return FALSE to stop the update for some reason.
  • update: Called when an order's status is changed. $order is the order object with the old order status ID ($order->order_status), and $arg2 is the new order status ID.
  • can_delete: Called before an order is deleted to verify that the order may be deleted. Returning FALSE will prevent a delete from happening. (For example, the payment module returns FALSE by default when an order has already received payments.)
  • delete: Called when an order is deleted and before the rest of the order information is removed from the database. Passes $order as the order object to let your module clean up it's tables.
  • total: Called when the total for an order is being calculated after the total of the products has been added. Passes $order as the order object. Expects in return a value (positive or negative) by which to modify the order total.
7 functions implement hook_uc_order()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

template_preprocess_uc_order in uc_order/uc_order.module
Preprocesses a formatted invoice with an order's data.
uc_credit_uc_order in payment/uc_credit/uc_credit.module
Implements hook_uc_order().
uc_googleanalytics_uc_order in uc_googleanalytics/uc_googleanalytics.module
Implements hook_uc_order().
uc_payment_uc_order in payment/uc_payment/uc_payment.module
Implements hook_uc_order().
uc_quote_uc_order in shipping/uc_quote/uc_quote.module
Implements hook_uc_order().

... See full list

5 invocations of hook_uc_order()
uc_cart_checkout_review_form_submit in uc_cart/uc_cart.pages.inc
Final checks to make sure the order can be completed.
uc_order_can_delete in uc_order/uc_order.module
Access callback for admin/store/orders/%uc_order/delete.
uc_order_get_total in uc_order/uc_order.module
Calculates an order's total.
uc_order_module_invoke in uc_order/uc_order.module
Invokes hook_uc_order() in every module.
uc_order_update_status in uc_order/uc_order.module
Updates an order's status as long as no one objects.

File

uc_order/uc_order.api.php, line 187
Hooks provided by the Order module.

Code

function hook_uc_order($op, $order, $arg2) {
  switch ($op) {
    case 'save':

      // Do something to save payment info!
      break;
  }
}