You are here

function uc_cart_login_update in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_cart/uc_cart.module \uc_cart_login_update()
  2. 7.3 uc_cart/uc_cart.module \uc_cart_login_update()
2 calls to uc_cart_login_update()
uc_cart_user in uc_cart/uc_cart.module
Implementation of hook_user().
uc_cart_user_login_form_submit in uc_cart/uc_cart.module

File

uc_cart/uc_cart.module, line 577

Code

function uc_cart_login_update($uid, $sess_id) {

  // Get the current contents of the cart.
  $items = uc_cart_get_contents($uid);

  // Update the cart so the ID is switched from the session to user ID.
  db_query("UPDATE {uc_cart_products} SET cart_id = %d WHERE cart_id = '%s'", $uid, $sess_id);

  // If there were items before the update, we need to re-add them all to
  // take care of item consolidation.
  if (count($items) > 0) {

    // Store again what items these are.
    $items = uc_cart_get_contents($uid, 'rebuild');

    // Remove from the table all the items in the cart.
    // Should be a function call instead of a single query. -RS
    db_query("DELETE FROM {uc_cart_products} WHERE cart_id = '%s'", $uid);

    // Reset the cart item cache.
    uc_cart_get_contents($uid, 'rebuild');

    // Loop through what the items should be and re-add them to the cart.
    foreach ($items as $key => $item) {
      uc_cart_add_item($item->nid, $item->qty, $item->data, $uid, FALSE, FALSE);
    }
  }
}