diff --git a/padelclub_backend/settings.py b/padelclub_backend/settings.py index 7f19c3f..24c7028 100644 --- a/padelclub_backend/settings.py +++ b/padelclub_backend/settings.py @@ -155,6 +155,7 @@ AUTHENTICATION_BACKENDS = [ ] CSRF_COOKIE_SECURE = True # if using HTTPS +SESSION_COOKIE_SECURE = True # Si vous utilisez HTTPS # Stripe Settings STRIPE_PUBLISHABLE_KEY = 'pk_test_51R4LrTPEZkECCx484C2KbmRpcO2ZkZb0NoNi8QJB4X3E5JFu3bvLk4JZQmz9grKbk6O40z3xI8DawHrGyUY0fOT600VEKC9ran' # Replace with your actual key diff --git a/shop/cart.py b/shop/cart.py index 154bc61..76dcec6 100644 --- a/shop/cart.py +++ b/shop/cart.py @@ -16,15 +16,21 @@ def add_to_cart(request, product_id, quantity=1, color_id=None, size_id=None): product = Product.objects.get(id=product_id) cart_id = get_or_create_cart_id(request) + color = Color.objects.get(id=color_id) if color_id else None + size = Size.objects.get(id=size_id) if size_id else None + try: - # Try to get existing cart item - cart_item = CartItem.objects.get(product=product, session_id=cart_id) + # Try to get existing cart item with the same product, color, and size + cart_item = CartItem.objects.get( + product=product, + session_id=cart_id, + color=color, + size=size + ) cart_item.quantity += quantity cart_item.save() except CartItem.DoesNotExist: # Create new cart item - color = Color.objects.get(id=color_id) if color_id else None - size = Size.objects.get(id=size_id) if size_id else None cart_item = CartItem.objects.create( product=product, quantity=quantity, diff --git a/shop/static/shop/css/shop.css b/shop/static/shop/css/shop.css index 09fe917..7d49698 100644 --- a/shop/static/shop/css/shop.css +++ b/shop/static/shop/css/shop.css @@ -131,7 +131,6 @@ /* Cart Table */ .cart-table { width: 100%; - border-collapse: collapse; } .cart-table th, @@ -329,3 +328,28 @@ .color-sample:hover { transform: scale(1.1); } + +.color-display { + display: flex; + align-items: center; + gap: 8px; +} + +.color-sample-cart { + width: 28px; + height: 28px; + border-radius: 50%; + border: 1px solid #ddd; + display: inline-block; +} + +/* Fix for white + sign */ +.quantity-btn { + color: #333; /* Darker text color to ensure visibility */ +} + +.quantity-btn:hover:not([disabled]) { + background-color: #f39200; + color: white; + border-color: #f39200; +} diff --git a/shop/templates/shop/cart.html b/shop/templates/shop/cart.html index 8034405..92aa4ee 100644 --- a/shop/templates/shop/cart.html +++ b/shop/templates/shop/cart.html @@ -5,6 +5,123 @@ {% block second_title %}Plein de goodies !{% endblock %} {% block content %} +
-
+

Votre panier

{% if cart_items %} - + {% for item in cart_items %} - - - - + + - - + - - - - + + + + +
{{ item.product.title }}{{ item.color.name }}{{ item.size.name }} + {{ item.product.title }} +
+
+ {{ item.color.name }} | {{ item.size.name }} +
+
{% csrf_token %} @@ -50,8 +171,8 @@
{{ item.get_total_price }} € + {{ item.get_total_price }} €
{% csrf_token %} @@ -63,30 +184,33 @@
Total:{{ total_quantity }}{{ total }} €{{ total_quantity }} produit(s){{ total }} €
- {% if cart_items %} - Vider le panier - {% endif %} {% if user.is_authenticated %} - - + + {% else %} - - Passer la commande -
-

Connectez-vous pour un paiement plus rapide.

- Se connecter -
+ + Passer la commande +
+

Connectez-vous pour un paiement plus rapide.

+ Se connecter +
{% endif %} +
+ {% if cart_items %} + Vider le panier + {% endif %} +
{% else %}

Votre panier est vide.

diff --git a/shop/templates/shop/product_item.html b/shop/templates/shop/product_item.html index db7d7c6..07568c5 100644 --- a/shop/templates/shop/product_item.html +++ b/shop/templates/shop/product_item.html @@ -1,4 +1,4 @@ -
+
{% if product.image %} {{ product.title }} @@ -32,12 +32,16 @@
{% if product.sizes.exists %} - + {% if product.sizes.all|length == 1 %} + + {% else %} + + {% endif %} {% endif %}
diff --git a/shop/templates/shop/product_list.html b/shop/templates/shop/product_list.html index 22e09e3..9bbcd46 100644 --- a/shop/templates/shop/product_list.html +++ b/shop/templates/shop/product_list.html @@ -21,7 +21,7 @@ diff --git a/shop/views.py b/shop/views.py index bdaba69..5e32c81 100644 --- a/shop/views.py +++ b/shop/views.py @@ -11,6 +11,7 @@ from django.conf import settings from django.urls import reverse from django.http import JsonResponse from django.views.decorators.http import require_POST +from django.views.decorators.csrf import ensure_csrf_cookie from . import cart @@ -109,6 +110,7 @@ def view_cart(request): return render(request, 'shop/cart.html', context) +@ensure_csrf_cookie def add_to_cart_view(request, product_id): """Add a product to the cart""" product = get_object_or_404(Product, id=product_id)