Skip to content

Commit

Permalink
non-integer quantities now translated to 0 in the cart-update view
Browse files Browse the repository at this point in the history
  • Loading branch information
jessesnyder committed Jul 6, 2012
1 parent 035d017 commit f3fbc04
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion collective/shoppingbehavior/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def update_cart(self, form):
new_qtys = form.get('quantities', [])
for qty_info in new_qtys:
item_id = qty_info['id']
qty = int(qty_info['quantity'])
qty = self._as_integer(qty_info['quantity'])
self.shopper.update_quantity(item_id, qty)

def items(self):
Expand All @@ -211,6 +211,15 @@ def items(self):
contents.append(data)
return contents

def _as_integer(self, value):
# un-castable values translate to 0
try:
qty = int(value)
except ValueError:
qty = 0

return qty

@property
def currency(self):
return u"$"

0 comments on commit f3fbc04

Please sign in to comment.