aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/payments/views.py
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-10-20 16:42:21 +0100
committerMatthew Lemon <y@yulqen.org>2024-10-20 16:42:21 +0100
commitfce28f5be8ba8831eed5ccf482fa2abf5432ee89 (patch)
tree3f0260c44accb04fa46f1e493bed466fff31c871 /alphabetlearning/payments/views.py
parent791cf758caaf25a9375005bdd7f699e614729823 (diff)
Cart shows items in it; disables buttons if item in basket
- Rough cart icon in navbar - Shows items in cart - Styled dependent on existence - Add to cart buttons disabled if resource in cart, on resource list page and detail page - Throws 404 error if trying add item to cart which has no price - eventually all items will have a price
Diffstat (limited to 'alphabetlearning/payments/views.py')
-rw-r--r--alphabetlearning/payments/views.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/alphabetlearning/payments/views.py b/alphabetlearning/payments/views.py
index d32542b..95eb5c8 100644
--- a/alphabetlearning/payments/views.py
+++ b/alphabetlearning/payments/views.py
@@ -1,5 +1,5 @@
import stripe
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseBadRequest
from django.core.mail import send_mail
from django.conf import settings
from django.contrib.auth.decorators import login_required
@@ -21,9 +21,11 @@ from .models import ShoppingCart
# TODO get the cart integrated with Stripe
# Steps to convert our Cart into something that can be used with Stripe:
#
+# - Fix the total in the cart
# - X Sort out the webhook
# - Associate the purchases with the users profile page
# - We need a profile page!
+# - Link in navbar (when logged in)
# - Fix the email and make it nice
# - Associate each of our resources with a Product item
# - this should be done in the create resource page
@@ -94,7 +96,10 @@ 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()]
- total = sum([r.price_obj.first().price for r in resources])
+ 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.")
context = {
"cart": cart,
"resources": resources,