1var saveCarrierTimes = ''; 2var id_msptimeslot = 0; 3var carrierDelivery = 0; 4shippingDays = new Array(); 5var availableText = ''; 6var disableText = ''; 7if(typeof baseDir=="undefined" && typeof prestashop!="undefined") 8 baseDir = prestashop.urls.base_url; 9function loadExtraCarrierContent() 10{ 11 $('.msp-extra-content').each(function(){ 12 $(this).remove(); 13 }) 14 $.ajax({ 15 type: 'POST', 16 url: baseDir + 'modules/megashipping/ajax.php', 17 async: false, 18 cache: false, 19 data: 'action=changeExtraCarrier', 20 success: function(jsonData,textStatus,jqXHR) 21 { 22 if(jsonData) 23 { 24 $('.carrier-extra-content:visible').html(jsonData).fadeIn(500); 25 loadPlanningShipping(); 26 //$(".checkout-step").off("click"); 27 } 28 } 29 }); 30} 31$(document).ready(function(){ 32 33 prestashop.on('updateProduct', function (event) { 34 setTimeout(function(){ loadMSPEvents(); }, 3000); 35 }); 36 37 prestashop.on( 38 'updateDeliveryForm', 39 function (event, type) { 40 alert(event); 41 } 42 ); 43 44 $(document).on("click","#msp-modal-click",function(e) { 45 $('#megashipping-modal').dialog('close'); 46 if($('#add_to_cart button').length) 47 $('#add_to_cart button').click(); 48 else 49 $('#add_to_cart input').click(); 50 51 }); 52 /*$('.delivery-option input[type="radio"]').click(function(){ 53 setTimeout(function(){ loadExtraCarrierContent(); }, 1800); 54 55 });*/ 56 /*$('.delivery-option input[type="radio"]:checked').change(); 57 setTimeout(function(){ 58 loadExtraCarrierContent(); 59 }, 60 1800);*/ 61 //$('.delivery-option input[type="radio"]:checked').click(); 62 63 /*if($("[name='confirmDeliveryOption']").length) 64 { 65 $("[name='confirmDeliveryOption']").unbind().click(function(e){ 66 var result = true; 67 if($('.carrier-extra-content:visible').find('.mspfieldsform').length) 68 result = saveMSPFields(); 69 if(typeof acceptCGV!='undefined') 70 result = acceptCGV(); 71 72 if($('.carrier-extra-content:visible').find('msp-time-error').length) 73 result = false; 74 if($('.carrier-extra-content:visible').find('.mspdelivery').length && $('.carrier-extra-content:visible').find('.mspdelivery').val()=='') 75 result = false; 76 if(result) 77 $(this).submit(); 78 else{ 79 e.preventDefault; 80 81 } 82 return result; 83 84 85 }); 86 87 }*/ 88 if($('#showinfodays').length && $('#idCombination').length && $('#idCombination').val()!=0) 89 { 90 var currentCombinationValue = $('#idCombination').val(); 91 92 setInterval(function() { 93 if($("#idCombination").val() != currentCombinationValue) 94 { 95 currentCombinationValue = $('#idCombination').val(); 96 $.ajax({
97 type: 'POST', 98 url: baseDir + 'modules/megashipping/ajax.php', 99 async: false, 100 cache: false, 101 data: 'action=productdays&id_product='+$('#product_page_product_id').val()+'&id_product_attribute='+$('#idCombination').val(), 102 success: function(jsonData,textStatus,jqXHR) 103 { 104 if(jsonData) 105 { 106 $("#showinfodays").replaceWith(jsonData); 107 } 108 } 109 }); 110 111 } }, 2000); 112 113 } 114 loadMSPEvents(); 115 setTimeout(function(){loadPlanningShipping()},100); 116 117}); 118function loadMSPEvents(){ 119 $('#btnCalculeCP').bind('click', function(event) { 120 var mscarrier = ''; 121 if($('#id_filter_carrier').length) 122 mscarrier += '&id_filter_carrier='+$('#id_filter_carrier').val(); 123 var quantity = parseInt($('#quantity_wanted').val()); 124 var sendgroups = ''; 125 if($('#megaproduct').length && typeof getSendGroups!='undefined') 126 { 127 sendgroups = getSendGroups(quantity); 128 129 var width = $('#id_width').val(); 130 if((width==0 && _MP.width_min!=-1) || typeof(width) == 'undefined') 131 width = 1; 132 var height = $('#id_height').val(); 133 if(height==0 && _MP.height_min!=-1 || typeof(height) == 'undefined') 134 height=1; 135 var long = $('#id_long').val(); 136 if((long==0 && _MP.long_min!=-1) || typeof(long) == 'undefined') 137 long=1; 138 sendgroups += '&width='+width+'&height='+height+'&long='+long; 139 } 140 //findCombination(); 141 $.ajax({ 142 type: 'POST', 143 url: baseDir + 'modules/megashipping/ajax.php', 144 async: false, 145 cache: false, 146 data: 'quantity='+quantity+sendgroups+'&id_product='+$('#product_page_product_id').val()+'&id_product_attribute='+$('#idCombination').val()+'&cp='+$('#id_ms_cp').val()+'&id_country='+$('#id_ms_country').val()+mscarrier, 147 success: function(jsonData,textStatus,jqXHR) 148 { 149 if(jsonData) 150 { 151 $('#megashipping-modal').html(jsonData).fadeIn(2000); 152 //refreshProductImages($('#idCombination').val()); 153 var imagepic = ''; 154 if($('#bigpic').length) 155 imagepic = $('#bigpic').attr('src').replace('large','home'); 156 else if($('.jqzoom img').length) 157 imagepic = $('.jqzoom img').attr('src').replace('large','home'); 158 $('#ms-modal-image').attr('src',imagepic); 159 $('#megashipping-modal').attr('title',$('#id_info_modal_text').val()); 160 161 $('#megashipping-modal').dialog({ 162 resizable: false, 163 modal: true, 164 width:'auto'}); 165 166 } 167 } 168 }); 169 }); 170 $(document).on('click','#btnColumnCP',function(event) { 171 $.ajax({ 172 type: 'POST', 173 url: baseDir + 'modules/megashipping/ajax.php', 174 async: false, 175 cache: false, 176 data: 'cp='+$('#id_ms_col_cp').val()+'&id_country='+$('#id_ms_country').val(), 177 success: function(jsonData,textStatus,jqXHR) 178 { 179 if(jsonData) 180 { 181 $('#megashipping-block-modal').html(jsonData).fadeIn(2000); 182 $('#megashipping-block-modal').attr('title',$('#id_info_modal_text').val()); 183 184 $('#megashipping-block-modal').dialog({ 185 resizable: false, 186 modal: true, 187 width:'auto'}); 188 } 189 } 190 }); 191 }); 192} 193function loadMspRules(){ 194 $('.planning-carrier').each(function(){ 195 var rules = $(this).attr('rules'); 196 if(rules!=''){ 197 198 var mspcarrier = $(this).data('mspcarrier'); 199 var arrayRules = JSON.parse(rules); 200 for(var i=0;i<arrayRules.length;i++){ 201 addShippingDate(mspcarrier,arrayRules[i]['date_start'],arrayRules[i]['date_end'],arrayRules[i]['days'],arrayRules[i]['type']); 202 } 203 } 204 }); 205 206} 207function loadPlanningShipping() 208{ 209 210 //if(typeof(plusdays) == 'undefined') 211 //return; 212 $("#checkout-delivery-step .content").unbind(); 213 $('.msp-extra-content').click(function(e){ 214 e.stopPropagation(); 215 }); 216 loadMspRules(); 217 $('.planning-carrier').each(function(){ 218 var mspcarrier = carrierDelivery = $(this).data('mspcarrier'); 219 plusdays = $(this).data('days'); 220 maxdays = 360; 221 if($(this).data('maxdays') && $(this).data('maxdays')!=0) 222 maxdays = $(this).data('maxdays'); 223 $(this).datepicker({ minDate: "+"+plusdays+"D",maxDate: "+"+maxdays+"D", 224 showOtherMonths: true, 225 selectOtherMonths: true, 226 dateFormat: "dd-mm-yy", 227 beforeShowDay: isShippingAvailable, 228 onSelect: function(selectedDate, inst) 229 { 230 231 var selectedday = $(this).datepicker('getDate'); 232 var yyyy = selectedday.getFullYear().toString(); 233 var mm = (selectedday.getMonth()+1).toString(); 234 var dd = selectedday.getDate().toString(); 235 id_mspcarrier = $('.carrier-extra-content:visible').find('.planning-carrier').data('mspcarrier'); 236 237 var dateselect = yyyy + '-' + (mm[1]?mm:"0"+mm[0]) + '-' + (dd[1]?dd:"0"+dd[0]); 238 $('.carrier-extra-content:visible').find('.mspdelivery').val(dateselect); 239 240 241 configcalendar = $('.carrier-extra-content:visible').find('.planning-carrier').data('calendar'); 242 if(typeof configcalendar!='undefined' && configcalendar>1) 243 { 244 $.ajax({
245 type: 'POST', 246 url: baseDir + 'modules/megashipping/ajax.php?action=shippingtimes', 247 async: false, 248 cache: false, 249 dataType : "json", 250 data: '&1'+'&id_mspcarrier='+id_mspcarrier+'&date_carrier='+dateselect, 251 success: function(json,textStatus,jqXHR) 252 { 253 $('.carrier-extra-content:visible').find('.planning-carrier-times').html(''); 254 if(json.html) 255 { 256 $('.carrier-extra-content:visible').find('.planning-carrier-times').html(json.html); 257 } 258 259 } 260 }); 261 } 262 else 263 { 264 sendDelivery(); 265 } 266 } 267 }) 268 269 }); 270 carrierDelivery = 0; 271 272 $('.carrier-extra-content').each(function(){ 273 if($(this).find('.mspdelivery').length && $(this).find('.mspdelivery').val()!='') 274 { 275 var defaultMpsDate = new Date($(this).find('.mspdelivery').val()); 276 $(this).find('.planning-carrier').datepicker("setDate", defaultMpsDate); 277 } 278 }); 279 /*if($('.carrier-extra-content:visible').find('.mspdelivery').length && $('.carrier-extra-content:visible').find('.mspdelivery').val()!='') 280 { 281 var defaultMpsDate = new Date($('.carrier-extra-content:visible').find('.mspdelivery').val()); 282 $('.carrier-extra-content:visible').find('.planning-carrier').datepicker("setDate", defaultMpsDate); 283 }*/ 284} 285function sendDelivery() 286{ 287 var dateselect = $('.carrier-extra-content:visible').find('.mspdelivery').val(); 288 var id_timeslot = 0; 289 if($('.carrier-extra-content:visible').find(".id_timeslot").length) 290 id_timeslot = $('.carrier-extra-content:visible').find(".id_timeslot").val(); 291 var id_mspcarrier = $('.carrier-extra-content:visible').find('.planning-carrier').data('mspcarrier'); 292 $.ajax({ 293 type: 'POST', 294 url: baseDir + 'modules/megashipping/ajax.php?action=setDelivery', 295 async: true, 296 cache: false, 297 dataType : "json", 298 data: '&1'+'&id_mspcarrier='+id_mspcarrier+'&id_timeslot='+id_timeslot+'&delivery='+dateselect, 299 success: function(jsonData,textStatus,jqXHR) 300 { 301 saveCarrierTimes = $("#planning-carrier"+id_mspcarrier).datepicker("getDate"); 302 if(typeof updateCarrierSelectionAndGift!='undefined') 303 updateCarrierSelectionAndGift(); 304 else 305 location.reload(); 306 307 } 308 }); 309} 310 311function selectTimeslot(el,id_timeslot) 312{ 313 id_msptimeslot = id_timeslot; 314 315 $(el).parents('.planning-carrier-times').find('a').removeClass('selectTimeslots'); 316 $(el).parents('.planning-carrier-times').find('.id_timeslot').val(id_timeslot); 317 $('#ts'+id_timeslot).addClass('selectTimeslots'); 318 if(typeof saveCarrierTimes!='undefined' && saveCarrierTimes=='') 319 sendDelivery(); 320} 321function refreshDeliveryOptions() 322{ 323 if(typeof saveCarrierTimes!='undefined' && saveCarrierTimes!=''){ 324 //$('#planning-carrier').html(saveCarrierTimes); 325 $('#planning-carrier').datepicker("setDate", saveCarrierTimes); 326 selectTimeslot(id_msptimeslot);
327 saveCarrierTimes = ''; 328 //loadPlanningShipping(); 329 } 330 331 332 $.each($('.delivery_option_radio'), function() { 333 if ($(this).prop('checked')) 334 { 335 if ($(this).parent().find('.delivery_option_carrier.not-displayable').length == 0) 336 $(this).parent().find('.delivery_option_carrier').show(); 337 var carrier_id_list = $(this).val().split(','); 338 carrier_id_list.pop(); 339 var it = this; 340 $(carrier_id_list).each(function() { 341 $(it).closest('.delivery_options').find('input[value="' + this.toString() + '"]').change(); 342 }); 343 } 344 else 345 $(this).parent().find('.delivery_option_carrier').hide(); 346 }); 347} 348 349function addShippingDate(idmspcarrier,start,end,days,type){ 350 if(typeof shippingDays=='undefined') 351 shippingDays = new Array(); 352 var dayArray = new Array(); 353 dayArray['start'] = start; 354 dayArray['end'] = end; 355 if(days) 356 dayArray['days'] = days.split('-'); 357 else 358 dayArray['days'] = false; 359 360 dayArray['type'] = type; 361 for(var i=0; i<dayArray['days'].length; i++) { dayArray['days'][i] = parseInt(dayArray['days'][i]); } 362 if(typeof shippingDays[idmspcarrier]=='undefined') 363 shippingDays[idmspcarrier] = new Array(); 364 shippingDays[idmspcarrier].push(dayArray); 365}; 366function isShippingAvailable(date){ 367 var dateAsString = date.getFullYear().toString() + "-" + ('0' + (date.getMonth()+1)).slice(-2) + "-" + ('0' + date.getDate()).slice(-2); 368 carrierShow = $('.carrier-extra-content:visible').find('.planning-carrier').data('mspcarrier'); 369 if(carrierDelivery!=0) 370 carrierShow = carrierDelivery; 371 372 if(typeof shippingDays[carrierShow]!='undefined'){ 373 var disableDay = false; 374 for (var key in shippingDays[carrierShow]) 375 { 376 var daysWeek = shippingDays[carrierShow][key]['days']; 377 var type = shippingDays[carrierShow][key]['type']; 378 var startString = shippingDays[carrierShow][key]['start'].split("-"); 379 var startDate = new Date(startString[0],startString[1]-1,startString[2]); 380 381 var endString = shippingDays[carrierShow][key]['end'].split("-"); 382 var endDate = new Date(endString[0],endString[1]-1,endString[2]); 383 384 var dayOfWeek = date.getDay(); 385 startDate.setDate(startDate.getDate()); 386 endDate.setDate(endDate.getDate()); 387 date.setHours(0,0,0,0); 388 startDate.setHours(0,0,0,0); 389 endDate.setHours(0,0,0,0); 390 if(startDate<=date && endDate>=date) 391 { 392 if(daysWeek!='' && $.inArray(dayOfWeek,daysWeek)!=-1) 393 { 394 if(type==0) 395 { 396 disableDay = true; 397 //return [false, "",disableText]; 398 } 399 else if(type==3) 400 { 401 return [true, "",availableText]; 402 } 403 } 404 else if(daysWeek==''){ 405 if(type==0) 406 { 407 disableDay = true; 408 //return [false, "",disableText]; 409 } 410 else if(type==3) 411 { 412 return [true, "",availableText]; 413 } 414 } 415 416 417 } 418 } 419 } 420 if(disableDay){ 421 return [false, "",disableText]; 422 } 423 424 return [true, "",availableText]; 425 426}; 427function saveMSPFields() 428{ 429 $('.carrier-extra-content:visible').find('.mspresult').html('').hide(); 430 var id_mspcarrier = $('.carrier-extra-content:visible').find('.planning-carrier').data('mspcarrier'); 431 432 var validateFields = true; 433 var datasend = ''; 434 $('.carrier-extra-content:visible').find('.mspfieldsform').find('input,textarea,select').each(function(){ 435 if($(this).val()=='' && $(this).data('required')){ 436 validateFields = false; 437 } 438 var id = $(this).attr('id'); 439 var valueField = $(this).val(); 440 datasend += '&'+id+'='+encodeURIComponent(valueField); 441 }); 442 443// var datafields = $('#mspfieldsform').serialize(); 444 if(validateFields) 445 { 446 $.ajax({ 447 type: 'POST', 448 url: baseDir + 'modules/megashipping/ajax.php?action=setFields&id_mspcarrier='+id_mspcarrier+datasend, 449 async: false, 450 cache: false, 451 dataType : "json", 452 success: function(jsonData,textStatus,jqXHR) 453 { 454 455 var mspresult = '<div class="alert alert-success">
455'+mspFieldSave+'</div>'; 456 $('.carrier-extra-content:visible').find('.mspresult').html(mspresult).show(); 457 return true; 458 } 459 }); 460 } 461 else{ 462 var msperror = '<div class="alert alert-danger">'+mspFieldRequired+'</div>'; 463 $('.carrier-extra-content:visible').find('.mspresult').html(msperror).show(); 464 return false; 465 } 466 return true; 467 468} 469 470 471
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.