1let current_product_id = $('[name="current_product_id"]').val(); 2var countSelectTimeout = false; 3 4 5function vd_debounce(func, delay = 300) { 6 let timeout; 7 console.log('timeout',timeout); 8 timeout = setTimeout(() => { 9 func(); 10 console.log('timeout2',timeout); 11 clearTimeout(timeout); 12 }, delay); 13} 14 15// ÐбÑÑ Ð´Ð¾Ð´Ð°ÑÐºÐ¾Ð²Ð¸Ñ Ð¿Ð¾ÑлÑг (набивка пÑÑзвиÑа/номеÑа, паÑÑÑ, зÑÑки) Ð·Ñ ÑÑоÑÑнки ÑоваÑÑ. 16// ÐикоÑиÑÑовÑÑÑÑÑÑ Ñ Ð² get_product_price, Ñ Ð² backet/add â Ñоб набивка поÑÑаплÑла в коÑик. 17function collect_services(){ 18 let services = []; 19 $('.additional-services__title [name="additional-services"]').each(function () { 20 if($(this).is(':checked')){ 21 let element = $(this).closest('.additional-services__item').find('.additional-services__value [service_id]'); 22 let service_id = element.attr('service_id'); 23 let service_type = element.attr('service_type'); 24 let value = element.val(); 25 let type = element.attr('type'); 26 if(service_type == 'player'){ 27 let svalue = $('[service_type="player_number"]').val(); 28 if(typeof svalue === 'string'){ 29 if(svalue.trim() != ''){ 30 value += ', ' + svalue; 31 } 32 } 33 } 34 if(typeof type === 'string' && type === 'checkbox'){ 35 value = element.is(':checked'); 36 } 37 services.push({ 38 service_id: service_id, 39 value: value, 40 service_type: service_type, 41 }); 42 } 43 }); 44 return services; 45} 46 47function get_product_price(){ 48 console.log('clear0', countSelectTimeout); 49 if(countSelectTimeout){ 50 return false; 51 // console.log('clear1', countSelectTimeout); 52 // clearTimeout(countSelectTimeout); 53 // countSelectTimeout = false; 54 // console.log('clear2', countSelectTimeout); 55 // countSelectTimeout = setTimeout(get_product_price, 1000); 56 // return false; 57 } 58 countSelectTimeout = true; 59 let count = 0; 60 // if($('#remove-from-basket').is(':visible')){ 61 count = $('#count-select').val(); 62 // } 63 let size = typeof $('[attribute_id]:checked').attr('attribute_id') !== 'undefined' ? $('[attribute_id]:checked').attr('attribute_id') : 0; 64 let services = collect_services(); 65 66 $.ajax({
67 'url': get_api_path()+'/api/shop/get_product_price', 68 'type': 'POST', 69 'data': { 70 product_id: current_product_id, 71 count: count, 72 lang: $('html').attr('lang'), 73 size: size, 74 services: services, 75 }, 76 success: function(response){ 77 if(typeof response.additionals !== 'undefined' && typeof response.additionals === 'object'){ 78 for(let serviceId in response.additionals){ 79 let serviceData = response.additionals[serviceId]; 80 $('[service_id='+serviceId+']').closest('.additional-services__item').find('.additional-services__price').text('+' + serviceData.price + response.price_symbol); 81 } 82 } 83 84 $('[currency]').removeClass('active'); 85 $('[currency="'+response.currency+'"]').addClass('active'); 86 $('#product_price').text(response.price + response.price_symbol); 87 if(response.old_price){ 88 $('#product_price').append('<span class="product-card__price_old">'+response.old_price + response.price_symbol+'</span>'); 89 } 90 91 if($('[name="filter-size"]').length){ 92 if(!$('[name="filter-size"]:checked').length){ 93 return false; 94 } 95 } 96 if(response.amount != 0){ 97 $('#product_stock_out').hide(); 98 $('#product_stock_in').show(); 99 $('#add-to-basket').prop('disabled', false); 100 }else{ 101 $('#add-to-basket').prop('disabled', true); 102 $('#product_stock_in').hide(); 103 $('#product_stock_out').show(); 104 } 105 let selected_size = false; 106 if(!Object.keys(response.backet).length){ 107 console.log('!Object.keys(response.backet).length', parseInt($('#count-select').val()), response.price_summary); 108 $('#remove-from-basket').hide(); 109 $('#add-to-basket').show(); 110 //$('#product_price_summary').text((parseInt($('#count-select').val()) * response.price) + response.price_symbol); 111 $('#product_price_summary').text((parseInt($('#count-select').val()) * response.price_summary) + response.price_symbol); 112 }else{ 113 console.log('ELSE!Object.keys(response.backet).length'); 114 if(typeof response.backet.size !== 'undefined'){ 115 selected_size = response.backet.size; 116 } 117 $('#add-to-basket').hide(); 118 $('#remove-from-basket').show(); 119 let count = response.backet.count; 120 console.log('backet',response.backet); 121 console.log('count',count); 122 console.log("$('#count-select').val()",$('#count-select').val()); 123 // $('#product_price_summary').text((count * response.price) + response.price_symbol); 124 $('#product_price_summary').text((count * response.price_summary) + response.price_symbol); 125 if($('#count-select').val() != count){ 126 // #count-select ÑÐ¸Ð½Ñ ÑонÑзÑÑмо з кÑлÑкÑÑÑÑ Ð¿Ð¾ÑоÑÐ½Ð¾Ñ Ð¿Ð¾Ð·Ð¸ÑÑÑ (без .change(), Ñоб не бÑло ÑÐ¸ÐºÐ»Ñ Ð·Ð°Ð¿Ð¸ÑÑв) 127 $('#count-select').val(count); 128 } 129 130 if(typeof response.backet.additionals !== 'undefined' && typeof response.backet.additionals === 'object'){ 131 for(let serviceId in response.backet.additionals){ 132 let serviceData = response.backet.additionals[serviceId]; 133 if(typeof serviceData.value !== 'undefined'){ 134 let stype = $('[service_id='+serviceId+']').attr('service_type'); 135 if(stype == 'player'){ 136 stype = serviceData.value.split(','); 137 if(typeof stype[0] !== 'undefined'){ 138 serviceData.value = stype[0].trim(); 139 } 140 if(typeof stype[1] !== 'undefined'){ 141 $('[service_type="player_number"]').val(stype[1].trim()); 142 } 143 } 144 $('[service_id='+serviceId+']').closest('.additional-services__item').find('.product-filter__checkbox [name="additional-services"]').prop('checked', true); 145 $('[service_id='+serviceId+']').closest('.additional-services__item').find('.product-filter__checkbox [name="additional-services"]').change(); 146 $('[service_id='+serviceId+']').change(); 147 let type = $('[service_id='+serviceId+']').attr('type'); 148 let hasChanged = false; 149 if(typeof type !== 'undefined'){ 150 if(type === 'checkbox'){ 151 $('[service_id='+serviceId+']').prop('checked', true); 152 hasChanged = true; 153 } 154 } 155 if(!hasChanged){ 156 $('[service_id='+serviceId+']').val(serviceData.value); 157 } 158 } 159 } 160 } 161 } 162 163 $('.product-filter__size .product-filter__body').empty(); 164 if(response.sizes.length){ 165 $('.product-filter__size').show(); 166 let itemTemplate = '<div class="product-filter__field product-filter__checkbox">\n' + 167 ' <input [checked] attribute_id="[attribute_id]" type="radio" name="filter-size" id="size-[attribute_id]">\n' + 168 ' <label for="size-[attribute_id]">[title]</label>\n' + 169 ' </div>'; 170 let html = ''; 171 for(let size of response.sizes){ 172 html += itemTemplate 173 .replaceAll('[attribute_id]', size.attribute_id) 174 .replaceAll('[title]', size.attribute_title) 175 .replaceAll('[checked]', selected_size && selected_size == size.attribute_id ? 'checked' : ''); 176 } 177 $('.product-filter__size .product-filter__body').html(html); 178 }else{ 179 $('.product-filter__size').hide(); 180 } 181 182 if($('[name="filter-size"]').length){ 183 if(!$('[name="filter-size"]:checked').length){ 184 if(!$('[attribute_id="'+size+'"]').is(':checked')){ 185 $('[attribute_id="'+size+'"]').prop('checked', true); 186 } 187 } 188 } 189 countSelectTimeout = false; 190 // clearTimeout(timerId); 191 192 $('body.product_item').addClass('vd_end_get_product_price'); 193 getBacket(); 194 } 195 });
196} 197 198$(document).ready(function(){ 199 // loadProductPage(); 200 vd_debounce(function (){ 201 get_product_price(); 202 }); 203 // get_product_price() 204 205 //#count-select, [attribute_id], [service_id], [name="additional-services"], [service_type="player_number"] 206 $(document).on('change', 'body.product_item.vd_end_get_product_price #count-select, body.product_item.vd_end_get_product_price [attribute_id], body.product_item.vd_end_get_product_price [service_id], body.product_item.vd_end_get_product_price [name="additional-services"], body.product_item.vd_end_get_product_price [service_type="player_number"]', function(e){ 207 console.log('e',e); 208 vd_debounce(function (){ 209 $('body.product_item').removeClass('vd_end_get_product_price'); 210 get_product_price(); 211 }); 212 //get_product_price() 213 // ; 214 // if(countSelectTimeout){ 215 // clearTimeout(countSelectTimeout); 216 // countSelectTimeout = null; 217 // console.log('clear', countSelectTimeout); 218 // } 219 // countSelectTimeout = setTimeout(get_product_price, 1000); 220 }); 221 222 $(document).on('click', '#add-to-basket', function(){ 223 if($('[name="filter-size"]').length){ 224 if(!$('[name="filter-size"]:checked').length){ 225 if(typeof notificationTranslates['notificationSelectSize'] === 'string'){ 226 iziToast.info({ 227 message: notificationTranslates['notificationSelectSize'], 228 position: 'bottomRight', 229 transitionIn: 'bounceInLeft' 230 }); 231 } 232 return false; 233 } 234 } 235 let count = parseInt($('#count-select').val()); 236 if(isNaN(count)){ 237 count = 1; 238 } 239 let size = typeof $('[attribute_id]:checked').attr('attribute_id') !== 'undefined' ? $('[attribute_id]:checked').attr('attribute_id') : 0; 240 let services = collect_services(); 241 $.ajax({
242 'url': get_api_path()+'/api/shop/backet/add', 243 'type': 'POST', 244 'data': { 245 product_id: current_product_id, 246 count: count, 247 lang: $('html').attr('lang'), 248 size: size, 249 services: services, 250 }, 251 success: function(response){ 252 //get_product_price(); 253 //getBacket(); 254 vd_debounce(function (){ 255 get_product_price(); 256 //getBacket(); 257 }); 258 // ÐÑнÑ-коÑик оновлÑÑмо завжди: get_product_price виÑе може бÑÑи 259 // пÑопÑÑений гейÑом countSelectTimeout â ÑÐ¾Ð´Ñ Ð±ÐµÐ· getBacket() ÑÑÑ 260 // бейдж/мÑнÑ-коÑик Ñ ÑапÑÑ Ð·Ð°Ð»Ð¸ÑилиÑÑ Ð±Ð¸ заÑÑаÑÑлими. 261 getBacket(); 262 iziToast.success({ 263 message: notificationTranslates['notificationAddedProductToCart'], 264 position: 'bottomRight', 265 transitionIn: 'bounceInLeft' 266 }); 267 } 268 }); 269 }); 270 271 $(document).on('click', '#remove-from-basket', function(){ 272 let size = typeof $('[attribute_id]:checked').attr('attribute_id') !== 'undefined' ? $('[attribute_id]:checked').attr('attribute_id') : 0; 273 $.ajax({
274 'url': get_api_path()+'/api/shop/backet/remove', 275 'type': 'POST', 276 'data': { 277 product_id: current_product_id, 278 size: size, 279 lang: $('html').attr('lang') 280 }, 281 success: function(response){ 282 // get_product_price(); 283 // getBacket(); 284 vd_debounce(function (){ 285 get_product_price(); 286 //getBacket(); 287 }); 288 // ÐналогÑÑно add: гаÑанÑÑÑмо Ð¾Ð½Ð¾Ð²Ð»ÐµÐ½Ð½Ñ Ð¼ÑнÑ-коÑика пÑÑÐ»Ñ Ð²Ð¸Ð´Ð°Ð»ÐµÐ½Ð½Ñ. 289 getBacket(); 290 } 291 }); 292 }); 293});
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.