From 52240b9a0c9efaf0d092bfb029b6ca7e74442217 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Wed, 9 Oct 2024 17:34:23 +0100 Subject: wip: clicking add to cart button takes you to card detail but thats it --- pyblackbird_cc/payments/tests/test_views.py | 7 +++++-- pyblackbird_cc/payments/urls.py | 2 +- pyblackbird_cc/payments/views.py | 4 ++-- pyblackbird_cc/templates/resources/resource_detail.html | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pyblackbird_cc/payments/tests/test_views.py b/pyblackbird_cc/payments/tests/test_views.py index 0b469b5..7d0f8b5 100644 --- a/pyblackbird_cc/payments/tests/test_views.py +++ b/pyblackbird_cc/payments/tests/test_views.py @@ -12,5 +12,8 @@ def test_cart_view(client, user): @pytest.mark.django_db -def test_add_resource_to_cart(resource, user): - url = reverse("payments:add_to_cart", args=[resource.pk]) +def test_add_resource_to_cart(client, resource, user): + url = reverse("payments:add_to_cart", kwargs={"resource_id": resource.id}) + client.force_login(user) + response = client.get(url) + assert response.status_code == 200 diff --git a/pyblackbird_cc/payments/urls.py b/pyblackbird_cc/payments/urls.py index d294aab..72f6678 100644 --- a/pyblackbird_cc/payments/urls.py +++ b/pyblackbird_cc/payments/urls.py @@ -15,7 +15,7 @@ urlpatterns = [ views.CreateCheckoutSessionView.as_view(), name="create-checkout-session", ), - path("add-to-card/", views.add_to_cart, name="add_to_cart"), + path("add-to-card/", views.add_to_cart, name="add_to_cart"), path("landing/", views.ProductLandingPageView.as_view(), name="landing"), # path("webhook/", views.webhook, name="webhook"), ] diff --git a/pyblackbird_cc/payments/views.py b/pyblackbird_cc/payments/views.py index 6863869..6ca31d8 100644 --- a/pyblackbird_cc/payments/views.py +++ b/pyblackbird_cc/payments/views.py @@ -55,9 +55,9 @@ def add_to_cart(request, resource_id): resource = get_object_or_404(Resource, id=resource_id) 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 + # cart_item.quantity += 1 cart_item.save() - return redirect("cart_detail") + return render(request, "payments/cart_detail.html", {"cart": cart}) @login_required diff --git a/pyblackbird_cc/templates/resources/resource_detail.html b/pyblackbird_cc/templates/resources/resource_detail.html index 48d7efb..6c6ceda 100644 --- a/pyblackbird_cc/templates/resources/resource_detail.html +++ b/pyblackbird_cc/templates/resources/resource_detail.html @@ -48,7 +48,7 @@
-
+ -- cgit v1.2.3