Skip navigation
Help

hook_uc_checkout_complete

6 hooks.php hook_uc_checkout_complete($order, $account)
7 uc_cart.api.php hook_uc_checkout_complete($order, $account)

Takes action when checkout is completed.

Parameters

$order: The resulting order object from the completed checkout.

$account: The customer that completed checkout, either the current user, or the account created for an anonymous customer.

Related topics

1 invocation of hook_uc_checkout_complete()

File

ubercart/uc_cart/uc_cart.api.php, line 263
Hooks provided by the Cart module.

Code

function hook_uc_checkout_complete($order, $account) {
  // Get previous records of customer purchases.
  $nids = array();
  $result = db_query("SELECT uid, nid, qty FROM {uc_customer_purchases} WHERE uid = :uid", array(':uid' => $account->uid));
  foreach ($result as $record) {
    $nids[$record->nid] = $record->qty;
  }

  // Update records with new data.
  $record = array('uid' => $account->uid);
  foreach ($order->products as $product) {
    $record['nid'] = $product->nid;
    if (isset($nids[$product->nid])) {
      $record['qty'] = $nids[$product->nid] + $product->qty;
      db_write_record($record, 'uc_customer_purchases', array('uid', 'nid'));
    }
    else {
      $record['qty'] = $product->qty;
      db_write_record($record, 'uc_customer_purchases');
    }
  }
}