You are here

function uc_cart_login_update in Ubercart 6.2

Same name and namespace in other branches
  1. 5 uc_cart/uc_cart.module \uc_cart_login_update()
  2. 7.3 uc_cart/uc_cart.module \uc_cart_login_update()

Updates a user's cart to include items from their anonymous session.

2 calls to uc_cart_login_update()
uc_cart_user in uc_cart/uc_cart.module
Implements hook_user().
uc_cart_user_login_form_submit in uc_cart/uc_cart.module
When a user logs in, update their cart items before the session changes.

File

uc_cart/uc_cart.module, line 854

Code

function uc_cart_login_update($uid) {
  if (!isset($_SESSION['uc_cart_id'])) {
    return;
  }

  // If there are items in the anonymous cart, consolidate them.
  if ($items = uc_cart_get_contents($_SESSION['uc_cart_id'])) {

    // Remove the anonymous cart items.
    db_query("DELETE FROM {uc_cart_products} WHERE cart_id = '%s'", $_SESSION['uc_cart_id']);

    // Merge the anonymous items into the user cart.
    foreach ($items as $key => $item) {
      uc_cart_add_item($item->nid, $item->qty, $item->data, $uid, FALSE, FALSE, FALSE);
    }

    // Unset the anonymous cart ID, it's no longer needed
    unset($_SESSION['uc_cart_id']);
  }
}