diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-09 17:34:23 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-09 17:34:23 +0100 |
commit | 52240b9a0c9efaf0d092bfb029b6ca7e74442217 (patch) | |
tree | 25a45dc7b01196a5b0091aaabd95862373ebc68e | |
parent | 677c935fdc3b083a9940a1b2f280cb1ccdbc03bd (diff) |
wip: clicking add to cart button takes you to card detail but thats it
-rw-r--r-- | pyblackbird_cc/payments/tests/test_views.py | 7 | ||||
-rw-r--r-- | pyblackbird_cc/payments/urls.py | 2 | ||||
-rw-r--r-- | pyblackbird_cc/payments/views.py | 4 | ||||
-rw-r--r-- | 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/<int:pk>", views.add_to_cart, name="add_to_cart"), + path("add-to-card/<int:resource_id>", 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 @@ </div> <div class="row align-items-end"> <div class="my-4 d-flex justify-content-center"> - <form action="{% url 'resource:add_to_cart' %}" method="get" accept-charset="utf-8"> + <form action="{% url 'payments:add_to_cart' resource.id %}" method="get" accept-charset="utf-8"> <button class="btn btn-primary w-100"> Add to cart </button> |