From cc0f9d64e0e70e72b3a0b0ef4f85f2d9ba2cf050 Mon Sep 17 00:00:00 2001 From: Raz Date: Wed, 19 Mar 2025 19:52:06 +0100 Subject: [PATCH] clean up --- shop/cart.py | 9 + shop/forms.py | 2 +- shop/static/shop/css/shop.css | 230 ++++++++++++++++-- shop/templates/shop/cart.html | 37 ++- shop/templates/shop/checkout.html | 46 ++-- shop/templates/shop/payment.html | 8 +- shop/templates/shop/payment_cancel.html | 21 +- shop/templates/shop/payment_success.html | 8 +- shop/urls.py | 2 + shop/views.py | 40 +++ tournaments/templates/registration/login.html | 3 - 11 files changed, 341 insertions(+), 65 deletions(-) diff --git a/shop/cart.py b/shop/cart.py index 9d8e720..154bc61 100644 --- a/shop/cart.py +++ b/shop/cart.py @@ -59,3 +59,12 @@ def clear_cart(request): """Clear the cart""" cart_id = get_or_create_cart_id(request) CartItem.objects.filter(session_id=cart_id).delete() + +# Add this function to your cart.py file +def get_cart_item(request, item_id): + """Get a specific cart item by its ID""" + cart_id = get_or_create_cart_id(request) + try: + return CartItem.objects.get(id=item_id, session_id=cart_id) + except CartItem.DoesNotExist: + raise Exception("Cart item not found") diff --git a/shop/forms.py b/shop/forms.py index c92b4db..a2f264b 100644 --- a/shop/forms.py +++ b/shop/forms.py @@ -2,4 +2,4 @@ from django import forms class GuestCheckoutForm(forms.Form): email = forms.EmailField(required=True) - phone = forms.CharField(max_length=20, required=True) + phone = forms.CharField(max_length=20, required=True, label="Téléphone portable") diff --git a/shop/static/shop/css/shop.css b/shop/static/shop/css/shop.css index 95e02d8..8fc4e4a 100644 --- a/shop/static/shop/css/shop.css +++ b/shop/static/shop/css/shop.css @@ -1,3 +1,4 @@ +/* Product Display */ .options-container { display: grid; grid-template-columns: 1fr 1fr 1fr; @@ -18,15 +19,16 @@ } .product-title { - font-size: 16px; /* Increase the font size for a bigger title */ - font-weight: bold; /* Make the title bold */ + font-size: 16px; + font-weight: bold; } .product-price { - font-size: 16px; /* Increase the font size for a bigger title */ - font-weight: bold; /* Make the title bold */ + font-size: 16px; + font-weight: bold; } +/* Grid Layout */ .option-element { align-content: center; } @@ -47,10 +49,12 @@ grid-column: 1; grid-row: 2; } + .option-element:nth-child(4) { grid-column: 2; grid-row: 2; } + .option-element:nth-child(5) { grid-column: 3; grid-row: 2; @@ -60,30 +64,38 @@ grid-column: 1 / span 2; grid-row: 3; } + .option-element:nth-child(7) { grid-column: 3; grid-row: 3; text-align: right; } +/* Buttons */ +.add-to-cart-button, +.checkout-button { + background-color: #90ee90; + color: #707070; + border: none; + border-radius: 12px; + font-size: 12px; + font-weight: 600; + text-decoration: none; + transition: background-color 0.3s ease; + cursor: pointer; +} + .add-to-cart-button { margin-top: 10px; width: 100%; - background-color: #90ee90; /* Green background */ text-align: center; display: inline-block; - height: 40px; /* Set the height to 40 pixels */ - transition: background-color 0.3s ease; /* Smooth transition on hover */ - color: #707070; - border-radius: 12px; - text-decoration: none; - font-size: 12px; - font-weight: 600; + height: 40px; } -.add-to-cart-button:hover { - background-color: #f39200; - color: white; +.checkout-button { + padding: 10px 20px; + display: inline-block; } .confirm-nav-button { @@ -95,12 +107,51 @@ color: white; } +.remove-btn { + background-color: #e84039; + color: white; + border: none; + padding: 5px 10px; + border-radius: 12px; + cursor: pointer; + font-size: 12px; + font-weight: 600; + transition: background-color 0.3s ease; +} + +.add-to-cart-button:hover, .confirm-nav-button:hover, -.cancel-nav-button:hover { - background-color: orange; +.cancel-nav-button:hover, +.remove-btn:hover { + background-color: #f39200; color: white; } +/* Cart Table */ +.cart-table { + width: 100%; + border-collapse: collapse; +} + +.cart-table th, +.cart-table td { + padding: 10px; + text-align: center; +} + +.text-left { + text-align: left !important; +} + +.price-column { + text-align: right; +} + +.cart-table thead, +.cart-table tfoot { + background-color: #f5f5f5; +} + .cart-table tbody tr.odd { background-color: #f0f0f0; } @@ -109,11 +160,6 @@ background-color: #e8e8e8; } -.cart-table th.price-column, -.cart-table td.price-column { - text-align: right; -} - .cart-table tfoot .total-label { font-weight: bold; } @@ -122,3 +168,143 @@ font-weight: bold; font-size: 1.2em; } + +/* Quantity Controls */ +.quantity-controls { + display: flex; + align-items: center; + justify-content: center; +} + +.quantity-form { + display: flex; + align-items: center; +} + +.quantity-btn { + width: 28px; + height: 28px; + border-radius: 50%; + border: 1px solid #ddd; + background-color: #f8f8f8; + cursor: pointer; + font-weight: bold; + display: flex; + align-items: center; + justify-content: center; + padding: 0; + margin: 0 3px; + font-size: 16px; + transition: background-color 0.3s ease; +} + +.quantity-btn:hover:not([disabled]) { + background-color: #f39200; + color: white; + border-color: #f39200; +} + +.quantity-btn:disabled { + opacity: 0.5; + cursor: not-allowed; +} + +.quantity-value { + margin: 0 5px; + min-width: 20px; + text-align: center; + font-weight: bold; + font-size: 14px; +} + +/* Cart Summary & Checkout */ +.cart-summary { + margin-top: 20px; + display: flex; + justify-content: space-between; + align-items: center; + flex-wrap: wrap; +} + +.guest-checkout-notice { + margin-top: 10px; + font-size: 0.9em; + background-color: #f8f9fa; + padding: 10px; + border-radius: 10px; + width: 100%; +} + +/* Checkout Page */ +.checkout-container { + padding: 25px; +} + +.checkout-section { + margin-bottom: 25px; +} + +.checkout-title { + color: #333; + font-size: 1.4em; + margin-bottom: 15px; + text-align: center; +} + +.checkout-description { + text-align: center; + margin-bottom: 20px; + color: #666; +} + +.guest-checkout-form { + background-color: #f8f9fa; + padding: 20px; + border-radius: 10px; + margin-bottom: 20px; +} + +.form-fields p { + margin-bottom: 15px; +} + +.form-fields label { + display: block; + margin-bottom: 5px; + font-weight: bold; +} + +.form-fields input { + width: 100%; + padding: 10px; + border: 1px solid #ddd; + border-radius: 8px; + font-size: 1em; +} + +.button-container { + display: flex; + justify-content: center; + margin-top: 20px; +} + +.checkout-options { + text-align: center; +} + +.checkout-options p { + margin: 15px 0; +} + +/* Links */ +.styled-link { + color: #f39200; + text-decoration: none; + font-weight: bold; + transition: color 0.3s; +} + +.styled-link:hover { + color: #e84039; + text-decoration: underline; +} diff --git a/shop/templates/shop/cart.html b/shop/templates/shop/cart.html index 8c0c971..f9717d2 100644 --- a/shop/templates/shop/cart.html +++ b/shop/templates/shop/cart.html @@ -25,47 +25,66 @@ - + + {% for item in cart_items %} - + - + + {% endfor %} - - + + +
ProduitProduit Couleur Taille Quantité PrixActions
{{ item.product.title }}{{ item.product.title }} {{ item.color.name }} {{ item.size.name }}{{ item.quantity }} +
+
+ {% csrf_token %} + + + {{ item.quantity }} + +
+
+
{{ item.get_total_price }} € +
+ {% csrf_token %} + + +
+
Total:{{ cart_items.total_quantity }}Total:{{ total_quantity }} {{ total }} €
{% if cart_items %} - Vider le panier + Vider le panier {% endif %} {% if user.is_authenticated %} - + {% else %} - Passer la commande + Passer la commande

