Skip to content

Commit

Permalink
This makes the Cart's empty() method use delete instead of simply emp…
Browse files Browse the repository at this point in the history
…tying the

content, so that a signal is fired by django (handy). Fixes awesto#38
  • Loading branch information
chrisglass committed Apr 20, 2011
1 parent f141c01 commit e142ca7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions shop/models/cartmodel.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def empty(self):
Remove all cart items
"""
self.items.all().delete()
self.delete()

@property
def total_quantity(self):
Expand Down
7 changes: 5 additions & 2 deletions shop/util/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ def get_or_create_cart(request):
# There is a session
cart_id = session.get('cart_id')
if cart_id:
cart = Cart.objects.get(pk=cart_id)
else:
try:
cart = Cart.objects.get(pk=cart_id)
except Cart.DoesNotExist:
cart = None
if not cart:
cart = Cart.objects.create()
session['cart_id'] = cart.id
return cart

0 comments on commit e142ca7

Please sign in to comment.