1(function( $ ) { 2 'use strict'; 3 4 $(function() { 5 // Eventos de pagina de prodducto 6 $('#cpc_terms_selector').on('change', function(e, data){ 7 const quantity = $('.input-text.qty.text').val(); 8 const term = $(this).val(); 9 const price = cpcRates.get_product_price(quantity); 10 11 if (price > 0) { 12 cpcRates.get_updated_rate(term, price); 13 } 14 }); 15 16 $('.input-text.qty.text[name="quantity"]').on('change', function(e, data){ 17 const quantity = $(this).val(); 18 const term = $('#cpc_terms_selector').val() !== '' ? $('#cpc_terms_selector').val() : $('#cpc_terms_selector').text(); 19 20 const price = cpcRates.get_product_price(quantity); 21 if (price > 0) { 22 cpcRates.get_updated_rate(term, price); 23 } 24 }); 25 26 //Eventos de pagina de checkout 27 $("body").on("click", "[name=\"cpc_rate_selector\"]", function() { 28 const id = this.id.replace('cpc_', ''); 29 $('.cpc_rate_show').addClass('cpc_rate_hide').removeClass('cpc_rate_show'); 30 $('#cpc_details_'+id).addClass('cpc_rate_show').removeClass('cpc_rate_hide'); 31 $('#cpc_codTarifa').val($('#cpc_codTarifa_'+id).val()); 32 $('#cpc_versionTarifa').val($('#cpc_versionTarifa_'+id).val()); 33 $('#cpc_numPlazos').val($('#cpc_numPlazos_'+id).val()); 34 35 if($('#cpc_indCesionDatos').is(':checked')) { 36 $('#place_order').removeClass('disabled').removeAttr('disabled'); 37 } 38 }); 39 40 $('body').on('click', '#cpc_toggle_cf', function (e) { 41 $('#cpc_cuotaFija_list').addClass('cpc_list_show').removeClass('cpc_list_hide'); 42 $('#cpc_plazoMensual_list').removeClass('cpc_list_show').addClass('cpc_list_hide'); 43 $(this).addClass('alt'); 44 $('#cpc_toggle_pm').removeClass('alt'); 45 }); 46 47 $('body').on('click', '#cpc_toggle_pm', function () { 48 $('#cpc_cuotaFija_list').removeClass('cpc_list_show').addClass('cpc_list_hide'); 49 $('#cpc_plazoMensual_list').addClass('cpc_list_show').removeClass('cpc_list_hide'); 50 $(this).addClass('alt'); 51 $('#cpc_toggle_cf').removeClass('alt'); 52 }); 53 54 $('body').on('change', "[name=\"payment_method\"]", function () { 55 if( $('#payment_method_cpc_gateway').is(':checked') ){ 56 if ( 57 !$("input[name='cpc_rate_selector']:checked").length 58 || !$('#cpc_indCesionDatos').is(':checked') 59 ) { 60 $('#place_order').addClass('disabled').attr('disabled', 'disabled'); 61 } else { 62 $('#place_order').removeClass('disabled').removeAttr('disabled'); 63 } 64 } else { 65 $('#place_order').removeClass('disabled').removeAttr('disabled'); 66 } 67 }); 68 69 $('body').on('change', '#cpc_indCesionDatos', function (e) { 70 if ($(e.target).is(':checked') && $("input[name='cpc_rate_selector']:checked").length) { 71 $('#place_order').removeClass('disabled').removeAttr('disabled'); 72 } else { 73 if ($('#payment_method_cpc_gateway').is(':checked')) { 74 $('#place_order').addClass('disabled').attr('disabled', 'disabled'); 75 } 76 } 77 }); 78 }); 79 80 const cpcRates = { 81 get_updated_rate: function (term, price) { 82 $.ajax({ 83 'type': 'POST', 84 'url': cpc_ratesUpdater.ajax_url, 85 'dataType': 'json', 86 'data': { 87 'action': 'launch_update_rate', 88 'price': price, 89 'term': term 90 }, 91 'beforeSend': () => { 92 $('#cpc_rates_info').fadeOut('fast', () => { 93 $('#cpc_loader').fadeIn('slow'); 94 }); 95 }, 96 'success': (res) => { 97 98 if (!res.success) { 99 $('#cpc_loader').fadeOut('fast'); 100 return; 101 } 102 const data = res.rate; 103 let cuotasRestantes = 0; 104 105 if (term === null) { 106 term = data['plazos']; 107 } 108 109 $('#cpc_title_cuotasRestantes').text(cpcRates.format_decimals(data['cuotasRestantes']??0)); 110 $('#cpc_porTin').text(cpcRates.format_decimals(data['tin'])); 111 $('#cpc_porTae').text(cpcRates.format_decimals(data['tae'])); 112 $('#cpc_numCuotas').text(data['plazos']); 113 $('#cpc_comisionApertura').text(cpcRates.format_decimals(data['comisionApertura'])); 114 $('#cpc_valorApertura').text(cpcRates.format_decimals(data['valorApertura'])); 115 $('#cpc_primeraCuota').text(cpcRates.format_decimals(data['primeraCuota'])); 116 $('#cpc_cuotasRestantes').text(cpcRates.format_decimals(data['cuotasRestantes'])); 117 $('#cpc_ultimaCuota').text(cpcRates.format_decimals(data['ultimaCuota'])); 118 const importeAFinanciar = data['importeTotalAdeudado'] - (data['importeAFinanciar'] / 100); 119 $('#cpc_impAFinanciar').text(cpcRates.format_decimals(importeAFinanciar)); 120 $('#cpc_impTotalAdeudado').text(cpcRates.format_decimals(data['importeTotalAdeudado'])); 121 $('#cpc_cabeceraTextoLegal').html(data['cabeceraTextoLegal']); 122 $('#cpc_cuerpoTextoLegalComun').html(data['cuerpoTextoLegalComun']); 123 const select = $('#cpc_terms_selector'); 124 if (select.length) { 125 select.empty(); 126 for (let i = 0; i < res.terms.length; i++) { 127 if (res.terms[i] == term) { 128 select.append('<option selected>'+res.terms[i]+'</option>'); 129 } else { 130 select.append('<option>'+res.terms[i]+'</option>'); 131 } 132 } 133 } 134 135 if (data['fechaFin'] === null || data['fechaFin'] === '') { 136 $('#cpc_offer_valid').hide(); 137 } else { 138 $('#cpc_offer_valid').show(); 139 const d = data['fechaFin'].toString(); 140 const year = d.substr(0, 4);
141 const month = d.substr(4, 2); 142 const day = d.substr(6, 2); 143 const date = day + '/' + month + '/' + year; 144 145 $('#cpc_offer_valid_date').text(date); 146 } 147 $('#cpc_loader').fadeOut('fast', () => { 148 $('#cpc_rates_info').removeClass('cpc_rate_hide'); 149 $('#cpc_rates_info').fadeIn('slow'); 150 }); 151 }, 152 'error': () => { 153 $('#cpc_loader').fadeOut('fast'); 154 } 155 }); 156 }, 157 format_decimals: function(number) { 158 const fixedNumber = Number.parseFloat(number).toFixed(2); 159 160 return String(fixedNumber).replace(".", ","); 161 }, 162 get_product_price: function(quantity) { 163 const isVariable = jQuery('.variations_form.cart').length === 0 ? false : true; 164 let price = 0; 165 let priceElement = jQuery('#cpc_product_simple_min_price').val(); 166 if(isVariable) { 167 return cpcRates.get_variable_price(quantity); 168 } 169 170 if (typeof priceElement !== 'undefined') { 171 price = Number.parseFloat(priceElement.replace(/[^0-9|^.|^,]/g, '').replace(",", ".")); 172 if (quantity > 0) { 173 price *= quantity; 174 } 175 } 176 return price.toFixed(2); 177 }, 178 get_variable_price: function (quantity) { 179 const variations_list = JSON.parse(jQuery('.variations_form.cart').attr('data-product_variations')); 180 const variation_id = jQuery('input[name="variation_id"]:hidden').length === 1 ? parseInt(j
180Query('input[name="variation_id"]:hidden').val()) : null; 181 let price = 0; 182 183 if (variation_id !== null) { 184 const variation_data = variations_list.find( variation => variation.variation_id === variation_id); 185 price = variation_data !== null ? variation_data.display_price : 0; 186 187 if(quantity > 0) { 188 price *= quantity; 189 } 190 191 } 192 193 return Number.parseFloat(price).toFixed(2); 194 } 195 196}})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.