function hook_uc_checkout_complete in Ubercart 6.2
Same name and namespace in other branches
- 8.4 uc_cart/uc_cart.api.php \hook_uc_checkout_complete()
- 7.3 uc_cart/uc_cart.api.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
- docs/
hooks.php, line 1542 - These are the hooks that are invoked by the Ubercart core.
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 = %d", $account->uid);
while ($record = db_fetch_object($result)) {
$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');
}
}
}