a falta del pago

This commit is contained in:
2025-11-02 11:57:05 +01:00
parent 51d22515e8
commit 4d451cc85e
17 changed files with 429 additions and 208 deletions

View File

@ -42,6 +42,7 @@ $(() => {
if ($('.product').length === 0) {
$("#alert-empty").removeClass("d-none");
$('.cart-content').addClass('d-none');
$('#btn-checkout').prop('disabled', true);
return;
}
else {
@ -59,7 +60,12 @@ $(() => {
return;
}
$(".alert-shipment").addClass("d-none");
$('#btn-checkout').prop('disabled', false);
if ($("#errorEnvio").hasClass("d-none")) {
$('#btn-checkout').prop('disabled', false);
}
else {
$('#btn-checkout').prop('disabled', true);
}
}
else {
const items = $(".product");
@ -92,7 +98,7 @@ $(() => {
item.find(".alert-icon-shipment").addClass("d-none");
}
}
if (errorFound) {
if (errorFound || $("#errorEnvio").hasClass("d-none") === false) {
$(".alert-shipment").removeClass("d-none");
$('#btn-checkout').prop('disabled', true);
}

View File

@ -1,3 +1,5 @@
import { showLoader, hideLoader } from '../loader.js';
$(() => {
const csrfToken = document.querySelector('meta[name="_csrf"]')?.getAttribute('content');
@ -14,8 +16,139 @@ $(() => {
const modalEl = document.getElementById('direccionFormModal');
const modal = bootstrap.Modal.getOrCreateInstance(modalEl);
$('#addBillingAddressBtn').on('click', seleccionarDireccionEnvio);
async function seleccionarDireccionEnvio() {
const { value: direccionId, isDenied } = await Swal.fire({
title: window.languageBundle['checkout.billing-address.title'] || 'Seleccione una dirección',
html: `
<select id="direccionSelect" class="form-select" style="width: 100%"></select>
`,
showCancelButton: true,
showDenyButton: true,
buttonsStyling: false,
confirmButtonText: window.languageBundle['app.seleccionar'] || 'Seleccionar',
cancelButtonText: window.languageBundle['app.cancelar'] || 'Cancelar',
denyButtonText: window.languageBundle['checkout.billing-address.new-address'] || 'Nueva dirección',
customClass: {
confirmButton: 'btn btn-secondary me-2',
cancelButton: 'btn btn-light',
denyButton: 'btn btn-secondary me-2'
},
focusConfirm: false,
// Inicializa cuando el DOM del modal ya existe
didOpen: () => {
const $select = $('#direccionSelect');
$select.empty(); // limpia placeholder estático
$select.select2({
width: '100%',
dropdownParent: $('.swal2-container'),
ajax: {
url: '/direcciones/facturacion/select2',
dataType: 'json',
delay: 250,
data: params => ({ q: params.term || '' }),
processResults: (data) => {
const items = Array.isArray(data) ? data : (data.results || []);
return {
results: items.map(item => ({
id: item.id,
text: item.text, // ← Select2 necesita 'id' y 'text'
alias: item.alias || 'Sin alias',
att: item.att || '',
direccion: item.direccion || '',
cp: item.cp || '',
ciudad: item.ciudad || '',
html: `
<div>
<strong>${item.alias || 'Sin alias'}</strong><br>
${item.att ? `<small>${item.att}</small><br>` : ''}
<small>${item.direccion || ''}${item.cp ? ', ' + item.cp : ''}${item.ciudad ? ', ' + item.ciudad : ''}</small>
</div>
`
})),
pagination: { more: false } // opcional, evita que espere más páginas
};
}
},
placeholder: window.languageBundle['checkout.billing-address.select-placeholder'] || 'Buscar en direcciones...',
language: language,
templateResult: data => {
if (data.loading) return data.text;
return $(data.html || data.text);
},
// Selección más compacta (solo alias + ciudad)
templateSelection: data => {
if (!data.id) return data.text;
const alias = data.alias || data.text;
const ciudad = data.ciudad ? `${data.ciudad}` : '';
return $(`<span>${alias}${ciudad}</span>`);
},
escapeMarkup: m => m
});
},
preConfirm: () => {
const $select = $('#direccionSelect');
const val = $select.val();
if (!val) {
Swal.showValidationMessage(
window.languageBundle['checkout.billing-address.errors.noAddressSelected'] || 'Por favor, seleccione una dirección.'
);
return false;
}
return val;
},
didClose: () => {
// Limpieza: destruir select2 para evitar fugas
const $select = $('#direccionSelect');
if ($select.data('select2')) {
$select.select2('destroy');
}
}
});
if (isDenied) {
$.get('/direcciones/direction-form', function (html) {
$('#direccionFormModalBody').html(html);
const title = $('#direccionFormModalBody #direccionForm').data('add');
$('#direccionFormModal .modal-title').text(title);
modal.show();
});
}
if (direccionId) {
// Obtén el objeto completo seleccionado
showLoader();
let uri = `/checkout/get-address/${direccionId}`;
const response = await fetch(uri);
if (response.ok) {
const html = await response.text();
$('#direccion-div').append(html);
$('#addBillingAddressBtn').addClass('d-none');
hideLoader();
return true;
}
hideLoader();
return false;
}
hideLoader();
return false;
}
$(document).on('click', '.btn-delete-direccion', function (e) {
e.preventDefault();
const $card = $(this).closest('.direccion-card');
const $div = $card.parent();
$card.remove();
$('#addBillingAddressBtn').removeClass('d-none');
});
});