Index: uc_cart.module
===================================================================
--- uc_cart.module	(revision 327)
+++ uc_cart.module	(working copy)
@@ -1315,16 +1315,30 @@
  * Return the unique cart_id of the user.
  */
 function uc_cart_get_id() {
+  $cid = uc_cart_get_id_existing();
+
+  if (0 == $cid) {
+    $cid = $_SESSION['uc_cart_id'] = md5(uniqid(rand(), TRUE));
+  }
+
+  return $cid;
+}
+
+/**
+ * Return the unique cart_id of authenticated user or existing cart_id of anonymous user.
+ * Returns 0 if anonymous user has no cart_id.
+ */
+function uc_cart_get_id_existing() {
   global $user;
 
   if ($user->uid) {
     return $user->uid;
   }
-  elseif (!isset($_SESSION['uc_cart_id'])) {
-    $_SESSION['uc_cart_id'] = md5(uniqid(rand(), TRUE));
+  elseif (isset($_SESSION['uc_cart_id'])) {
+    return $_SESSION['uc_cart_id'];
   }
 
-  return $_SESSION['uc_cart_id'];
+  return 0;
 }
 
 /**
@@ -1335,7 +1349,12 @@
  */
 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_existing();
+
+  if (0 == $cid) {
+    return array();
+  }
 
   if ($action == 'rebuild') {
     unset($items[$cid]);
