function hook_uc_checkout_complete in Ubercart 7.3
Same name and namespace in other branches
- 8.4 uc_cart/uc_cart.api.php \hook_uc_checkout_complete()
 - 6.2 docs/hooks.php \hook_uc_checkout_complete()
 
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.
1 invocation of hook_uc_checkout_complete()
- uc_cart_complete_sale in uc_cart/
uc_cart.module  - Completes a sale, including adjusting order status and creating user account.
 
File
- uc_cart/
uc_cart.api.php, line 262  - 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');
    }
  }
}