Skip to content

Commit

Permalink
Be thread-safe. Be cool. Be Oscar™
Browse files Browse the repository at this point in the history
  • Loading branch information
patrys committed Jan 9, 2013
1 parent 646ef2c commit 8f776e4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions oscar/apps/basket/middleware.py
Expand Up @@ -12,7 +12,7 @@
class BasketMiddleware(object):

def process_request(self, request):
self.cookies_to_delete = []
request.cookies_to_delete = []
basket = self.get_basket(request)
self.apply_offers_to_basket(request, basket)
request.basket = basket
Expand All @@ -38,7 +38,7 @@ def get_basket(self, request):

if cookie_basket:
self.merge_baskets(basket, cookie_basket, request=request)
self.cookies_to_delete.append(settings.OSCAR_BASKET_COOKIE_OPEN)
request.cookies_to_delete.append(settings.OSCAR_BASKET_COOKIE_OPEN)
elif cookie_basket:
# Anonymous user with a basket tied to the cookie
basket = cookie_basket
Expand All @@ -59,8 +59,8 @@ def merge_baskets(self, master, slave, request=None):
def process_response(self, request, response):

# Delete any surplus cookies
if hasattr(self, 'cookies_to_delete'):
for cookie_key in self.cookies_to_delete:
if hasattr(request, 'cookies_to_delete'):
for cookie_key in request.cookies_to_delete:
response.delete_cookie(cookie_key)

# If a basket has had products added to it, but the user is anonymous
Expand Down Expand Up @@ -98,9 +98,9 @@ def get_cookie_basket(self, cookie_key, request, manager):
try:
basket = basket_model.objects.get(pk=basket_id, owner=None)
except basket_model.DoesNotExist:
self.cookies_to_delete.append(cookie_key)
request.cookies_to_delete.append(cookie_key)
else:
self.cookies_to_delete.append(cookie_key)
request.cookies_to_delete.append(cookie_key)
return basket

def apply_offers_to_basket(self, request, basket):
Expand Down

0 comments on commit 8f776e4

Please sign in to comment.