diff options
-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, |