diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-20 17:00:30 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-20 17:00:30 +0100 |
commit | 6e5370af1f98a3cd2f67b3b730c1b64014be859d (patch) | |
tree | 38c0d6159b266e58f0ed5adac5a3811cfc28682e | |
parent | fce28f5be8ba8831eed5ccf482fa2abf5432ee89 (diff) |
bugfix: bad request if resource doesn't have price object
-rw-r--r-- | alphabetlearning/payments/views.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py index 95eb5c8..f7ab583 100644 --- a/alphabetlearning/payments/views.py +++ b/alphabetlearning/payments/views.py @@ -85,6 +85,8 @@ class ProductLandingPageView(TemplateView): @login_required def add_to_cart(request, resource_id): resource = get_object_or_404(Resource, id=resource_id) + if not resource.price_obj.first(): + return HttpResponseBadRequest(f"There is no price assigned to this resource. Please contact Alphabet Learning Support.") cart, created = ShoppingCart.objects.get_or_create(user=request.user) cart_item, created = CartItem.objects.get_or_create(cart=cart, resource=resource) # cart_item.quantity += 1 @@ -96,10 +98,7 @@ def add_to_cart(request, resource_id): def cart_detail(request): cart, created = ShoppingCart.objects.get_or_create(user=request.user) resources = [i.resource for i in cart.items.all()] - try: - total = sum([r.price_obj.first().price for r in resources]) - except AttributeError: - return HttpResponseBadRequest(f"There is no price assigned to at least one of the resources you have added to the basket. Please contact Alphabet Learning Support.") + total = sum([r.price_obj.first().price for r in resources]) context = { "cart": cart, "resources": resources, |