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