jQuery.ajaxSetup({ headers: { 'X-CSRF-TOKEN': jQuery('meta[name="csrf-token"]').attr('content') } }); function validateSession(data){ // debugger ret = false; data["href"] = location.href; $.ajax({ 'url': default_url+'/ajax', 'type': 'post', 'async': false, 'data': { 'type': 'isauth', 'params': data }, 'success': function(response){ res = JSON.parse(response); ret = res.logued; if(!res.logued){ $('#loginModal input[name="url"]').val(res.href); $("#loginModal").modal('show'); } } }); return ret; } Livewire.on('alertResolution', () => { Swal.fire({ title: "Por favor intente más tarde.", text: "En estos momentos no es posible seguir con la compra.", icon: "info" }); }); Livewire.on('pickupError', (data) => { Swal.fire({ title: "Ups!", text: data.message, icon: "info" }); }); function updateCartbag(){ $.ajax({ 'url': default_url+'/cart/ajax', 'type': 'post', 'async': false, 'data': { 'type': 'select' }, 'success': function(response){ ret = JSON.parse(response); // console.log('update total',ret); $(".cartbagqty").text(ret.qty); $(".cartbagtotal").text('$ '+ret.total); } }); } function updateFavoritebag(){ $.ajax({ 'url': default_url+'/ajax', 'type': 'post', 'async': false, 'data': { 'type': 'update-favorite' }, 'success': function(response){ ret = JSON.parse(response); $(".favoritebagqty").text(ret.length); } }); } jQuery(document).ready(function($){ $('#city_master').on('change', function () { const city = $(this).val(); const actionUrl = default_url + '/search_city'; if(city != ''){ $.ajax({ type: 'POST', url: actionUrl, data: { data: city, _token: $('input[name="_token"]').val() // Agregar CSRF token }, success: function (response) { Swal.fire({ title: 'OK', text: 'No se pudo procesar la solicitud '+ response.city.name, confirmButtonText: 'OK' }); window.location.href = "/"; }, error: function (xhr) { console.error('Error:', xhr.responseText); Swal.fire({ title: 'Error', text: 'No se pudo procesar la solicitud', icon: 'error', confirmButtonText: 'OK' }); } }); } }); /** OFF-CANVAS */ $(document).on('click', '.pull-bs-canvas-right, .pull-bs-canvas-left', function(){ $('body').prepend('
'); if($(this).hasClass('pull-bs-canvas-right')) $('.bs-canvas-right').addClass('mr-0'); else $('.bs-canvas-left').addClass('ml-0'); return false; }); /** OFF-CANVAS */ $('.hero__search__categories__all').on('click', function(){ $('.hero__search__categories ul').slideToggle(400); }); $("body").on('click', ".gotopay, .gotofav", function(){ return validateSession({ 'href': $(this).attr('href') }); }); $(document).ready(function () { $("body").on('click', ".addCart", function (e) { e.preventDefault(); let data = { "id": $(this).attr("data-p-id"), "cant": $(this).attr("data-p-cant"), "company_id": $(this).attr("data-p-company_id"), "requires_delivery": $(this).attr("data-p-delivery") }; $.ajax({ url: default_url + '/cart/add', type: 'post', async: false, data: { data: data }, success: function (response) { if (response.hasOwnProperty('show_delivery_modal') && response.show_delivery_modal) { $('#overlay').show(); $('#delivery').show(); return false; } if (response.hasOwnProperty('show_delivery_modal_confirm') && response.show_delivery_modal_confirm) { $('.address').text(response.location.address); $('#overlay').show(); $('#confirm__method__delivery').show(); return false; } if (response.hasOwnProperty('quantity_not_available')) { window.livewire.emit('quantity_not_available'); return false; } if(response.hasOwnProperty('presentation_not_city')){ toastr.error('Su producto pertenece a un comercio que no tiene cobertura en la ciudad seleccionada.', { closeButton: true, progressBar: true, positionClass: "toast-top-right", timeOut: 5000 }); } if (response.hasOwnProperty('addCart')) { toastr.success('Su producto fue agregado al carrito.', 'Carrito de compras', { closeButton: true, progressBar: true, positionClass: "toast-top-right", timeOut: 5000 }); window.livewire.emit('render', 'shop-menu'); updateCartbag(); } // else { // toastr.error('El producto no se encuentra disponible para compra.', 'Carrito de compras', { // closeButton: true, // progressBar: true, // positionClass: "toast-top-right" // }); // } }, error: function () { toastr.error('No se puede agregar el producto al carrito.', 'Carrito de compras', { closeButton: true, progressBar: true, positionClass: "toast-top-right" }); location.href = location.href; } }); }); $('.header__logo a').on('click', function(e) { e.preventDefault(); $.ajax({ url: default_url + '/ajax', type: "POST", data: { type: 'reload', }, beforeSend: function() { // Swal.fire({ // title: "Recargando sitio", // text: "Por favor, espere mientras recargamos el sitio.", // didOpen: () => { // Swal.showLoading(); // } // }); }, success: function(response) { response = JSON.parse(response); window.location = '/'; }, error: function(xhr) { window.location = '/'; } }); }); }); $(".removeitemcart").on('click', function(){ _this = $(this); id = _this.attr("data-c-id"); // console.log(id); $.ajax({ 'url': default_url+'/cart/remove', 'type': 'post', 'async': false, 'data': { 'id': id }, 'success': function(response){ location.href = location.href; } }); }); $("body").on('click', ".addFavorite", function (e){ e.preventDefault(); data = { "id": $(this).attr("data-p-id"), "cant": $(this).attr("data-p-cant"), // "price": $(this).attr("data-p-price"), }; val = validateSession(data); if(val == true){ $.ajax({ 'url': default_url+'/ajax', 'type': 'post', 'async': false, 'data': { 'type': 'add-favorite', 'data': data }, 'success': function(response){ ret = JSON.parse(response); if(ret){ toastr.success('Su producto fue agregado a favoritos.', 'Favoritos', { closeButton: true, progressBar: true, positionClass: "toast-top-right", timeOut: 5000 }); window.livewire.emit('render', 'shop-menu'); updateFavoritebag(); } else { toastr.error('El producto no se puede agregar a favoritos.', 'Favoritos', { closeButton: true, progressBar: true, positionClass: "toast-top-right" }); } }, 'error': function(){ toastr.error('No se puede agregar el producto a favoritos.', 'Favoritos', { closeButton: true, progressBar: true, positionClass: "toast-top-right" }); } }); } }); $("body").on('click', ".removeFavorite", function (e){ e.preventDefault(); data = { "id": $(this).attr("data-p-id"), }; val = validateSession(data); if(val == true){ $.ajax({ 'url': default_url+'/ajax', 'type': 'post', 'async': false, 'data': { 'type': 'removefavorite', 'data': data }, 'success': function(response){ ret = JSON.parse(response); if(ret){ toastr.success('Favorito eliminado correctamente.', 'Favorito', { closeButton: true, progressBar: true, positionClass: "toast-top-right", timeOut: 5000 }); window.livewire.emit('render', 'shop-menu'); updateFavoritebag(); location.reload(); } else { toastr.error('El producto no se puede eliminar de favoritos.', 'Favoritos', { closeButton: true, progressBar: true, positionClass: "toast-top-right" }); } }, 'error': function(){ toastr.error('No se puede eliminar el producto de favoritos.', 'Favoritos', { closeButton: true, progressBar: true, positionClass: "toast-top-right" }); } }); } }); /*Validación NIT código de verificación checkout*/ const tipodoc = document.getElementById('tipodoc'); const documento = document.getElementById('documento'); const dv = document.getElementById('dv'); // Función para calcular el dígito verificador (DV) function calcularDigitoVerificacion(myNit) { var vpri, x, y, z; myNit = myNit.replace(/\s/g, "").replace(/,/g, "").replace(/\./g, "").replace(/-/g, ""); if (isNaN(myNit)) return ""; vpri = new Array(16); vpri[1] = 3; vpri[2] = 7; vpri[3] = 13; vpri[4] = 17; vpri[5] = 19; vpri[6] = 23; vpri[7] = 29; vpri[8] = 37; vpri[9] = 41; vpri[10] = 43; vpri[11] = 47; vpri[12] = 53; vpri[13] = 59; vpri[14] = 67; vpri[15] = 71; x = 0; z = myNit.length; for (var i = 0; i < z; i++) { y = myNit.substr(i, 1); x += (y * vpri[z - i]); } y = x % 11; return (y > 1) ? 11 - y : y; } // Evento para calcular el DV en tiempo real if(documento){ documento.addEventListener('input', () => { if (tipodoc.value === '4' && documento.value.match(/^\d+$/)) { dv.value = calcularDigitoVerificacion(documento.value); } else { dv.value = ''; } }); } if(tipodoc){ // Limpiar el DV si se cambia el tipo de documento tipodoc.addEventListener('change', () => { if (tipodoc.value !== '4') { dv.value = ''; } }); } $(document).ready(function () { // Mostrar/ocultar la lista $(".select-delivery-city-matrix").on('click', function () { $(".autocomplete_list_matrix").toggle(); }); }); $(".autocomplete_list_matrix li").on('click', function () { let cityName = $(this).data('name'); // obtener el nombre de la ciudad let selectCity = $(".select-delivery-city-matrix"); let icon = $("").addClass("icon_pin_alt"); // corregido sin espacio selectCity.text(''); selectCity.append(icon).append(cityName); $(".autocomplete_list_matrix").hide(); let containName = $("#city_select_matrix"); containName.empty(); // limpiar contenido anterior $('#place-autocomplete-card-matrix').css({'border': 'none'}) }); var pay_checkout_movil = $("#pay_checkout_movil"); if(window.innerWidth <= 991){ var modal_pay_checkout = $(".modal_pay_checkout") pay_checkout_movil.append(modal_pay_checkout); } });