Connectez-vous pour un paiement plus rapide.

- Se connecter + Se connecter
{% endif %}
diff --git a/shop/templates/shop/checkout.html b/shop/templates/shop/checkout.html index 97a1ad7..53836e9 100644 --- a/shop/templates/shop/checkout.html +++ b/shop/templates/shop/checkout.html @@ -17,29 +17,37 @@ Se connecter {% endif %} -

Votre panier

+

Validation de la commande

-
+
{% if request.user.is_authenticated %} -

Vous êtes déjà connecté en tant que {{ request.user.email }}.

- Passer à la commande +
+

Vous êtes déjà connecté en tant que {{ request.user.email }}.

+ Passer à la commande +
{% else %} -

Vous n'êtes pas connecté. Veuillez choisir une option :

- -
- {% csrf_token %} - {{ form.as_p }} - -
- -
- -

Ou connectez-vous si vous avez déjà un compte.

- -
- -

Pas encore de compte ? Créez-en un maintenant

+
+

Finaliser votre commande

+

Vous n'êtes pas connecté. Veuillez choisir une option :

+
+ +
+
+ {% csrf_token %} +
+ {{ form.as_p }} +
+
+ +
+
+
+ +
+

Ou connectez-vous si vous avez déjà un compte.

+

Pas encore de compte ? Créez-en un maintenant

