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$(document).ready(function(){ 26 ajaxCart.overrideButtonsInThePage(); 27 28 $(document).on('click', '.block_cart_collapse', function(e){ 29 e.preventDefault(); 30 ajaxCart.collapse(); 31 }); 32 $(document).on('click', '.block_cart_expand', function(e){ 33 e.preventDefault(); 34 ajaxCart.expand(); 35 }); 36 37 var current_timestamp = parseInt(new Date().getTime() / 1000); 38 39 if (typeof $('.ajax_cart_quantity').html() == 'undefined' || (typeof generated_date != 'undefined' && generated_date != null && (parseInt(generated_date) + 30) < current_timestamp)) 40 ajaxCart.refresh(); 41 42 /* roll over cart */ 43 var cart_block = new HoverWatcher('#header .cart_block'); 44 var shopping_cart = new HoverWatcher('#header .shopping_cart'); 45 var is_touch_enabled = false; 46 47 if ('ontouchstart' in document.documentElement) 48 is_touch_enabled = true; 49 50 $(document).on('click', '#header .shopping_cart > a:first', function(e){ 51 e.preventDefault(); 52 e.stopPropagation(); 53 54 // Simulate hover when browser says device is touch based 55 56 if ($(this).next('.cart_block:visible').length && !cart_block.isHoveringOver()) 57 $("#header .cart_block").stop(true, true).slideUp(450); 58 else if (ajaxCart.nb_total_products > 0 || parseInt($('.ajax_cart_quantity').html()) > 0) 59 $("#header .cart_block").stop(true, true).slideDown(450); 60 return; 61 } 62 ); 63 64 65 $(document).on('click', '.delete_voucher', function(e){ 66 e.preventDefault(); 67 $.ajax({ 68 type: 'POST', 69 headers: { "cache-control": "no-cache" }, 70 async: true, 71 cache: false, 72 url:$(this).attr('href') + '?rand=' + new Date().getTime() 73 }); 74 $(this).parent().parent().remove(); 75 ajaxCart.refresh(); 76 if ($('body').attr('id') == 'order' || $('body').attr('id') == 'order-opc') 77 { 78 if (typeof(updateAddressSelection) != 'undefined') 79 updateAddressSelection(); 80 else 81 location.reload(); 82 } 83 }); 84 85 $(document).on('click', '#cart_navigation input', function(e){ 86 $(this).prop('disabled', 'disabled').addClass('disabled'); 87 $(this).closest("form").get(0).submit(); 88 }); 89 90 $(document).on('click', '#layer_cart .cross, #layer_cart .continue, .layer_cart_overlay', function(e){ 91 e.preventDefault(); 92 $('.layer_cart_overlay').hide(); 93 $('#layer_cart').fadeOut('fast'); 94 }); 95 96 $('#columns #layer_cart, #columns .layer_cart_overlay').detach().prependTo('#columns'); 97}); 98 99//JS Object : update the cart by ajax actions 100var ajaxCart = { 101 nb_total_products: 0, 102 //override every button in the page in relation to the cart 103 overrideButtonsInThePage : function(){ 104 //for every 'add' buttons... 105 $(document).off('click', '.ajax_add_to_cart_button').on('click', '.ajax_add_to_cart_button', function(e){ 106 e.preventDefault(); 107 var idProduct = parseInt($(this).data('id-product')); 108 var idProductAttribute = parseInt($(this).data('id-product-attribute')); 109 var minimalQuantity = parseInt($(this).data('minimal_quantity')); 110 if (!minimalQuantity) 111 minimalQuantity = 1; 112 if ($(this).prop('disabled') != 'disabled') 113 ajaxCart.add(idProduct, idProductAttribute, false, this, minimalQuantity); 114 }); 115 //for product page 'add' button... 116 if ($('.cart_block').length) { 117 $(document).off('click', '#add_to_cart button').on('click', '#add_to_cart button', function(e){ 118 e.preventDefault(); 119 ajaxCart.add($('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null); 120 }); 121 } 122 123 //for 'delete' buttons in the cart block... 124 $(document).off('click', '.cart_block_list .ajax_cart_block_remove_link').on('click', '.cart_block_list .ajax_cart_block_remove_link', function(e){ 125 e.preventDefault(); 126 // Customized product management 127 var customizationId = 0; 128 var productId = 0; 129 var productAttributeId = 0; 130 var customizableProductDiv = $($(this).parent().parent()).find("div[data-id^=deleteCustomizableProduct_]"); 131 var idAddressDelivery = false;
132 133 if (customizableProductDiv && $(customizableProductDiv).length) 134 { 135 var ids = customizableProductDiv.data('id').split('_'); 136 if (typeof(ids[1]) != 'undefined') 137 { 138 customizationId = parseInt(ids[1]); 139 productId = parseInt(ids[2]); 140 if (typeof(ids[3]) != 'undefined') 141 productAttributeId = parseInt(ids[3]); 142 if (typeof(ids[4]) != 'undefined') 143 idAddressDelivery = parseInt(ids[4]); 144 } 145 } 146 147 // Common product management 148 if (!customizationId) 149 { 150 //retrieve idProduct and idCombination from the displayed product in the block cart 151 var firstCut = $(this).parent().parent().data('id').replace('cart_block_product_', ''); 152 firstCut = firstCut.replace('deleteCustomizableProduct_', ''); 153 ids = firstCut.split('_'); 154 productId = parseInt(ids[0]); 155 156 if (typeof(ids[1]) != 'undefined') 157 productAttributeId = parseInt(ids[1]); 158 if (typeof(ids[2]) != 'undefined') 159 idAddressDelivery = parseInt(ids[2]); 160 } 161 162 // Removing product from the cart 163 ajaxCart.remove(productId, productAttributeId, customizationId, idAddressDelivery); 164 }); 165 }, 166 167 // try to expand the cart 168 expand : function(){ 169 if ($('.cart_block_list').hasClass('collapsed')) 170 { 171 $('.cart_block_list.collapsed').slideDown({ 172 duration: 450, 173 complete: function(){ 174 $(this).parent().show(); // parent is hidden in global.js::accordion() 175 $(this).addClass('expanded').removeClass('collapsed'); 176 } 177 }); 178 179 // save the expand statut in the user cookie 180 $.ajax({ 181 type: 'POST', 182 headers: { "cache-control": "no-cache" }, 183 url: baseDir + 'modules/blockcart/blockcart-set-collapse.php' + '?rand=' + new Date().getTime(), 184 async: true, 185 cache: false, 186 data: 'ajax_blockcart_display=expand', 187 complete: function(){ 188 $('.block_cart_expand').fadeOut('fast', function(){ 189 $('.block_cart_collapse').fadeIn('fast'); 190 }); 191 } 192 }); 193 } 194 }, 195 196 // try to collapse the cart 197 collapse : function(){ 198 if ($('.cart_block_list').hasClass('expanded')) 199 { 200 $('.cart_block_list.expanded').slideUp('slow', function(){ 201 $(this).addClass('collapsed').removeClass('expanded'); 202 }); 203 204 // save the expand statut in the user cookie 205 $.ajax({ 206 type: 'POST', 207 headers: { "cache-control": "no-cache" }, 208 url: baseDir + 'modules/blockcart/blockcart-set-collapse.php' + '?rand=' + new Date().getTime(), 209 async: true, 210 cache: false, 211 data: 'ajax_blockcart_display=collapse' + '&rand=' + new Date().getTime(), 212 complete: function(){ 213 $('.block_cart_collapse').fadeOut('fast', function(){ 214 $('.block_cart_expand').fadeIn('fast'); 215 }); 216 } 217 }); 218 } 219 }, 220 // Fix display when using back and previous browsers buttons 221 refresh : function(){ 222 $.ajax({ 223 type: 'POST', 224 headers: { "cache-control": "no-cache" }, 225 url: (typeof(baseUri) !== 'undefined') ? baseUri + '?rand=' + new Date().getTime() : '', 226 async: true, 227 cache: false, 228 dataType : "json", 229 data: (typeof(static_token) !== 'undefined') ? 'controller=cart&ajax=true&token=' + static_token : '', 230 success: function(jsonData) 231 { 232 ajaxCart.updateCart(jsonData); 233 } 234 }); 235 }, 236 237 // Update the cart information 238 updateCartInformation : function (jsonData, addedFromProductPage){ 239 ajaxCart.updateCart(jsonData); 240 //reactive the button when adding has finished 241 if (addedFromProductPage) 242 { 243 $('#add_to_cart button').removeProp('disabled').removeClass('disabled'); 244 if (!jsonData.hasError || jsonData.hasError == false) 245 $('#add_to_cart button').addClass('added'); 246 else 247 $('#add_to_cart button').removeClass('added'); 248 } 249 else 250 $('.ajax_add_to_cart_button').removeProp('disabled'); 251 }, 252 // close fancybox 253 updateFancyBox : function (){}, 254 // add a product in the cart via ajax 255 add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist){ 256 257 if (addedFromProductPage && !checkCustomizations()) 258 { 259 if (contentOnly) 260 { 261 var productUrl = window.document.location.href + ''; 262 var data = productUrl.replace('content_only=1', ''); 263 window.parent.document.location.href = data; 264 return; 265 } 266 if (!!$.prototype.fancybox) 267 $.fancybox.open([ 268 { 269 type: 'inline', 270 autoScale: true, 271 minHeight: 30, 272 content: '<p class="fancybox-error">' + fieldRequired + '</p>' 273 } 274 ], { 275 padding: 0 276 }); 277 else 278 alert(fieldRequired); 279 return; 280 } 281 282 //disabled the button when adding to not double add if user double click 283 if (addedFromProductPage) 284 { 285 $('#add_to_cart button').prop('disabled', 'disabled').addClass('disabled'); 286 $('.filled').removeClass('filled'); 287 } 288 else 289 $(callerElement).prop('disabled', 'disabled'); 290 291 if ($('.cart_block_list').hasClass('collapsed')) 292 this.expand();
293 //send the ajax request to the server 294 //window.alert ("test2"); 295 $.ajax({ 296 type: 'POST', 297 headers: { "cache-control": "no-cache" }, 298 url: baseUri + '?rand=' + new Date().getTime(), 299 async: true, 300 cache: false, 301 dataType : "json", 302 data: 'controller=cart&add=1&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): '' + '&id_customization=' + ((typeof customizationId !== 'undefined') ? customizationId : 0)), 303 success: function(jsonData,textStatus,jqXHR) 304 { 305 //window.alert("test3s"); 306 // add appliance to whishlist module 307 if (whishlist && !jsonData.errors) 308 WishlistAddProductCart(whishlist[0], idProduct, idCombination, whishlist[1]); 309 310 if (!jsonData.hasError) 311 { 312 if (contentOnly) 313 window.parent.ajaxCart.updateCartInformation(jsonData, addedFromProductPage); 314 else 315 ajaxCart.updateCartInformation(jsonData, addedFromProductPage); 316 317 if (jsonData.crossSelling) 318 $('.crossseling').html(jsonData.crossSelling); 319 320 if (idCombination) 321 $(jsonData.products).each(function(){ 322 if (this.id != undefined && this.id == parseInt(idProduct) && this.idCombination == parseInt(idCombination)) 323 if (contentOnly) 324 window.parent.ajaxCart.updateLayer(this); 325 else 326 ajaxCart.updateLayer(this); 327 }); 328 else 329 $(jsonData.products).each(function(){ 330 if (this.id != undefined && this.id == parseInt(idProduct)) 331 if (contentOnly) 332 window.parent.ajaxCart.updateLayer(this); 333 else 334 ajaxCart.updateLayer(this); 335 }); 336 if (contentOnly) 337 parent.$.fancybox.close(); 338 } 339 else 340 { 341 if (contentOnly) 342 window.parent.ajaxCart.updateCart(jsonData); 343 else 344 ajaxCart.updateCart(jsonData); 345 if (addedFromProductPage) 346 $('#add_to_cart button').removeProp('disabled').removeClass('disabled'); 347 else 348 $(callerElement).removeProp('disabled'); 349 } 350 351 emptyCustomizations(); 352 353 }, 354 error: function(XMLHttpRequest, textStatus, errorThrown) 355 { 356 var error = "Impossible to add the product to the cart.<br/>textStatus: '" + textStatus + "'<br/>errorThrown: '" + errorThrown + "'<br/>responseText:<br/>" + XMLHttpRequest.responseText; 357 if (!!$.prototype.fancybox) 358 $.fancybox.open([ 359 { 360 type: 'inline', 361 autoScale: true, 362 minHeight: 30, 363 content: '<p class="fancybox-error">' + error + '</p>' 364 }], 365 { 366 padding: 0 367 }); 368 else 369 alert(error); 370 //reactive the button when adding has finished 371 if (addedFromProductPage) 372 $('#add_to_cart button').removeProp('disabled').removeClass('disabled'); 373 else 374 $(callerElement).removeProp('disabled'); 375 } 376 }); 377 }, 378 379 //remove a product from the cart via ajax 380 remove : function(idProduct, idCombination, customizationId, idAddressDelivery){ 381 //send the ajax request to the server 382 $.ajax({ 383 type: 'POST', 384 headers: { "cache-control": "no-cache" }, 385 url: baseUri + '?rand=' + new Date().getTime(), 386 async: true, 387 cache: false, 388 dataType : "json", 389 data: 'controller=cart&delete=1&id_product=' + idProduct + '&ipa=' + ((idCombination != null && parseInt(idCombination)) ? idCombination : '') + ((customizationId && customizationId != null) ? '&id_customization=' + customizationId : '') + '&id_address_delivery=' + idAddressDelivery + '&token=' + static_token + '&ajax=true', 390 success: function(jsonData) { 391 ajaxCart.updateCart(jsonData); 392 if ($('body').attr('id') == 'order' || $('body').attr('id') == 'order-opc') 393 deleteProductFromSummary(idProduct+'_'+idCombination+'_'+customizationId+'_'+idAddressDelivery); 394 }, 395 error: function() 396 { 397 var error = 'ERROR: unable to delete the product'; 398 if (!!$.prototype.fancybox) 399 { 400 $.fancybox.open([ 401 { 402 type: 'inline', 403 autoScale: true, 404 minHeight: 30, 405 content: error 406 } 407 ], { 408 padding: 0 409 }); 410 } 411 else 412 alert(error); 413 } 414 }); 415 }, 416 417 //hide the products displayed in the page but no more in the json data 418 hideOldProducts : function(jsonData){ 419 //delete an eventually removed product of the displayed cart (only if cart is not empty!) 420 if ($('.cart_block_list:first dl.products').length > 0) 421 { 422 var removedProductId = null; 423 var removedProductData = null; 424 var removedProductDomId = null; 425 //look for a product to delete... 426 $('.cart_block_list:first dl.products dt').each(function(){ 427 //retrieve idProduct and idCombination from the displayed product in the block cart 428 var domIdProduct = $(this).data('id'); 429 var firstCut = domIdProduct.replace('cart_block_product_', ''); 430 var ids = firstCut.split('_'); 431 432 //try to know if the current product is still in the new list 433 var stayInTheCart = false;
434 for (aProduct in jsonData.products) 435 { 436 //we've called the variable aProduct because IE6 bug if this variable is called product 437 //if product has attributes 438 if (jsonData.products[aProduct]['id'] == ids[0] && (!ids[1] || jsonData.products[aProduct]['idCombination'] == ids[1])) 439 { 440 stayInTheCart = true; 441 // update the product customization display (when the product is still in the cart) 442 ajaxCart.hideOldProductCustomizations(jsonData.products[aProduct], domIdProduct); 443 } 444 } 445 //remove product if it's no more in the cart 446 if (!stayInTheCart) 447 { 448 removedProductId = $(this).data('id'); 449 if (removedProductId != null) 450 { 451 var firstCut = removedProductId.replace('cart_block_product_', ''); 452 var ids = firstCut.split('_'); 453 454 $('dt[data-id="' + removedProductId + '"]').addClass('strike').fadeTo('slow', 0, function(){ 455 $(this).slideUp('slow', function(){ 456 $(this).remove(); 457 // If the cart is now empty, show the 'no product in the cart' message and close detail 458 if($('.cart_block:first dl.products dt').length == 0) 459 { 460 $('.ajax_cart_quantity').html('0'); 461 $("#header .cart_block").stop(true, true).slideUp(200); 462 $('.cart_block_no_products:hidden').slideDown(450); 463 $('.cart_block dl.products').remove(); 464 } 465 }); 466 }); 467 $('dd[data-id="cart_block_combination_of_' + ids[0] + (ids[1] ? '_'+ids[1] : '') + (ids[2] ? '_'+ids[2] : '') + '"]').fadeTo('fast', 0, function(){ 468 $(this).slideUp('fast', function(){ 469 $(this).remove(); 470 }); 471 }); 472 } 473 } 474 }); 475 } 476 }, 477 478 hideOldProductCustomizations : function (product, domIdProduct){ 479 var customizationList = $('ul[data-id="customization_' + product['id'] + '_' + product['idCombination'] + '"]'); 480 if(customizationList.length > 0) 481 { 482 $(customizationList).find("li").each(function(){ 483 $(this).find("div").each(function(){ 484 var customizationDiv = $(this).data('id'); 485 var tmp = customizationDiv.replace('deleteCustomizableProduct_', ''); 486 var ids = tmp.split('_'); 487 if ((parseInt(product.idCombination) == parseInt(ids[2])) && !ajaxCart.doesCustomizationStillExist(product, ids[0])) 488 $('div[data-id="' + customizationDiv + '"]').parent().addClass('strike').fadeTo('slow', 0, function(){ 489 $(this).slideUp('slow'); 490 $(this).remove(); 491 }); 492 }); 493 }); 494 } 495 496 var removeLinks = $('.deleteCustomizableProduct[data-id="' + domIdProduct + '"]').find('.ajax_cart_block_remove_link'); 497 if (!product.hasCustomizedDatas && !removeLinks.length) 498 $('div[data-id="' + domIdProduct + '"]' + ' span.remove_link').html('<a class="ajax_cart_block_remove_link" rel="nofollow" href="' + baseUri + '?controller=cart&delete=1&id_product=' + product['id'] + '&ipa=' + product['idCombination'] + '&
498token=' + static_token + '"> </a>'); 499 if (product.is_gift) 500 $('div[data-id="' + domIdProduct + '"]' + ' span.remove_link').html(''); 501 }, 502 503 doesCustomizationStillExist : function (product, customizationId){ 504 var exists = false; 505 506 $(product.customizedDatas).each(function(){ 507 if (this.customizationId == customizationId) 508 { 509 exists = true; 510 // This return does not mean that we found nothing but simply break the loop 511 return false; 512 } 513 }); 514 return (exists); 515 }, 516 517 //refresh display of vouchers (needed for vouchers in % of the total) 518 refreshVouchers : function (jsonData){ 519 if (typeof(jsonData.discounts) == 'undefined' || jsonData.discounts.length == 0) 520 $('.vouchers').hide(); 521 else 522 { 523 $('.vouchers tbody').html(''); 524 525 for (i=0;i<jsonData.discounts.length;i++) 526 { 527 if (parseFloat(jsonData.discounts[i].price_float) > 0) 528 { 529 var delete_link = ''; 530 if (jsonData.discounts[i].code.length) 531 delete_link = '<a class="delete_voucher" href="'+jsonData.discounts[i].link+'" title="'+delete_txt+'"><i class="icon-remove-sign"></i></a>'; 532 $('.vouchers tbody').append($( 533 '<tr class="bloc_cart_voucher" data-id="bloc_cart_voucher_'+jsonData.discounts[i].id+'">' 534 +' <td class="quantity">1x</td>' 535 +' <td class="name" title="'+jsonData.discounts[i].description+'">'+jsonData.discounts[i].name+'</td>' 536 +' <td class="price">-'+jsonData.discounts[i].price+'</td>' 537 +' <td class="delete">' + delete_link + '</td>' 538 +'</tr>' 539 )); 540 } 541 } 542 $('.vouchers').show(); 543 } 544 545 }, 546 547 // Update product quantity 548 updateProductQuantity : function (product, quantity){ 549 $('dt[data-id=cart_block_product_' + product.id + '_' + (product.idCombination ? product.idCombination : '0')+ '_' + (product.idAddressDelivery ? product.idAddressDelivery : '0') + '] .quantity').fadeTo('fast', 0, function(){ 550 $(this).text(quantity); 551 $(this).fadeTo('fast', 1, function(){ 552 $(this).fadeTo('fast', 0, function(){ 553 $(this).fadeTo('fast', 1, function(){ 554 $(this).fadeTo('fast', 0, function(){ 555 $(this).fadeTo('fast', 1); 556 }); 557 }); 558 }); 559 }); 560 }); 561 }, 562 563 //display the products witch are in json data but not already displayed 564 displayNewProducts : function(jsonData){ 565 //add every new products or update displaying of every updated products 566 $(jsonData.products).each(function(){ 567 //fix ie6 bug (one more item 'undefined' in IE6) 568 if (this.id != undefined) 569 { 570 //create a container for listing the products and hide the 'no product in the cart' message (only if the cart was empty) 571 572 if ($('.cart_block:first dl.products').length == 0) 573 { 574 $('.cart_block_no_products').before('<dl class="products"></dl>'); 575 $('.cart_block_no_products').hide(); 576 } 577 //if product is not in the displayed cart, add a new product's line 578 var domIdProduct = this.id + '_' + (this.idCombination ? this.idCombination : '0') + '_' + (this.idAddressDelivery ? this.idAddressDelivery : '0'); 579 var domIdProductAttribute = this.id + '_' + (this.idCombination ? this.idCombination : '0'); 580 581 if ($('dt[data-id="cart_block_product_' + domIdProduct + '"]').length == 0) 582 { 583 var productId = parseInt(this.id); 584 var productAttributeId = (this.hasAttributes ? parseInt(this.attributes) : 0); 585 var content = '<dt class="unvisible" data-id="cart_block_product_' + domIdProduct + '">'; 586 var name = $.trim($('<span />').html(this.name).text()); 587 //name = (name.length > 12 ? name.substring(0, 10) + '...' : name); 588 content += '<a class="cart-images" href="' + this.link + '" title="' + name + '"><img src="' + this.image_cart + '" alt="' + this.name +'"></a>'; 589 content += '<div class="cart-info"><div class="product-name">' + '<span class="quantity-formated"><span class="quantity">' + this.quantity + '</span> x </span><a href="' + this.link + '" title="' + this.name + '" class="cart_block_product_name">' + name + '</a></div>'; 590 if (this.hasAttributes) 591 content += '<div class="product-atributes"><a href="' + this.link + '" title="' + this.name + '">' + this.attributes + '</a></div>'; 592 if (typeof(freeProductTranslation) != 'undefined') 593 content += '<span class="price">' + (parseFloat(this.price_float) > 0 ? this.priceByLine : freeProductTranslation) + '</span></div>'; 594 595 if (typeof(this.is_gift) == 'undefined' || this.is_gift == 0) 596 content += '<span class="remove_link"><a rel="nofollow" class="ajax_cart_block_remove_link" href="' + baseUri + '?controller=cart&delete=1&id_product=' + productId + '&
596token=' + static_token + (this.hasAttributes ? '&ipa=' + parseInt(this.idCombination) : '') + '"> </a></span><br clear="all">'; 597 else 598 content += '<span class="remove_link"></span><br clear="all">'; 599 content += '</dt>'; 600 if (this.hasAttributes) 601 content += '<dd data-id="cart_block_combination_of_' + domIdProduct + '" class="unvisible">'; 602 if (this.hasCustomizedDatas) 603 content += ajaxCart.displayNewCustomizedDatas(this); 604 if (this.hasAttributes) content += '</dd>'; 605 606 $('.cart_block dl.products').append(content); 607 } 608 //else update the product's line 609 else 610 { 611 var jsonProduct = this; 612 if($.trim($('dt[data-id="cart_block_product_' + domIdProduct + '"] .quantity').html()) != jsonProduct.quantity || $.trim($('dt[data-id="cart_block_product_' + domIdProduct + '"] .price').html()) != jsonProduct.priceByLine) 613 { 614 // Usual product 615 if (!this.is_gift) 616 $('dt[data-id="cart_block_product_' + domIdProduct + '"] .price').text(jsonProduct.priceByLine); 617 else 618 $('dt[data-id="cart_block_product_' + domIdProduct + '"] .price').html(freeProductTranslation); 619 ajaxCart.updateProductQuantity(jsonProduct, jsonProduct.quantity); 620 621 // Customized product 622 if (jsonProduct.hasCustomizedDatas) 623 { 624 customizationFormatedDatas = ajaxCart.displayNewCustomizedDatas(jsonProduct); 625 if (!$('ul[data-id="customization_' + domIdProductAttribute + '"]').length) 626 { 627 if (jsonProduct.hasAttributes) 628 $('dd[data-id="cart_block_combination_of_' + domIdProduct + '"]').append(customizationFormatedDatas); 629 else 630 $('.cart_block dl.products').append(customizationFormatedDatas); 631 } 632 else 633 { 634 $('ul[data-id="customization_' + domIdProductAttribute + '"]').html(''); 635 $('ul[data-id="customization_' + domIdProductAttribute + '"]').append(customizationFormatedDatas); 636 } 637 } 638 } 639 } 640 $('.cart_block dl.products .unvisible').slideDown(450).removeClass('unvisible'); 641 642 var removeLinks = $('dt[data-id="cart_block_product_' + domIdProduct + '"]').find('a.ajax_cart_block_remove_link'); 643 if (this.hasCustomizedDatas && removeLinks.length) 644 $(removeLinks).each(function(){ 645 $(this).remove(); 646 }); 647 } 648 }); 649 }, 650 651 displayNewCustomizedDatas : function(product){ 652 var content = ''; 653 var productId = parseInt(product.id); 654 var productAttributeId = typeof(product.idCombination) == 'undefined' ? 0 : parseInt(product.idCombination); 655 var hasAlreadyCustomizations = $('ul[data-id="customization_' + productId + '_' + productAttributeId + '"]').length; 656 657 if (!hasAlreadyCustomizations) 658 { 659 if (!product.hasAttributes) 660 content += '<dd data-id="cart_block_combination_of_' + productId + '" class="unvisible">'; 661 if ($('ul[data-id="customization_' + productId + '_' + productAttributeId + '"]').val() == undefined) 662 content += '<ul class="cart_block_customizations" data-id="customization_' + productId + '_' + productAttributeId + '">'; 663 } 664 665 $(product.customizedDatas).each(function(){ 666 var done = 0; 667 customizationId = parseInt(this.customizationId); 668 productAttributeId = typeof(product.idCombination) == 'undefined' ? 0 : parseInt(product.idCombination); 669 content += '<li name="customization"><div class="deleteCustomizableProduct" data-id="deleteCustomizableProduct_' + customizationId + '_' + productId + '_' + (productAttributeId ? productAttributeId : '0') + '"><a rel="nofollow" class="ajax_cart_block_remove_link" href="' + baseUri + '?controller=cart&delete=1&id_product=' + productId + '&ipa=' + productAttributeId + '&id_customization=' + customizationId + '&
669token=' + static_token + '"></a></div>'; 670 671 // Give to the customized product the first textfield value as name 672 $(this.datas).each(function(){ 673 if (this['type'] == CUSTOMIZE_TEXTFIELD) 674 { 675 $(this.datas).each(function(){ 676 if (this['index'] == 0) 677 { 678 content += ' ' + this.truncatedValue.replace(/<br \/>/g, ' '); 679 done = 1; 680 return false; 681 } 682 }) 683 } 684 }); 685 686 // If the customized product did not have any textfield, it will have the customizationId as name 687 if (!done) 688 content += customizationIdMessage + customizationId; 689 if (!hasAlreadyCustomizations) content += '</li>'; 690 // Field cleaning 691 if (customizationId) 692 { 693 $('#uploadable_files li div.customizationUploadBrowse img').remove(); 694 $('#text_fields input').attr('value', ''); 695 } 696 }); 697 698 if (!hasAlreadyCustomizations) 699 { 700 content += '</ul>'; 701 if (!product.hasAttributes) content += '</dd>'; 702 } 703 return (content); 704 }, 705 706 updateLayer : function(product){ 707 708 $('#layer_cart_product_title').text(product.name); 709 $('#layer_cart_product_attributes').text(''); 710 if (product.hasAttributes && product.hasAttributes == true) 711 $('#layer_cart_product_attributes').html(product.attributes); 712 $('#layer_cart_product_price').text(product.price); 713 $('#layer_cart_product_quantity').text(product.quantity); 714 $('.layer_cart_img').html('<img class="layer_cart_img img-responsive" src="' + product.image + '" alt="' + product.name + '" title="' + product.name + '" />'); 715 716 //var n = '0 px'; 717 var n = parseInt($(window).scrollTop()) + 'px'; 718 $('.layer_cart_overlay').css('width','100%'); 719 $('.layer_cart_overlay').css('height','100%'); 720 $('.layer_cart_overlay').show(); 721 $('#layer_cart').css({'top': n}).fadeIn('fast'); 722 crossselling_serialScroll(); 723 }, 724 725 //genarally update the display of the cart 726 updateCart : function(jsonData){ 727 //user errors display 728 if (jsonData.hasError) 729 { 730 var errors = ''; 731 for (error in jsonData.errors) 732 //IE6 bug fix 733 if (error != 'indexOf') 734 errors += $('<div />').html(jsonData.errors[error]).text() + "\n"; 735 if (!!$.prototype.fancybox) 736 $.fancybox.open([ 737 { 738 type: 'inline', 739 autoScale: true, 740 minHeight: 30, 741 content: '<p class="fancybox-error">' + errors + '</p>' 742 } 743 ], { 744 padding: 0 745 }); 746 else 747 alert(errors); 748 } 749 else 750 { 751 ajaxCart.updateCartEverywhere(jsonData); 752 ajaxCart.hideOldProducts(jsonData); 753 ajaxCart.displayNewProducts(jsonData); 754 ajaxCart.refreshVouchers(jsonData); 755 756 //update 'first' and 'last' item classes 757 $('.cart_block .products dt').removeClass('first_item').removeClass('last_item').removeClass('item'); 758 $('.cart_block .products dt:first').addClass('first_item'); 759 $('.cart_block .products dt:not(:first,:last)').addClass('item'); 760 $('.cart_block .products dt:last').addClass('last_item'); 761 } 762 }, 763 764 //update general cart informations everywhere in the page 765 updateCartEverywhere : function(jsonData){ 766 $('.ajax_cart_total').text($.trim(jsonData.productTotal)); 767 768 if (typeof hasDeliveryAddress == 'undefined') 769 hasDeliveryAddress = false; 770 771 if (parseFloat(jsonData.shippingCostFloat) > 0) 772 $('.ajax_cart_shipping_cost').text(jsonData.shippingCost).parent().find('.unvisible').show(); 773 else if ((hasDeliveryAddress || typeof(orderProcess) !== 'undefined' && orderProcess == 'order-opc') && typeof(freeShippingTranslation) != 'undefined') 774 $('.ajax_cart_shipping_cost').html(freeShippingTranslation); 775 else if ((typeof toBeDetermined !== 'undefined') && !hasDeliveryAddress) 776 $('.ajax_cart_shipping_cost').html(toBeDetermined); 777 778 if (!jsonData.shippingCostFloat && !jsonData.free_ship) 779 $('.ajax_cart_shipping_cost').parent().find('.unvisible').hide(); 780 else if (hasDeliveryAddress && !jsonData.isVirtualCart) 781 $('.ajax_cart_shipping_cost').parent().find('.unvisible').show(); 782 783 $('.ajax_cart_tax_cost').text(jsonData.taxCost); 784 $('.cart_block_wrapping_cost').text(jsonData.wrappingCost); 785 $('.ajax_block_cart_total').text(jsonData.total); 786 $('.ajax_block_products_total').text(jsonData.productTotal); 787 $('.ajax_total_price_wt').text(jsonData.total_price_wt); 788 789 if (parseFloat(jsonData.freeShippingFloat) > 0) 790 { 791 $('.ajax_cart_free_shipping').html(jsonData.freeShipping); 792 $('.freeshipping').fadeIn(0); 793 } 794 else if (parseFloat(jsonData.freeShippingFloat) == 0) 795 $('.freeshipping').fadeOut(0); 796 797 this.nb_total_products = jsonData.nbTotalProducts; 798 799 if (parseInt(jsonData.nbTotalProducts) > 0) 800 { 801 $('.ajax_cart_no_product').hide(); 802 $('.ajax_cart_quantity').text(jsonData.nbTotalProducts); 803 $('.ajax_cart_quantity').fadeIn('slow'); 804 $('.ajax_cart_total').fadeIn('slow'); 805 806 if (parseInt(jsonData.nbTotalProducts) > 1) 807 { 808 $('.ajax_cart_product_txt').each( function (){ 809 $(this).hide(); 810 }); 811 812 $('.ajax_cart_product_txt_s').each( function (){ 813 $(this).show(); 814 }); 815 } 816 else 817 {
818 $('.ajax_cart_product_txt').each( function (){ 819 $(this).show(); 820 }); 821 822 $('.ajax_cart_product_txt_s').each( function (){ 823 $(this).hide(); 824 }); 825 } 826 } 827 else 828 { 829 $('.ajax_cart_quantity, .ajax_cart_product_txt_s, .ajax_cart_product_txt, .ajax_cart_total').each(function(){ 830 $(this).hide(); 831 }); 832 $('.ajax_cart_no_product').show('slow'); 833 } 834 } 835}; 836 837function HoverWatcher(selector) 838{ 839 this.hovering = false; 840 var self = this; 841 842 this.isHoveringOver = function(){ 843 return self.hovering; 844 } 845 846 $(selector).hover(function(){ 847 self.hovering = true; 848 }, function(){ 849 self.hovering = false; 850 }) 851} 852 853function crossselling_serialScroll() 854{ 855 if (!!$.prototype.bxSlider) 856 $('#blockcart_caroucel').bxSlider({ 857 minSlides: 2, 858 maxSlides: 4, 859 slideWidth: 178, 860 slideMargin: 20, 861 moveSlides: 1, 862 infiniteLoop: false, 863 hideControlOnEnd: true, 864 pager: false 865 }); 866}
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.