Skip to content

Commit

Permalink
Add abolity to add held products to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
yumike committed Jan 23, 2012
1 parent 4a9d44b commit a52bfd1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions tinycart/models.py
Expand Up @@ -69,11 +69,11 @@ def get_total_price(self):
total_price = modifier(self, total_price)
return total_price

def add(self, product, quantity=1):
def add(self, product, quantity=1, is_held=False):
item, created = self.items.get_or_create(
product_type = ContentType.objects.get_for_model(product),
product_id = product.pk,
defaults = {'quantity': quantity},
defaults = {'quantity': quantity, 'is_held': is_held},
)
if not created:
item.quantity += quantity
Expand Down
5 changes: 5 additions & 0 deletions tinycart/tests/test_models.py
Expand Up @@ -70,6 +70,11 @@ def test_cart_add(self):
self.assertEqual(cart.items.get().quantity, 6)
self.assertEqual(len(cart.cached_items), 1)

def test_cart_add_held(self):
cart = Cart.objects.get_for_request(self.request)
cart_item = cart.add(Shirt.objects.create(), is_held=True)
self.assertTrue(cart_item.is_held)

def test_cart_price(self):
cart = Cart.objects.get_for_request(self.request)
self.assertEqual(cart.get_price(), Decimal('0.00'))
Expand Down

0 comments on commit a52bfd1

Please sign in to comment.