Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update() logic #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions cart/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,20 @@ def update(self, product, quantity, unit_price=None):
cart=self.cart,
product=product,
)
if quantity:
item.quantity = quantity
if unit_price:
item.unit_price = unit_price
item.save()
else:
item.delete()
except models.Item.DoesNotExist:
raise ItemDoesNotExist

if unit_price:
if quantity: # Maybe user updated 0 to 0. Happens
self.add(product, unit_price, quantity)
else:
raise ItemDoesNotExist

def count(self):
result = 0
for item in self.cart.item_set.all():
Expand Down