1/* 2* 2007-2016 PrestaShop 3* 4* NOTICE OF LICENSE 5* 6* This source file is subject to the Academic Free License (AFL 3.0) 7* that is bundled with this package in the file LICENSE.txt. 8* It is also available through the world-wide-web at this URL: 9* http://opensource.org/licenses/afl-3.0.php 10* If you did not receive a copy of the license and are unable to 11* obtain it through the world-wide-web, please send an email 12* to [email protected] so we can send you a copy immediately. 13* 14* DISCLAIMER 15* 16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer 17* versions in the future. If you wish to customize PrestaShop for your 18* needs please refer to http://www.prestashop.com for more information. 19* 20* @author PrestaShop SA <[email protected]> 21* @copyright 2007-2016 PrestaShop SA 22* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 23* International Registered Trademark & Property of PrestaShop SA 24*/ 25 26/** 27* Update WishList Cart by adding, deleting, updating objects 28* 29* @return void 30*/ 31//global variables 32var wishlistProductsIds = []; 33$(document).ready(function(){ 34 wishlistRefreshStatus(); 35 36 $(document).on('change', 'select[name=wishlists]', function(){ 37 WishlistChangeDefault('wishlist_block_list', $(this).val()); 38 }); 39 40 41 $('.wishlist').each(function() { 42 current = $(this); 43 $(this).children('.wishlist_button_list').popover({ 44 html: true, 45 content: function () { 46 return current.children('.popover-content').html(); 47 } 48 }); 49 }); 50 51 52 53 jQuery(".addToDorWishlist").click(function(){ 54 var id = 0; 55 var id_wishlist = 0; 56 var quantity = 1; 57 var action = "add"; 58 var id_product = jQuery(this).closest(".js-product-miniature").attr("data-id-product"); 59 var id_product_attribute = jQuery(this).closest(".js-product-miniature").attr("data-id-product-attribute"); 60 //WishlistCart(id, action, id_product, id_product_attribute, quantity, id_wishlist); 61 }); 62 DeleteWishlistItem(); 63}); 64 65function WishlistPop(mess){ 66 var htmlPop = '<div class="dor-jspop-wishlist">'; 67 htmlPop += '<span class="dor-jspop-wishlist-close"></span>'; 68 htmlPop += '<div class="dor-jspop-wishlist-info">'; 69 htmlPop += mess; 70 htmlPop += '</div>'; 71 htmlPop += '</div>'; 72 jQuery(".dor-jspop-wishlist").remove(); 73 setTimeout(function(){ 74 jQuery("body").append(htmlPop); 75 jQuery(".dor-jspop-wishlist-close").click(function(){ 76 jQuery(".dor-jspop-wishlist").remove(); 77 }); 78 },300); 79 80 setTimeout(function(){ 81 jQuery(".dor-jspop-wishlist").remove(); 82 },3000); 83} 84 85function DeleteWishlistItem(){ 86 jQuery("body").on("click",".btn-remove-wishlist",function(){ 87 var id = 0; 88 var id_wishlist = 0; 89 var quantity = 1; 90 var action = "delete"; 91 var id_product = jQuery(this).closest(".js-product-miniature").attr("data-id-product"); 92 var id_product_attribute = jQuery(this).closest(".js-product-miniature").attr("data-id-product-attribute"); 93 WishlistCart(id, action, id_product, id_product_attribute, quantity, id_wishlist); 94 jQuery(this).closest(".js-product-miniature").remove(); 95 }); 96} 97 98function WishlistCart(id, action, id_product, id_product_attribute, quantity, id_wishlist) 99{ 100 var current = $('.total-wishlist strong').text(); 101 $.ajax({ 102 type: 'GET', 103 url: prestashop.urls.base_url+ 'modules/dorblockwishlist/cart.php?rand=' + new Date().getTime(), 104 headers: { "cache-control": "no-cache" }, 105 async: true, 106 cache: false, 107 data: 'action=' + action + '&id_product=' + id_product + '&quantity=' + quantity + '&token=' + prestashop.static_token + '&id_product_attribute=' + id_product_attribute + '&id_wishlist=' + id_wishlist, 108 success: function(data) 109 { 110 if (action == 'add') 111 { 112 if (prestashop.customer.is_logged == true) { 113 wishlistProductsIdsAdd(id_product); 114 wishlistRefreshStatus(); 115 WishlistPop("The product was successfully added to your wishlist."); 116 117 if(typeof parseInt(current) == 'number'){ 118 current = parseInt(current) + 1; 119 $('.total-wishlist strong').text(current); 120 } 121 } 122 else 123 { 124 WishlistPop("Musisz byÄ zalogowany aby zarzÄ dzaÄ listÄ "); 125 } 126 }
127 if (action == 'delete') { 128 wishlistProductsIdsRemove(id_product); 129 wishlistRefreshStatus(); 130 if(typeof parseInt(current) == 'number'){ 131 current = parseInt(current) - 1; 132 $('.total-wishlist strong').text(current); 133 } 134 } 135 if($('#' + id).length != 0) 136 { 137 $('#' + id).slideUp('normal'); 138 document.getElementById(id).innerHTML = data; 139 $('#' + id).slideDown('normal'); 140 } 141 } 142 }); 143} 144 145/** 146* Change customer default wishlist 147* 148* @return void 149*/ 150function WishlistChangeDefault(id, id_wishlist) 151{ 152 $.ajax({ 153 type: 'GET', 154 url: baseDir + 'modules/blockwishlist/cart.php?rand=' + new Date().getTime(), 155 headers: { "cache-control": "no-cache" }, 156 async: true, 157 data: 'id_wishlist=' + id_wishlist + '&token=' + static_token, 158 cache: false, 159 success: function(data) 160 { 161 $('#' + id).slideUp('normal'); 162 document.getElementById(id).innerHTML = data; 163 $('#' + id).slideDown('normal'); 164 } 165 }); 166} 167 168/** 169* Buy Product 170* 171* @return void 172*/ 173function WishlistBuyProduct(token, id_product, id_product_attribute, id_quantity, button, ajax) 174{ 175 if(ajax) 176 ajaxCart.add(id_product, id_product_attribute, false, button, 1, [token, id_quantity]); 177 else 178 { 179 $('#' + id_quantity).val(0); 180 WishlistAddProductCart(token, id_product, id_product_attribute, id_quantity) 181 document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].method='POST'; 182 document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].action=baseUri + '?controller=cart'; 183 document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].elements['token'].value = static_token; 184 document.forms['addtocart' + '_' + id_product + '_' + id_product_attribute].submit(); 185 } 186 return (true); 187} 188 189function WishlistAddProductCart(token, id_product, id_product_attribute, id_quantity) 190{ 191 if ($('#' + id_quantity).val() <= 0) 192 return (false); 193 194 $.ajax({ 195 type: 'GET', 196 url: baseDir + 'modules/blockwishlist/buywishlistproduct.php?rand=' + new Date().getTime(), 197 headers: { "cache-control": "no-cache" }, 198 data: 'token=' + token + '&static_token=' + static_token + '&id_product=' + id_product + '&id_product_attribute=' + id_product_attribute, 199 async: true, 200 cache: false, 201 success: function(data) 202 { 203 if (data) 204 { 205 if (!!$.prototype.fancybox) 206 $.fancybox.open([ 207 { 208 type: 'inline', 209 autoScale: true, 210 minHeight: 30, 211 content: '<p class="fancybox-error">' + data + '</p>' 212 } 213 ], { 214 padding: 0 215 }); 216 else 217 alert(data); 218 } 219 else 220 $('#' + id_quantity).val($('#' + id_quantity).val() - 1); 221 } 222 }); 223 224 return (true); 225} 226 227/** 228* Show wishlist managment page 229* 230* @return void 231*/ 232function WishlistManage(id, id_wishlist) 233{ 234 $.ajax({ 235 type: 'GET', 236 async: true, 237 url: baseDir + 'modules/blockwishlist/managewishlist.php?rand=' + new Date().getTime(), 238 headers: { "cache-control": "no-cache" }, 239 data: 'id_wishlist=' + id_wishlist + '&refresh=' + false, 240 cache: false, 241 success: function(data) 242 { 243 $('#' + id).hide(); 244 document.getElementById(id).innerHTML = data; 245 $('#' + id).fadeIn('slow'); 246 247 $('.wishlist_change_button').each(function(index) { 248 $(this).change(function () { 249 wishlistProductChange($('option:selected', this).attr('data-id-product'), $('option:selected', this).attr('data-id-product-attribute'), $('option:selected', this).attr('data-id-old-wishlist'), $('option:selected', this).attr('data-id-new-wishlist')); 250 }); 251 }); 252 } 253 }); 254} 255 256/** 257* Show wishlist product managment page 258* 259* @return void 260*/ 261function WishlistProductManage(id, action, id_wishlist, id_product, id_product_attribute, quantity, priority) 262{ 263 $.ajax({ 264 type: 'GET', 265 async: true, 266 url: baseDir + 'modules/blockwishlist/managewishlist.php?rand=' + new Date().getTime(), 267 headers: { "cache-control": "no-cache" }, 268 data: 'action=' + action + '&id_wishlist=' + id_wishlist + '&id_product=' + id_product + '&id_product_attribute=' + id_product_attribute + '&quantity=' + quantity + '&priority=' + priority + '&refresh=' + true, 269 cache: false, 270 success: function(data) 271 { 272 if (action == 'delete') 273 $('#wlp_' + id_product + '_' + id_product_attribute).fadeOut('fast'); 274 else if (action == 'update') 275 { 276 $('#wlp_' + id_product + '_' + id_product_attribute).fadeOut('fast'); 277 $('#wlp_' + id_product + '_' + id_product_attribute).fadeIn('fast'); 278 } 279 nb_products = 0; 280 $("[id^='quantity']").each(function(index, element){ 281 nb_products += parseInt(element.value); 282 }); 283 $("#wishlist_"+id_wishlist).children('td').eq(1).html(nb_products); 284 } 285 }); 286} 287 288/** 289* Delete wishlist 290* 291* @return boolean succeed 292*/ 293function WishlistDelete(id, id_wishlist, msg) 294{ 295 var res = confirm(msg); 296 if (res == false) 297 return (false); 298 299 if (typeof mywishlist_url == 'undefined') 300 return (false); 301 302 $.ajax({ 303 type: 'GET', 304 async: true, 305 dataType: "json", 306 url: mywishlist_url, 307 headers: { "cache-control": "no-cache" }, 308 cache: false, 309 data: { 310 rand: new Date().getTime(), 311 deleted: 1, 312 myajax: 1, 313 id_wishlist: id_wishlist, 314 action: 'deletelist' 315 }, 316 success: function(data) 317 { 318 var mywishlist_siblings_count = $('#' + id).siblings().length; 319 $('#' + id).fadeOut('slow').remove(); 320 $("#block-order-detail").html(''); 321 if (mywishlist_siblings_count == 0) 322 $("#block-history").remove(); 323 324 if (data.id_default) 325 { 326 var td_default = $("#wishlist_"+data.id_default+" > .wishlist_default"); 327 $("#wishlist_"+data.id_default+" > .wishlist_default > a").remove(); 328 td_default.append('<p class="is_wish_list_default"><i class="icon icon-check-square"></i></p>'); 329 } 330 } 331 }); 332} 333 334function WishlistDefault(id, id_wishlist) 335{ 336 if (typeof mywishlist_url == 'undefined') 337 return (false); 338 339 $.ajax({ 340 type: 'GET', 341 async: true, 342 url: mywishlist_url, 343 headers: { "cache-control": "no-cache" }, 344 cache: false, 345 data: { 346 rand:new Date().getTime(), 347 'default': 1, 348 id_wishlist:id_wishlist, 349 myajax: 1, 350 action: 'setdefault' 351 }, 352 success: function (data) 353 { 354 var old_default_id = $(".is_wish_list_default").parents("tr").attr("id"); 355 var td_check = $(".is_wish_list_default").parent(); 356 $(".is_wish_list_default").remove(); 357 td_check.append('<a href="#" onclick="javascript:event.preventDefault();(WishlistDefault(\''+old_default_id+'\', \''+old_default_id.replace("wishlist_", "")+'\'));"><i class="icon icon-square"></i></a>'); 358 var td_default = $("#"+id+" > .wishlist_default"); 359 $("#"+id+" > .wishlist_default > a").remove(); 360 td_default.append('<p class="is_wish_list_default"><i class="icon icon-check-square"></i></p>'); 361 } 362 }); 363} 364 365/** 366* Hide/Show bought product 367* 368* @return void 369*/ 370function WishlistVisibility(bought_class, id_button) 371{ 372 if ($('#hide' + id_button).is(':hidden')) 373 { 374 $('.' + bought_class).slideDown('fast'); 375 $('#show' + id_button).hide(); 376 $('#hide' + id_button).css('display', 'block'); 377 } 378 else 379 { 380 $('.' + bought_class).slideUp('fast'); 381 $('#hide' + id_button).hide(); 382 $('#show' + id_button).css('display', 'block'); 383 } 384} 385 386/** 387* Send wishlist by email 388* 389* @return void 390*/ 391function WishlistSend(id, id_wishlist, id_email) 392{ 393 $.post( 394 baseDir + 'modules/blockwishlist/sendwishlist.php', 395 { 396 token: static_token, 397 id_wishlist: id_wishlist, 398 email1: $('#' + id_email + '1').val(), 399 email2: $('#' + id_email + '2').val(), 400 email3: $('#' + id_email + '3').val(), 401 email4: $('#' + id_email + '4').val(), 402 email5: $('#' + id_email + '5').val(), 403 email6: $('#' + id_email + '6').val(), 404 email7: $('#' + id_email + '7').val(), 405 email8: $('#' + id_email + '8').val(), 406 email9: $('#' + id_email + '9').val(), 407 email10: $('#' + id_email + '10').val() 408 }, 409 function(data) 410 { 411 if (data) 412 { 413 if (!!$.prototype.fancybox) 414 $.fancybox.open([ 415 { 416 type: 'inline', 417 autoScale: true, 418 minHeight: 30, 419 content: '<p class="fancybox-error">' + data + '</p>' 420 } 421 ], { 422 padding: 0 423 }); 424 else 425 alert(data); 426 } 427 else 428 WishlistVisibility(id, 'hideSendWishlist'); 429 } 430 ); 431} 432 433function wishlistProductsIdsAdd(id) 434{ 435 if ($.inArray(parseInt(id),wishlistProductsIds) == -1) 436 wishlistProductsIds.push(parseInt(id)) 437} 438 439function wishlistProductsIdsRemove(id) 440{ 441 wishlistProductsIds.splice($.inArray(parseInt(id),wishlistProductsIds), 1) 442} 443 444function wishlistRefreshStatus() 445{ 446 $('.addToWishlist').each(function(){ 447 if ($.inArray(parseInt($(this).prop('rel')),wishlistProductsIds)!= -1) 448 $(this).addClass('checked'); 449 else 450 $(this).removeClass('checked'); 451 }); 452} 453 454function wishlistProductChange(id_product, id_product_attribute, id_old_wishlist, id_new_wishlist) 455{ 456 if (typeof mywishlist_url == 'undefined') 457 return (false); 458 459 var quantity = $('#quantity_' + id_product + '_' + id_product_attribute).val(); 460 461 $.ajax({ 462 type: 'GET', 463 url: mywishlist_url, 464 headers: { "cache-control": "no-cache" }, 465 async: true, 466 cache: false, 467 dataType: "json", 468 data: { 469 id_product:id_product, 470 id_product_attribute:id_product_attribute, 471 quantity: quantity, 472 priority: $('#priority_' + id_product + '_' + id_product_attribute).val(), 473 id_old_wishlist:id_old_wishlist, 474 id_new_wishlist:id_new_wishlist, 475 myajax: 1, 476 action: 'productchangewishlist' 477 }, 478 success: function (data) 479 {
480 console.log(data); 481 console.log(data.msg); 482 if (data.success == true) { 483 $('#wlp_' + id_product + '_' + id_product_attribute).fadeOut('slow'); 484 $('#wishlist_' + id_old_wishlist + ' td:nth-child(2)').text($('#wishlist_' + id_old_wishlist + ' td:nth-child(2)').text() - quantity); 485 $('#wishlist_' + id_new_wishlist + ' td:nth-child(2)').text(+$('#wishlist_' + id_new_wishlist + ' td:nth-child(2)').text() + +quantity); 486 } 487 else 488 { 489 if (!!$.prototype.fancybox) 490 $.fancybox.open([ 491 { 492 type: 'inline', 493 autoScale: true, 494 minHeight: 30, 495 content: '<p class="fancybox-error">' + data.error + '</p>' 496 } 497 ], { 498 padding: 0 499 }); 500 } 501 } 502 }); 503} 504 505 506var DORWISHLIST = { 507 init:function(){ 508 DORWISHLIST.Event(); 509 }, 510 Event:function(){ 511 var btnRemove = "<a href='#' class='btn btn-default btn-remove-wishlist' onclick='return false'><span><i class='material-icons hidden'>highlight_off</i><strong>Clear</strong></span></a>"; 512 jQuery("#mywishlist .product-miniature").each(function(){ 513 jQuery(this).find(".control-line-cart .add").append(btnRemove); 514 }); 515 } 516} 517 518jQuery(document).ready(function(){ 519 DORWISHLIST.init(); 520});
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.