Arreglado un problema visual del precio 6.1000000000000005 tipo a si
This commit is contained in:
@@ -85,20 +85,24 @@
|
||||
alert("¡Por favor, selecciona un personaje antes de añadir un ítem al carrito!");
|
||||
return;
|
||||
}
|
||||
|
||||
carrito.push({ id, nombre, precio });
|
||||
|
||||
carrito.push({ id, nombre, precio: parseFloat(precio) }); // Convertir precio a float
|
||||
actualizarCarrito();
|
||||
}
|
||||
|
||||
function actualizarCarrito() {
|
||||
carritoLista.innerHTML = "";
|
||||
let total = 0;
|
||||
|
||||
carrito.forEach((item, index) => {
|
||||
total += item.precio;
|
||||
const itemCarrito = `<li class="real-info-box">${item.nombre} - ${item.precio} monedas <button class="real-info-box red-info" onclick="eliminarDelCarrito(${index})">Eliminar</button></li>`;
|
||||
const itemCarrito = `<li class="real-info-box">${item.nombre} - ${item.precio.toFixed(2)} monedas
|
||||
<button class="real-info-box red-info" onclick="eliminarDelCarrito(${index})">Eliminar</button>
|
||||
</li>`;
|
||||
carritoLista.innerHTML += itemCarrito;
|
||||
});
|
||||
totalElement.textContent = total;
|
||||
|
||||
totalElement.textContent = total.toFixed(2);
|
||||
totalIVAElement.textContent = (total * 1.21).toFixed(2);
|
||||
}
|
||||
|
||||
@@ -112,25 +116,25 @@
|
||||
});
|
||||
|
||||
document.getElementById("comprar").addEventListener("click", () => {
|
||||
const personajeSeleccionado = document.getElementById("personaje").value;
|
||||
const personajeSeleccionado = document.getElementById("personaje").value;
|
||||
|
||||
if (!personajeSeleccionado) {
|
||||
alert("¡Por favor, selecciona un personaje antes de continuar!");
|
||||
return;
|
||||
}
|
||||
if (!personajeSeleccionado) {
|
||||
alert("¡Por favor, selecciona un personaje antes de continuar!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (carrito.length === 0) {
|
||||
alert("El carrito está vacío");
|
||||
return;
|
||||
}
|
||||
|
||||
if (carrito.length === 0) {
|
||||
alert("El carrito está vacío");
|
||||
} else {
|
||||
// Crear la sesión de pago con Stripe
|
||||
fetch('/es/store-novawow/', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
character: personajeSeleccionado, // Añadir el personaje seleccionado
|
||||
carrito: carrito, // Si necesitas enviar los ítems del carrito, también puedes incluirlos aquí
|
||||
character: personajeSeleccionado,
|
||||
carrito: carrito,
|
||||
}),
|
||||
})
|
||||
.then(response => response.json())
|
||||
@@ -143,7 +147,7 @@
|
||||
}
|
||||
})
|
||||
.catch(error => console.error("Error al crear la sesión de pago:", error));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
cargarItems("Bolsas");
|
||||
</script>
|
||||
|
||||
+16
-12
@@ -17,7 +17,7 @@ from .library_correo import enviar_correo
|
||||
from django.utils.crypto import get_random_string
|
||||
from django.conf import settings
|
||||
from django.utils.timezone import now
|
||||
from decimal import Decimal
|
||||
from decimal import Decimal, ROUND_HALF_UP
|
||||
|
||||
# Configuración del logger
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -1753,9 +1753,9 @@ def store_novawow_view(request):
|
||||
username = request.session.get('username')
|
||||
if not username:
|
||||
return redirect('login')
|
||||
|
||||
|
||||
category_name = request.GET.get("category")
|
||||
|
||||
|
||||
# Obtener personajes del usuario desde la base de datos acore_characters
|
||||
with connections['acore_characters'].cursor() as cursor:
|
||||
cursor.execute("""
|
||||
@@ -1772,7 +1772,7 @@ def store_novawow_view(request):
|
||||
# Obtener categorías e ítems
|
||||
categories = Category.objects.prefetch_related("items").all()
|
||||
store_data = {category.name: list(category.items.values()) for category in categories}
|
||||
|
||||
|
||||
# Si se está solicitando una categoría específica, devolver solo los ítems de esa categoría
|
||||
if category_name:
|
||||
items_in_category = Category.objects.get(name=category_name).items.values()
|
||||
@@ -1780,7 +1780,10 @@ def store_novawow_view(request):
|
||||
|
||||
# Obtener carrito desde la sesión
|
||||
carrito = request.session.get('carrito', [])
|
||||
total_price = sum(Decimal(item['precio']) for item in carrito) * Decimal('1.21')
|
||||
|
||||
# ✅ Calcular el precio total con 2 decimales
|
||||
total_price = sum(Decimal(item['precio']) for item in carrito)
|
||||
total_price_with_iva = (total_price * Decimal('1.21')).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
|
||||
if request.method == 'POST':
|
||||
# Obtener datos del body
|
||||
@@ -1791,12 +1794,13 @@ def store_novawow_view(request):
|
||||
if not character_name:
|
||||
return JsonResponse({'success': False, 'message': 'Por favor, selecciona un personaje.'})
|
||||
|
||||
# ✅ ACTUALIZAR EL CARRITO ANTES DE CALCULAR EL PRECIO
|
||||
# ✅ ACTUALIZAR EL CARRITO Y FORZAR LA SESIÓN
|
||||
request.session['carrito'] = carrito
|
||||
request.session.modified = True # Forzar que Django guarde la sesión inmediatamente
|
||||
|
||||
# ✅ CALCULAR EL PRECIO CON EL CARRITO ACTUALIZADO
|
||||
total_price = sum(Decimal(item['precio']) for item in carrito) * Decimal('1.21')
|
||||
|
||||
# ✅ RECALCULAR EL PRECIO CON EL CARRITO ACTUALIZADO
|
||||
total_price = sum(Decimal(item['precio']) for item in carrito)
|
||||
total_price_with_iva = (total_price * Decimal('1.21')).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
|
||||
# Verificar si el personaje pertenece al usuario
|
||||
if character_name not in characters:
|
||||
@@ -1805,7 +1809,7 @@ def store_novawow_view(request):
|
||||
# Crear sesión de pago con Stripe
|
||||
success_url = request.build_absolute_uri(reverse('store-novawow/success'))
|
||||
cancel_url = request.build_absolute_uri(reverse('store-novawow/cancel'))
|
||||
stripe_response = create_checkout_session(total_price, success_url=success_url, cancel_url=cancel_url)
|
||||
stripe_response = create_checkout_session(total_price_with_iva, success_url=success_url, cancel_url=cancel_url)
|
||||
|
||||
if stripe_response["success"]:
|
||||
request.session['store_novawow'] = character_name
|
||||
@@ -1821,9 +1825,9 @@ def store_novawow_view(request):
|
||||
'characters': characters,
|
||||
'store_data': store_data,
|
||||
'categories': categories,
|
||||
'total_price': total_price
|
||||
'total_price': total_price_with_iva
|
||||
})
|
||||
|
||||
|
||||
def store_novawow_success_view(request):
|
||||
# Procesar el comando SOAP tras el pago exitoso
|
||||
character_name = request.session.get('store_novawow')
|
||||
|
||||
Reference in New Issue
Block a user