Merge pull request #55 from dsaub/copilot/unify-add-to-cart-post

[WIP] Fix inconsistency in add to cart action using POST
This commit is contained in:
Daniel (elordenador)
2026-04-29 11:18:42 +02:00
committed by GitHub
3 changed files with 12 additions and 6 deletions
+5 -3
View File
@@ -196,9 +196,11 @@
<a href="{% url 'producto' product.id %}" class="btn btn-primary btn-sm flex-grow-1"> <a href="{% url 'producto' product.id %}" class="btn btn-primary btn-sm flex-grow-1">
Ver detalles Ver detalles
</a> </a>
<a href="{% url 'add_to_cart' product.id %}" class="btn btn-outline-primary btn-sm"> <form method="post" action="{% url 'add_to_cart' product.id %}" style="display:inline;">
🛒 {% csrf_token %}
</a> <input type="hidden" name="quantity" value="1">
<button type="submit" class="btn btn-outline-primary btn-sm">🛒</button>
</form>
</div> </div>
</div> </div>
</div> </div>
+5 -3
View File
@@ -79,9 +79,11 @@
<a href="{% url 'producto' product.id %}" class="btn btn-primary btn-sm flex-grow-1"> <a href="{% url 'producto' product.id %}" class="btn btn-primary btn-sm flex-grow-1">
Ver detalles Ver detalles
</a> </a>
<a href="{% url 'add_to_cart' product.id %}" class="btn btn-outline-primary btn-sm"> <form method="post" action="{% url 'add_to_cart' product.id %}" style="display:inline;">
🛒 {% csrf_token %}
</a> <input type="hidden" name="quantity" value="1">
<button type="submit" class="btn btn-outline-primary btn-sm">🛒</button>
</form>
</div> </div>
</div> </div>
</div> </div>
+2
View File
@@ -16,6 +16,7 @@ from .vars import (
) )
from django.conf import settings from django.conf import settings
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_POST
from django.urls import reverse from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from decimal import Decimal, ROUND_HALF_UP from decimal import Decimal, ROUND_HALF_UP
@@ -704,6 +705,7 @@ def create_order_from_cart(request, payment_method, payment_reference="", shippi
return order, "" return order, ""
@require_POST
def add_to_cart(request: HttpRequest, product_id: int): def add_to_cart(request: HttpRequest, product_id: int):
"""Agrega un producto al carrito""" """Agrega un producto al carrito"""
try: try: