Commits

Bruce Kroeze committed a5bd2a5

fixing a bug with persistent cart - wasn't loading the cart unless the PERSISTENT_CART_MERGE option was true

  • Participants
  • Parent commits e3421ac

Comments (0)

Files changed (1)

File satchmo/apps/satchmo_store/accounts/views.py

 def _get_prev_cart(request):
     try:
         contact = Contact.objects.from_request(request)
+        if not contact:
+            return None
         saved_cart = contact.cart_set.latest('date_time_created')
         # If the latest cart has len == 0, cart is unusable.
-        if len(saved_cart) and 'cart' in request.session:
-            existing_cart = Cart.objects.from_request(request, create=False)
-            if ( (len(existing_cart) == 0) or config_value('SHOP','PERSISTENT_CART_MERGE') ):
-                # Merge the two carts together
-                saved_cart.merge_carts(existing_cart)
-                request.session['cart'] = saved_cart.id
-    except Exception, e:
-        pass
+        if saved_cart and len(saved_cart):
+            if 'cart' in request.session:
+                existing_cart = Cart.objects.from_request(request, create=False)
+                if ( (len(existing_cart) == 0) or config_value('SHOP','PERSISTENT_CART_MERGE') ):
+                    # Merge the two carts together
+                    saved_cart.merge_carts(existing_cart)
+
+            request.session['cart'] = saved_cart.id
+            log.debug('retrieved cart: %s', saved_cart)
+            return saved_cart
+
+    except Exception:
+        return None
 
 def register_handle_address_form(request, redirect=None, action_required=''):
     """