$(document).ready(function(){ $('#frmpedido').submit(function(){ return false; }); function ComprobarCesta(saltar) { comprobaciones = false; resultado = $.ajax({ type: 'POST', async: false, url : AJ_HOST+'js/ajax/js-comprobaciones-carro.php', data: { comprobar: saltar }, success : function (data) { }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(xhr.responseText); alert(thrownError); } }).responseText; if (resultado.replace(/^\s+|\s+$/, '') == 1) { return true; } else { return false; } } // cupon descuento $('#cupon-descuento').click(function(e){ e.preventDefault(); if ($.trim($('#coupon').val()) == "") {alert('Debe introducir un código de cupón de descuento.');$('#coupon').focus();return false;} if (ComprobarCesta(0) == true) { alert('No se puede canjear cupones porque hay producto/s que contiene/n descuento/s o precios rebajados en la cesta. Disculpa las molestias.'); return false; } $.ajax({ type: 'POST', cache: false, dataType: "json", beforeSend: function(x) { if(x && x.overrideMimeType) { x.overrideMimeType("application/json;charset=UTF-8"); } }, url : AJ_HOST+'js/ajax/js-cupon-descuento.php', data: { accion: 'anadir', cupon: $('#coupon').val()}, success : function (data) { //alert(data); if (data == 0) location.reload(); else if (data == 1) {alert('El cupón ya está en uso');$('#coupon').focus();return false;} else if (data == 2) {alert('El cupón no existe');$('#coupon').focus();return false;} else if (data == 3) {alert('El cupón es privado');$('#coupon').focus();return false;} }, error : function (data) { alert('Error de llamada AJAX: '+data);return false; } }); return false; }); // borrar cupon $('#delete-cupon').click(function(e){ e.preventDefault(); if(!confirm('¿Estás segur@ de eliminar el cupón?')) return false; $.ajax({ type: 'POST', cache: false, dataType: "text", beforeSend: function(x) { if(x && x.overrideMimeType) { x.overrideMimeType("application/text;charset=UTF-8"); } }, url : AJ_HOST+'js/ajax/js-cupon-descuento.php', data: { accion: 'eliminar'}, success : function (data) { location.reload(); }, error:function(xhr,err){ alert('readyState: '+xhr.readyState+' nstatus: '+xhr.status); alert('responseText: '+xhr.responseText); //console.log(xhr.responseText); } }); return false; }); // paso 0 $('#volver-paso-0').click(function(e){ e.preventDefault(); $.ajax({ type: 'POST', cache: false, dataType: "text", beforeSend: function(x) { if(x && x.overrideMimeType) { x.overrideMimeType("application/text;charset=UTF-8"); } }, url : AJ_HOST+'js/ajax/js-step.php', data: { step: '0'}, success : function (data) { //if (data) { // mostrar paso_1 location.reload(); //} else { //} }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(xhr.responseText); alert(thrownError); } }); return false; }); // paso 1 $('#realizar-pedido').click(function(e){ e.preventDefault(); //alert($('#seleccionar-envio').val()); //if ($('#seleccionar-envio').val() == 0) {alert('Selecciona una forma de envío');return false;} //$.blockUI(); // abrir loader $.ajax({ type: 'POST', cache: false, dataType: "text", beforeSend: function(x) { if(x && x.overrideMimeType) { x.overrideMimeType("application/text;charset=UTF-8"); } }, url : AJ_HOST+'js/ajax/js-step.php', data: { step: '1'}, success : function (data) { //if (data) { // mostrar paso_1 location.reload(); //} else { //} }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(xhr.responseText); alert(thrownError); } }); return false; }); $('#pagar-pedido').click(function(e){ e.preventDefault(); if (!$('#acepta2').is(':checked')) return false; if (typeof($('.envio:checked').val()) == "undefined") { alert('Debe seleccionar la forma de envío'); return false; } if(isNaN(parseInt($('.envio:checked').val())) ? 0 : parseInt($('.envio:checked').val()) == 0){ alert('Debe seleccionar la forma de envío'); return false; } if(!confirm('¿Estás segur@?')) return false; //alert('Procesando el pedido, espere unos segundos...'); if (ComprobarCesta(1) == true) { alert('No se puede realizar el pedido porque hay producto/s que contiene/n descuento/s o precios rebajados que no son compatibles con el cupón asignado en la cesta. Disculpa las molestias.'); return false; } $.ajax({ type: 'POST', cache: false, dataType: "json", beforeSend: function(x) { if(x && x.overrideMimeType) { x.overrideMimeType("application/json;charset=UTF-8"); } }, url : AJ_HOST+'js/ajax/js-step.php', data: { step: '3', forma_pago: '0', envio: $('.envio:checked').val(), base_imponible: $('.base_imponible').text(), tipo_iva: $('.tipo_iva').text(), iva: $('.iva').text(), imp_cupon: $('.imp-cupon').text(), portes: $('.portes').text(), total: $('.total2').text(), comentario: $('.comentario').val()}, success : function (data) { //if (data) { // mostrar paso_1 //location.reload(); window.location = 'pedidos/'+data; //} else { //} }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(xhr.responseText); alert(thrownError); } }); return false; }); // anular cesta $('#anular-cesta').click(function(e){ e.preventDefault(); if(!confirm('¿Estás segur@?')) return false; $.ajax({ type: 'POST', cache: false, dataType: "text", beforeSend: function(x) { if(x && x.overrideMimeType) { x.overrideMimeType("application/text;charset=UTF-8"); } }, url : AJ_HOST+'js/ajax/js-step.php', data: { step: '4'}, success : function (data) { //if (data) { // mostrar paso_1 location.reload(); //} else { //} }, error:function(xhr,err){ alert('readyState: '+xhr.readyState+' nstatus: '+xhr.status); alert('responseText: '+xhr.responseText); //console.log(xhr.responseText); } }); return false; }); });