+
{% endif %}
diff --git a/shop/templates/shop/payment.html b/shop/templates/shop/payment.html index 6b3bddf..d98ef82 100644 --- a/shop/templates/shop/payment.html +++ b/shop/templates/shop/payment.html @@ -27,7 +27,7 @@ - + @@ -37,7 +37,7 @@ {% for item in order_items %} - + @@ -47,7 +47,7 @@ - + @@ -56,7 +56,7 @@
- +
diff --git a/shop/templates/shop/payment_cancel.html b/shop/templates/shop/payment_cancel.html index f1b6e4c..7c2d8c9 100644 --- a/shop/templates/shop/payment_cancel.html +++ b/shop/templates/shop/payment_cancel.html @@ -1,18 +1,33 @@ {% extends 'tournaments/base.html' %} -{% block head_title %}Paiement annulé{% endblock %} +{% block head_title %}La boutique{% endblock %} +{% block first_title %}La boutique Padel Club{% endblock %} +{% block second_title %}Paiement annulé{% endblock %} {% block content %} + + +
-

Paiement annulé

+

Paiement

Le paiement a été annulé

Votre commande n'a pas été finalisée car le paiement a été annulé.

diff --git a/shop/templates/shop/payment_success.html b/shop/templates/shop/payment_success.html index ef9222b..33de0f3 100644 --- a/shop/templates/shop/payment_success.html +++ b/shop/templates/shop/payment_success.html @@ -30,7 +30,7 @@
ProduitProduit Couleur Taille Quantité
{{ item.product.title }}{{ item.product.title }} {{ item.color.name|default:"N/A" }} {{ item.size.name|default:"N/A" }} {{ item.quantity }}
Total:Total: {{ order_items.count }} {{ order.total_price }} €
- + @@ -40,7 +40,7 @@ {% for item in order_items %} - + @@ -50,7 +50,7 @@ - + @@ -58,7 +58,7 @@
ProduitProduit Couleur Taille Quantité
{{ item.product.title }}{{ item.product.title }} {{ item.color.name|default:"N/A" }} {{ item.size.name|default:"N/A" }} {{ item.quantity }}
Total:Total: {{ order_items.count }} {{ total }} €
diff --git a/shop/urls.py b/shop/urls.py index 95d94b4..1c00daf 100644 --- a/shop/urls.py +++ b/shop/urls.py @@ -18,5 +18,7 @@ urlpatterns = [ path('payment/cancel//', views.payment_cancel, name='payment_cancel'), # path('webhook/stripe/', views.stripe_webhook, name='stripe_webhook'), path('create-checkout-session/', views.create_checkout_session, name='create_checkout_session'), + path('cart/update-item/', views.update_cart_item, name='update_cart_item'), + path('cart/remove-item/', views.remove_from_cart, name='remove_from_cart'), ] diff --git a/shop/views.py b/shop/views.py index 4c9ba75..bdaba69 100644 --- a/shop/views.py +++ b/shop/views.py @@ -344,3 +344,43 @@ def create_checkout_session(request): return JsonResponse({'id': checkout_session.id}) except Exception as e: return JsonResponse({'error': str(e)}, status=400) + +@require_POST +def update_cart_item(request): + """Update a cart item quantity (increase/decrease)""" + item_id = request.POST.get('item_id') + action = request.POST.get('action') + + try: + cart_item = cart.get_cart_item(request, item_id) + + if action == 'increase': + # Increase quantity by 1 + cart_item.quantity += 1 + cart_item.save() + messages.success(request, "Quantity increased.") + + elif action == 'decrease' and cart_item.quantity > 1: + # Decrease quantity by 1 + cart_item.quantity -= 1 + cart_item.save() + messages.success(request, "Quantity decreased.") + + except Exception as e: + messages.error(request, f"Error updating cart: {str(e)}") + + return redirect('shop:view_cart') + +@require_POST +def remove_from_cart(request): + """Remove an item from cart by item_id""" + item_id = request.POST.get('item_id') + + try: + cart_item = cart.get_cart_item(request, item_id) + cart_item.delete() + messages.success(request, "Item removed from cart.") + except Exception as e: + messages.error(request, f"Error removing item: {str(e)}") + + return redirect('shop:view_cart') diff --git a/tournaments/templates/registration/login.html b/tournaments/templates/registration/login.html index ba26166..66e056a 100644 --- a/tournaments/templates/registration/login.html +++ b/tournaments/templates/registration/login.html @@ -43,9 +43,6 @@

Pas encore de compte ? Créer le tout de suite !

- {% for message in messages %} -
{{ message }}
- {% endfor %}