function hook_uc_checkout_complete in Ubercart 8.4
Same name and namespace in other branches
- 6.2 docs/hooks.php \hook_uc_checkout_complete()
- 7.3 uc_cart/uc_cart.api.php \hook_uc_checkout_complete()
Takes action when checkout is completed.
Parameters
\Drupal\uc_order\OrderInterface $order: The resulting order object from the completed checkout.
\Drupal\Core\Session\AccountInterface $account: The customer that completed checkout, either the current user, or the account created for an anonymous customer.
2 functions implement hook_uc_checkout_complete()
Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.
- uc_cart_uc_checkout_complete in uc_cart/
uc_cart.module - Implements hook_uc_checkout_complete().
- uc_stock_uc_checkout_complete in uc_stock/
uc_stock.module - Implements hook_uc_checkout_complete().
1 invocation of hook_uc_checkout_complete()
- CartManager::completeSale in uc_cart/
src/ CartManager.php - Completes a sale, including adjusting order status and creating an account.
File
- uc_cart/
uc_cart.api.php, line 214 - Hooks provided by the Cart module.
Code
function hook_uc_checkout_complete(OrderInterface $order, AccountInterface $account) {
// Get previous records of customer purchases.
$nids = [];
$result = db_query("SELECT uid, nid, qty FROM {uc_customer_purchases} WHERE uid = :uid", [
':uid' => $account
->id(),
]);
foreach ($result as $record) {
$nids[$record->nid] = $record->qty;
}
// Update records with new data.
$record = [
'uid' => $account
->id(),
];
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', [
'uid',
'nid',
]);
}
else {
$record['qty'] = $product->qty;
db_write_record($record, 'uc_customer_purchases');
}
}
}