falta actualizar bien el resumen

This commit is contained in:
2025-10-30 19:48:26 +01:00
parent feff9ee94a
commit 167c136dca
28 changed files with 518 additions and 342 deletions

View File

@ -24,7 +24,10 @@ $(() => {
$(this).find('.item-tirada').attr('name', 'direcciones[' + i + '].unidades');
});
$.post(form.attr('action'), form.serialize(), (response) => {
// handle response
// if success and received html, replace container summary
if (response) {
$('.cart-summary-container').replaceWith(response);
}
}).always(() => {
hideLoader();
});

View File

@ -10,7 +10,7 @@ $(() => {
$('.nav-product').addClass('d-none');
document.querySelectorAll('.card.product').forEach(card => {
const detailsBtn = card.querySelector('.nav-link[id^="pills-details-"][id$="-tab"]');
if (detailsBtn) $(new bootstrap.Tab(detailsBtn)).removeClass('d-none');
if (detailsBtn) new bootstrap.Tab(detailsBtn).show();
});
$('#shippingAddressesContainer').empty().removeClass('d-none');
$('.shipping-addresses-item').toArray().forEach(element => {
@ -235,7 +235,7 @@ $(() => {
return false;
}
}
else if(presupuestoId == null){ // caso para todas los envios a la misma direccion
else if (presupuestoId == null && direccionId) { // caso para todas los envios a la misma direccion
const isPaletsValue = await getTipoEnvio();
if (isPaletsValue !== null) {
isPalets = isPaletsValue ? 1 : 0;
@ -285,13 +285,13 @@ $(() => {
value="${tirada}" class="form-control text-center">
</div>
<div class="form-check form-switch form-switch-custom mb-3 d-flex align-items-center justify-content-center ps-0">
<input type="checkbox"
id="swal-input-palets"
class="form-check-input ms-0 me-2 float-none">
<label for="swal-input-palets" class="form-check-label mb-0">
${window.languageBundle['cart.shipping.send-in-palets'] || 'Enviar en palets'}
</label>
</div>
<input type="checkbox"
id="swal-input-palets"
class="form-check-input ms-0 me-2 float-none">
<label for="swal-input-palets" class="form-check-label mb-0">
${window.languageBundle['cart.shipping.send-in-palets'] || 'Enviar en palets'}
</label>
</div>
<span class="form-text text-muted">
${window.languageBundle['cart.shipping.send-in-palets.info'] || 'En palets la entrega se realizará a pie de calle.'}
</span>
@ -327,19 +327,19 @@ $(() => {
}
async function getTipoEnvio() {
const { value: checkValue } = await Swal.fire({
const { isConfirmed, value } = await Swal.fire({
title: window.languageBundle['cart.shipping.tipo-envio'] || 'Tipo de envío',
html: `
<div class="form-check form-switch form-switch-custom my-3 d-flex align-items-center justify-content-center gap-2">
<input type="checkbox" class="form-check-input" id="swal-input-palets">
<label for="swal-input-palets" class="form-label mb-0">
<div class="form-check form-switch form-switch-custom my-3 d-flex align-items-center justify-content-center gap-2">
<input type="checkbox" class="form-check-input" id="swal-input-palets">
<label for="swal-input-palets" class="form-label mb-0">
${window.languageBundle['cart.shipping.send-in-palets'] || 'Enviar en palets'}
</label>
</div>
<span class="form-text text-muted">
${window.languageBundle['cart.shipping.send-in-palets.info'] || 'En palets la entrega se realizará a pie de calle.'}
</span>
`,
</label>
</div>
<span class="form-text text-muted">
${window.languageBundle['cart.shipping.send-in-palets.info'] || 'En palets la entrega se realizará a pie de calle.'}
</span>
`,
focusConfirm: false,
showCancelButton: true,
buttonsStyling: false,
@ -350,17 +350,18 @@ $(() => {
confirmButtonText: window.languageBundle['app.aceptar'] || 'Aceptar',
cancelButtonText: window.languageBundle['app.cancelar'] || 'Cancelar',
preConfirm: () => {
const isPalets = document.getElementById('swal-input-palets').checked;
return isPalets;
const popup = Swal.getPopup();
const chk = popup.querySelector('#swal-input-palets');
// Devuelve un OBJETO (siempre truthy) con el booleano dentro
return { isPalets: !!chk?.checked };
}
});
if (checkValue !== undefined) {
return checkValue; // boolean
}
return null; // Si se cancela el Swal
if (!isConfirmed) return null; // cancelado
return value.isPalets; // true / false
}
function checkTotalUnits(container, tirada) {
const totalUnits = container.find('.direccion-card').toArray().reduce((acc, el) => {