diff --git uc_cart/uc_cart.module uc_cart/uc_cart.module index 2fbba65..ce681ad 100644 --- uc_cart/uc_cart.module +++ uc_cart/uc_cart.module @@ -1306,18 +1306,23 @@ function theme_uc_cart_complete_sale($message) { /** * Return the unique cart_id of the user. + * + * @param $create + * Toggle auto creation of cart id. + * @return + * Cart id. If $create is FALSE will return FALSE if there is no cart id. */ -function uc_cart_get_id() { +function uc_cart_get_id($create = TRUE) { global $user; if ($user->uid) { return $user->uid; } - elseif (!isset($_SESSION['uc_cart_id'])) { + elseif (!isset($_SESSION['uc_cart_id']) && $create) { $_SESSION['uc_cart_id'] = md5(uniqid(rand(), TRUE)); } - return $_SESSION['uc_cart_id']; + return isset($_SESSION['uc_cart_id']) ? $_SESSION['uc_cart_id'] : FALSE; } /** @@ -1328,7 +1333,13 @@ function uc_cart_get_id() { */ function uc_cart_get_contents($cid = NULL, $action = NULL) { static $items = array(); - $cid = $cid ? $cid : uc_cart_get_id(); + + $cid = $cid ? $cid : uc_cart_get_id(FALSE); + + // If we didn't get a cid, return empty. + if (!$cid) { + return array(); + } if ($action == 'rebuild') { unset($items[$cid]); @@ -1387,14 +1398,17 @@ function uc_cart_get_contents($cid = NULL, $action = NULL) { * An integer representing the total number of items in the cart. */ function uc_cart_get_total_qty($cid = NULL) { - if (empty($cid)) { - $cid = uc_cart_get_id(); - } $qty = 0; - foreach (uc_cart_get_contents($cid) as $item) { - $qty += $item->qty; + if (empty($cid)) { + $cid = uc_cart_get_id(FALSE); + } + + if ($cid) { + foreach (uc_cart_get_contents($cid) as $item) { + $qty += $item->qty; + } } return $qty;