You are here

function hook_order in Ubercart 6.2

Same name and namespace in other branches
  1. 5 docs/hooks.php \hook_order()

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_order() gets invoked to let your modules know what's happening and make stuff happen.

Parameters

$op: The action being performed.

&$arg1: This is the order object.

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

  • new: Called when an order is created. $arg1 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. $arg1 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 $arg1 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. $arg1 is the order object with the old order status ID ($arg1->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. $arg1 is the order object with the old order status ID ($arg1->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 $arg1 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 $arg1 as the order object. Expects in return a value (positive or negative) by which to modify the order total.
9 functions implement hook_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
Preprocess a formatted invoice with an order's data.
uc_credit_order in payment/uc_credit/uc_credit.module
Implements hook_order().
uc_googleanalytics_order in uc_googleanalytics/uc_googleanalytics.module
Implements hook_order().
uc_order_can_view_order in uc_order/uc_order.module
Access callback for user/%user/orders*.
uc_payment_order in payment/uc_payment/uc_payment.module
Implements hook_order().

... See full list

1 invocation of hook_order()
uc_order_can_delete in uc_order/uc_order.module
Access callback for admin/store/orders/%uc_order/delete.

File

docs/hooks.php, line 790
These are the hooks that are invoked by the Ubercart core.

Code

function hook_order($op, $arg1, $arg2) {
  switch ($op) {
    case 'save':

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