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 26$(document).ready(function(){ 27 $('.cart_quantity_up').off('click').on('click', function(e){ 28 e.preventDefault(); 29 upQuantity($(this).attr('id').replace('cart_quantity_up_', '')); 30 $('#' + $(this).attr('id').replace('_up_', '_down_')).removeClass('disabled'); 31 }); 32 $('.cart_quantity_down').off('click').on('click', function(e){ 33 e.preventDefault(); 34 downQuantity($(this).attr('id').replace('cart_quantity_down_', '')); 35 }); 36 $('.cart_quantity_delete' ).off('click').on('click', function(e){ 37 e.preventDefault(); 38 deleteProductFromSummary($(this).attr('id')); 39 }); 40 $('.cart_address_delivery').on('change', function(e){ 41 changeAddressDelivery($(this)); 42 }); 43 44 $(document).on('click', '.voucher_name', function(e){ 45 $('#discount_name').val($(this).data('code')); 46 }); 47 48 $('.cart_quantity_input').typeWatch({ 49 highlight: true, wait: 600, captureLength: 0, callback: function(val){ 50 updateQty(val, true, this.el); 51 } 52 }); 53 54 cleanSelectAddressDelivery(); 55 56 refreshDeliveryOptions(); 57 58 $('.delivery_option_radio').on('change', function(){ 59 refreshDeliveryOptions(); 60 }); 61 62 $('#allow_seperated_package').on('click', function(){ 63 $.ajax({ 64 type: 'POST', 65 headers: { "cache-control": "no-cache" }, 66 url: baseUri + '?rand=' + new Date().getTime(), 67 async: true, 68 cache: false, 69 dataType: 'json', 70 data: 'controller=cart&ajax=true' 71 + '&summary=true' 72 + '&allowSeperatedPackage=true' 73 + '&value=' 74 + ($(this).prop('checked') ? '1' : '0') 75 + '&token='+static_token 76 + '&allow_refresh=1', 77 success: function(jsonData) 78 { 79 if (jsonData.hasError) 80 { 81 var errors = ''; 82 for(var error in jsonData.errors) 83 //IE6 bug fix 84 if(error !== 'indexOf') 85 errors += $('<div />').html(jsonData.errors[error]).text() + "\n"; 86 if (!!$.prototype.fancybox) 87 $.fancybox.open([ 88 { 89 type: 'inline', 90 autoScale: true, 91 minHeight: 30, 92 content: '<p class="fancybox-error">' + errors + '</p>' 93 }], 94 { 95 padding: 0 96 }); 97 else 98 alert(errors); 99 $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); 100 } 101 else 102 { 103 if (jsonData.refresh) 104 window.location.href = window.location.href; 105 updateCartSummary(jsonData.summary); 106 if (window.ajaxCart != undefined) 107 ajaxCart.updateCart(jsonData); 108 updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); 109 updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); 110 if (typeof(getCarrierListAndUpdate) !== 'undefined') 111 getCarrierListAndUpdate(); 112 if (typeof(updatePaymentMethodsDisplay) !== 'undefined') 113 updatePaymentMethodsDisplay(); 114 } 115 } 116 }); 117 }); 118 119 $('#gift').checkboxChange(function(){ 120 $('#gift_div').show('slow'); 121 }, function(){ 122 $('#gift_div').hide('slow'); 123 }); 124 125 $('#enable-multishipping').checkboxChange( 126 function(){ 127 $('.standard-checkout').hide(0); 128 $('.multishipping-checkout').show(0); 129 }, 130 function(){ 131 $('.standard-checkout').show(0); 132 $('.multishipping-checkout').hide(0); 133 } 134 ); 135}); 136 137function cleanSelectAddressDelivery() 138{ 139 if (window.ajaxCart !== undefined) 140 { 141 //Removing "Ship to an other address" from the address delivery select option if there is not enought address 142 $.each($('.cart_address_delivery'), function(it, item) 143 { 144 var options = $(item).find('option'); 145 var address_count = 0; 146 147 var ids = $(item).attr('id').split('_'); 148 var id_product = ids[3]; 149 var id_product_attribute = ids[4]; 150 var id_address_delivery = ids[5]; 151 152 $.each(options, function(i) { 153 if ($(options[i]).val() > 0 154 && ($('#product_' + id_product + '_' + id_product_attribute + '_0_' + $(options[i]).val()).length == 0 // Check the address is not already used for a similare products 155 || id_address_delivery == $(options[i]).val() 156 ) 157 ) 158 address_count++; 159 }); 160 161 // Need at least two address to allow skipping products to multiple address
162 if (address_count < 2) 163 $($(item).find('option[value=-2]')).remove(); 164 else if($($(item).find('option[value=-2]')).length == 0) 165 $(item).append($('<option value="-2">' + ShipToAnOtherAddress + '</option>')); 166 }); 167 } 168} 169 170function changeAddressDelivery(obj) 171{ 172 var ids = obj.attr('id').split('_'); 173 var id_product = ids[3]; 174 var id_product_attribute = ids[4]; 175 var old_id_address_delivery = ids[5]; 176 var new_id_address_delivery = obj.val(); 177 178 if (new_id_address_delivery == old_id_address_delivery) 179 return; 180 181 if (new_id_address_delivery > 0) // Change the delivery address 182 { 183 $.ajax({ 184 type: 'POST', 185 headers: { "cache-control": "no-cache" }, 186 url: baseUri + '?rand=' + new Date().getTime(), 187 async: true, 188 cache: false, 189 dataType: 'json', 190 data: 'controller=cart&ajax=true&changeAddressDelivery=1&summary=1&id_product=' + id_product 191 + '&id_product_attribute='+id_product_attribute 192 + '&old_id_address_delivery='+old_id_address_delivery 193 + '&new_id_address_delivery='+new_id_address_delivery 194 + '&token='+static_token 195 + '&allow_refresh=1', 196 success: function(jsonData) 197 { 198 if (typeof(jsonData.hasErrors) != 'undefined' && jsonData.hasErrors) 199 { 200 if (!!$.prototype.fancybox) 201 $.fancybox.open([ 202 { 203 type: 'inline', 204 autoScale: true, 205 minHeight: 30, 206 content: '<p class="fancybox-error">' + jsonData.error + '</p>' 207 }], 208 { 209 padding: 0 210 }); 211 else 212 alert(jsonData.error); 213 214 // Reset the old address 215 $('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).val(old_id_address_delivery); 216 } 217 else 218 { 219 // The product exist 220 if ($('#product_' + id_product + '_' + id_product_attribute + '_0_' + new_id_address_delivery).length) 221 { 222 updateCartSummary(jsonData.summary); 223 if (window.ajaxCart != undefined) 224 ajaxCart.updateCart(jsonData); 225 updateCustomizedDatas(jsonData.customizedDatas); 226 updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); 227 updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); 228 if (typeof(getCarrierListAndUpdate) !== 'undefined') 229 getCarrierListAndUpdate(); 230 231 // @todo reverse the remove order 232 // This effect remove the current line, but it's better to remove the other one, and refresshing this one 233 $('#product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery).remove(); 234 235 // @todo improve customization upgrading 236 $('.product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery).remove(); 237 } 238 if (window.ajaxCart != undefined) 239 ajaxCart.updateCart(jsonData); 240 updateAddressId(id_product, id_product_attribute, old_id_address_delivery, new_id_address_delivery); 241 cleanSelectAddressDelivery(); 242 } 243 } 244 }); 245 } 246 else if (new_id_address_delivery == -1) // Adding a new address 247 window.location = $($('.address_add a')[0]).attr('href'); 248 else if (new_id_address_delivery == -2) // Add a new line for this product 249 { 250 // This test is will not usefull in the future 251 if (old_id_address_delivery == 0) 252 { 253 if (!!$.prototype.fancybox) 254 $.fancybox.open([ 255 { 256 type: 'inline', 257 autoScale: true, 258 minHeight: 30, 259 content: '<p class="fancybox-error">' + txtSelectAnAddressFirst + '</p>' 260 }], 261 { 262 padding: 0 263 }); 264 else 265 alert(txtSelectAnAddressFirst); 266 return false; 267 } 268 269 // Get new address to deliver 270 var id_address_delivery = 0; 271 var options = $('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery + ' option'); 272 $.each(options, function(i) { 273 // Check the address is not already used for a similare products 274 if ($(options[i]).val() > 0 && $(options[i]).val() !== old_id_address_delivery && $('#product_' + id_product + '_' + id_product_attribute + '_0_' + $(options[i]).val()).length == 0) 275 { 276 id_address_delivery = $(options[i]).val(); 277 return false;
278 } 279 }); 280 281 $.ajax({ 282 type: 'POST', 283 headers: { "cache-control": "no-cache" }, 284 url: baseUri + '?rand=' + new Date().getTime(), 285 async: true, 286 cache: false, 287 dataType: 'json', 288 context: obj, 289 data: 'controller=cart' 290 + '&ajax=true&duplicate=true&summary=true' 291 + '&id_product='+id_product 292 + '&id_product_attribute='+id_product_attribute 293 + '&id_address_delivery='+old_id_address_delivery 294 + '&new_id_address_delivery='+id_address_delivery 295 + '&token='+static_token 296 + '&allow_refresh=1', 297 success: function(jsonData) 298 { 299 if (jsonData.error && !!$.prototype.fancybox) 300 $.fancybox.open([ 301 { 302 type: 'inline', 303 autoScale: true, 304 minHeight: 30, 305 content: '<p class="fancybox-error">' + jsonData.error + '</p>' 306 }], 307 { 308 padding: 0 309 }); 310 else 311 alert(jsonData.error); 312 313 var line = $('#product_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery); 314 var new_line = line.clone(); 315 updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, new_line); 316 line.after(new_line); 317 new_line.find('input[name=quantity_' + id_product + '_' + id_product_attribute + '_0_' + old_id_address_delivery + '_hidden]') 318 .val(1); 319 new_line.find('.cart_quantity_input') 320 .val(1); 321 $('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).val(old_id_address_delivery); 322 $('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery).val(id_address_delivery); 323 324 325 cleanSelectAddressDelivery(); 326 327 updateCartSummary(jsonData.summary); 328 if (window.ajaxCart !== undefined) 329 ajaxCart.updateCart(jsonData); 330 } 331 }); 332 } 333 return true; 334} 335 336function updateAddressId(id_product, id_product_attribute, old_id_address_delivery, id_address_delivery, line) 337{ 338 if (typeof(line) == 'undefined' || line.length == 0) 339 line = $('#cart_summary tr[id^=product_' + id_product + '_' + id_product_attribute + '_0_], #cart_summary tr[id^=product_' + id_product + '_' + id_product_attribute + '_nocustom_]'); 340 341 $('.product_customization_for_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).each(function(){ 342 $(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery)).removeClass('product_customization_for_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery + ' address_' + old_id_address_delivery).addClass('product_customization_for_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery + ' address_' + id_address_delivery); 343 $(this).find('input[name^=quantity_]').each(function(){ 344 if (typeof($(this).attr('name')) != 'undefined') 345 $(this).attr('name', $(this).attr('name').replace(/_\d+(_hidden|)$/, '_' + id_address_delivery)); 346 }); 347 $(this).find('a').each(function(){ 348 if (typeof($(this).attr('href')) != 'undefined') 349 $(this).attr('href', $(this).attr('href').replace(/id_address_delivery=\d+/, 'id_address_delivery=' + id_address_delivery)); 350 }); 351 }); 352 353 line.attr('id', line.attr('id').replace(/_\d+$/, '_' + id_address_delivery)).removeClass('address_' + old_id_address_delivery).addClass('address_' + id_address_delivery).find('span[id^=cart_quantity_custom_], span[id^=total_product_price_], input[name^=quantity_], .cart_quantity_down, .cart_quantity_up, .cart_quantity_delete').each(function(){ 354 355 if (typeof($(this).attr('name')) != 'undefined') 356 $(this).attr('name', $(this).attr('name').replace(/_\d+(_hidden|)$/, '_' + id_address_delivery)); 357 if (typeof($(this).attr('id')) != 'undefined') 358 $(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery)); 359 if (typeof($(this).attr('href')) != 'undefined') 360 $(this).attr('href', $(this).attr('href').replace(/id_address_delivery=\d+/, 'id_address_delivery=' + id_address_delivery)); 361 }); 362 363 line.find('#select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + old_id_address_delivery).attr('id', 'select_address_delivery_' + id_product + '_' + id_product_attribute + '_' + id_address_delivery); 364 365 if (window.ajaxCart !== undefined) 366 { 367 $('.cart_block_list dd, .cart_block_list dt').each(function(){ 368 if (typeof($(this).attr('id')) != 'undefined') 369 $(this).attr('id', $(this).attr('id').replace(/_\d+$/, '_' + id_address_delivery)); 370 }); 371 } 372} 373 374function updateQty(val, cart, el) 375{ 376 var prefix = ""; 377 378 if (typeof(cart) == 'undefined' || cart) 379 prefix = '#order-detail-content '; 380 else 381 prefix = '#fancybox-content '; 382 383 var id = $(el).attr('name'); 384 385 var exp = new RegExp("^[0-9]+$"); 386 387 if (exp.test(val) == true) 388 { 389 var hidden = $(prefix + 'input[name=' + id + '_hidden]').val(); 390 var input = $(prefix + 'input[name=' + id + ']').val(); 391 var QtyToUp = parseInt(input) - parseInt(hidden); 392 393 if (parseInt(QtyToUp) > 0) 394 upQuantity(id.replace('quantity_', ''), QtyToUp); 395 else if(parseInt(QtyToUp) < 0) 396 downQuantity(id.replace('quantity_', ''), QtyToUp); 397 } 398 else 399 $(prefix + 'input[name=' + id + ']').val($(prefix + 'input[name=' + id + '_hidden]').val()); 400 401 if (typeof(getCarrierListAndUpdate) !== 'undefined') 402 getCarrierListAndUpdate(); 403} 404 405function deleteProductFromSummary(id) 406{ 407 var customizationId = 0; 408 var productId = 0; 409 var productAttributeId = 0; 410 var id_address_delivery = 0; 411 var ids = 0; 412 ids = id.split('_'); 413 productId = parseInt(ids[0]); 414 if (typeof(ids[1]) !== 'undefined') 415 productAttributeId = parseInt(ids[1]); 416 if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom') 417 customizationId = parseInt(ids[2]); 418 if (typeof(ids[3]) !== 'undefined') 419 id_address_delivery = parseInt(ids[3]); 420 $.ajax({ 421 type: 'POST', 422 headers: { "cache-control": "no-cache" }, 423 url: baseUri + '?rand=' + new Date().getTime(), 424 async: true, 425 cache: false, 426 dataType: 'json', 427 data: 'controller=cart' 428 + '&ajax=true&delete=true&summary=true' 429 + '&id_product='+productId 430 + '&ipa='+productAttributeId 431 + '&id_address_delivery='+id_address_delivery 432 + ((customizationId !== 0) ? '&id_customization=' + customizationId : '')
433 + '&token=' + static_token 434 + '&allow_refresh=1', 435 success: function(jsonData) 436 { 437 if (jsonData.hasError) 438 { 439 var errors = ''; 440 for(var error in jsonData.errors) 441 //IE6 bug fix 442 if(error !== 'indexOf') 443 errors += $('<div />').html(jsonData.errors[error]).text() + "\n"; 444 if (!!$.prototype.fancybox) 445 $.fancybox.open([ 446 { 447 type: 'inline', 448 autoScale: true, 449 minHeight: 30, 450 content: '<p class="fancybox-error">' + errors + '</p>' 451 }], 452 { 453 padding: 0 454 }); 455 else 456 alert(errors); 457 } 458 else 459 { 460 if (jsonData.refresh) 461 { 462 location.reload(); 463 return; 464 } 465 if (parseInt(jsonData.summary.products.length) == 0) 466 { 467 if (typeof(orderProcess) == 'undefined' || orderProcess !== 'order-opc') 468 document.location.href = document.location.href; // redirection 469 else 470 { 471 $('#center_column').children().each(function() { 472 if ($(this).attr('id') !== 'emptyCartWarning' && $(this).attr('class') !== 'breadcrumb' && $(this).attr('id') !== 'cart_title') 473 { 474 $(this).fadeOut('slow', function () { 475 $(this).remove(); 476 }); 477 } 478 }); 479 $('#summary_products_label').remove(); 480 $('#emptyCartWarning').fadeIn('slow'); 481 } 482 } 483 else 484 { 485 $('#product_' + id).fadeOut('slow', function() { 486 $(this).remove(); 487 cleanSelectAddressDelivery(); 488 if (!customizationId) 489 refreshOddRow(); 490 }); 491 var exist = false; 492 for (i=0;i<jsonData.summary.products.length;i++) 493 { 494 if (jsonData.summary.products[i].id_product == productId 495 && jsonData.summary.products[i].id_product_attribute == productAttributeId 496 && jsonData.summary.products[i].id_address_delivery == id_address_delivery 497 && (parseInt(jsonData.summary.products[i].customizationQuantityTotal) > 0)) 498 exist = true; 499 } 500 // if all customization removed => delete product line 501 if (!exist && customizationId) 502 $('#product_' + productId + '_' + productAttributeId + '_0_' + id_address_delivery).fadeOut('slow', function() { 503 $(this).remove(); 504 var line = $('#product_' + productId + '_' + productAttributeId + '_nocustom_' + id_address_delivery); 505 if (line.length > 0) 506 { 507 line.find('input[name^=quantity_], .cart_quantity_down, .cart_quantity_up, .cart_quantity_delete').each(function(){ 508 if (typeof($(this).attr('name')) != 'undefined') 509 $(this).attr('name', $(this).attr('name').replace(/nocustom/, '0')); 510 if (typeof($(this).attr('id')) != 'undefined') 511 $(this).attr('id', $(this).attr('id').replace(/nocustom/, '0')); 512 }); 513 line.find('span[id^=total_product_price_]').each(function(){ 514 $(this).attr('id', $(this).attr('id').replace(/_nocustom/, '')); 515 }); 516 line.attr('id', line.attr('id').replace(/nocustom/, '0')); 517 } 518 refreshOddRow(); 519 }); 520 } 521 updateCartSummary(jsonData.summary); 522 if (window.ajaxCart != undefined) 523 ajaxCart.updateCart(jsonData); 524 updateCustomizedDatas(jsonData.customizedDatas); 525 updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); 526 updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); 527 if (typeof(getCarrierListAndUpdate) !== 'undefined' && jsonData.summary.products.length > 0) 528 getCarrierListAndUpdate(); 529 if (typeof(updatePaymentMethodsDisplay) !== 'undefined') 530 updatePaymentMethodsDisplay(); 531 } 532 }, 533 error: function(XMLHttpRequest, textStatus, errorThrown) { 534 if (textStatus !== 'abort') 535 { 536 var error = "TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus; 537 if (!!$.prototype.fancybox) 538 $.fancybox.open([ 539 { 540 type: 'inline', 541 autoScale: true, 542 minHeight: 30, 543 content: '<p class="fancybox-error">' + error + '</p>' 544 }], 545 { 546 padding: 0 547 }); 548 else 549 alert(error); 550 } 551 } 552 }); 553} 554 555function refreshOddRow() 556{ 557 var odd_class = 'odd'; 558 var even_class = 'even'; 559 $.each($('.cart_item'), function(i, it) 560 { 561 if (i == 0) // First item 562 { 563 if ($(this).hasClass('even')) 564 { 565 odd_class = 'even'; 566 even_class = 'odd'; 567 } 568 $(this).addClass('first_item'); 569 } 570 if(i % 2) 571 $(this).removeClass(odd_class).addClass(even_class); 572 else 573 $(this).removeClass(even_class).addClass(odd_class); 574 }); 575 $('.cart_item:last-child, .customization:last-child').addClass('last_item'); 576} 577 578function upQuantity(id, qty) 579{ 580 if (typeof(qty) == 'undefined' || !qty) 581 qty = 1; 582 var customizationId = 0; 583 var productId = 0; 584 var productAttributeId = 0; 585 var id_address_delivery = 0; 586 var ids = 0; 587 ids = id.split('_'); 588 productId = parseInt(ids[0]); 589 if (typeof(ids[1]) !== 'undefined') 590 productAttributeId = parseInt(ids[1]); 591 if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom') 592 customizationId = parseInt(ids[2]); 593 if (typeof(ids[3]) !== 'undefined') 594 id_address_delivery = parseInt(ids[3]); 595 596 $.ajax({ 597 type: 'POST', 598 headers: { "cache-control": "no-cache" }, 599 url: baseUri + '?rand=' + new Date().getTime(), 600 async: true, 601 cache: false, 602 dataType: 'json', 603 data: 'controller=cart' 604 + '&ajax=true' 605 + '&add=true' 606 + '&getproductprice=true' 607 + '&summary=true' 608 + '&id_product=' + productId 609 + '&ipa=' + productAttributeId 610 + '&id_address_delivery=' + id_address_delivery 611 + ((customizationId !== 0) ? '&id_customization=' + customizationId : '') 612 + '&qty=' + qty
613 + '&token=' + static_token 614 + '&allow_refresh=1', 615 success: function(jsonData) 616 { 617 if (jsonData.hasError) 618 { 619 var errors = ''; 620 for(var error in jsonData.errors) 621 //IE6 bug fix 622 if(error !== 'indexOf') 623 errors += $('<div />').html(jsonData.errors[error]).text() + "\n"; 624 if (!!$.prototype.fancybox) 625 $.fancybox.open([ 626 { 627 type: 'inline', 628 autoScale: true, 629 minHeight: 30, 630 content: '<p class="fancybox-error">' + errors + '</p>' 631 }], 632 { 633 padding: 0 634 }); 635 else 636 alert(errors); 637 $('input[name=quantity_'+ id +']').val($('input[name=quantity_'+ id +'_hidden]').val()); 638 } 639 else 640 { 641 if (jsonData.refresh) 642 window.location.href = window.location.href; 643 updateCartSummary(jsonData.summary); 644 if (window.ajaxCart != undefined) 645 ajaxCart.updateCart(jsonData); 646 if (customizationId !== 0) 647 updateCustomizedDatas(jsonData.customizedDatas); 648 updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); 649 updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); 650 if (typeof(getCarrierListAndUpdate) !== 'undefined') 651 getCarrierListAndUpdate(); 652 if (typeof(updatePaymentMethodsDisplay) !== 'undefined') 653 updatePaymentMethodsDisplay(); 654 } 655 }, 656 error: function(XMLHttpRequest, textStatus, errorThrown) { 657 if (textStatus !== 'abort') 658 { 659 error = "TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus; 660 if (!!$.prototype.fancybox) 661 $.fancybox.open([ 662 { 663 type: 'inline', 664 autoScale: true, 665 minHeight: 30, 666 content: '<p class="fancybox-error">' + error + '</p>' 667 }], 668 { 669 padding: 0 670 }); 671 else 672 alert(error); 673 } 674 } 675 }); 676} 677 678function downQuantity(id, qty) 679{ 680 var val = $('input[name=quantity_' + id + ']').val(); 681 var newVal = val; 682 if(typeof(qty) == 'undefined' || !qty) 683 { 684 qty = 1; 685 newVal = val - 1; 686 } 687 else if (qty < 0) 688 qty = -qty; 689 690 var customizationId = 0; 691 var productId = 0; 692 var productAttributeId = 0; 693 var id_address_delivery = 0; 694 var ids = 0; 695 696 ids = id.split('_'); 697 productId = parseInt(ids[0]); 698 if (typeof(ids[1]) !== 'undefined') 699 productAttributeId = parseInt(ids[1]); 700 if (typeof(ids[2]) !== 'undefined' && ids[2] !== 'nocustom') 701 customizationId = parseInt(ids[2]); 702 if (typeof(ids[3]) !== 'undefined') 703 id_address_delivery = parseInt(ids[3]); 704 705 if (newVal > 0 || $('#product_' + id + '_gift').length) 706 { 707 $.ajax({ 708 type: 'POST', 709 headers: { "cache-control": "no-cache" }, 710 url: baseUri + '?rand=' + new Date().getTime(), 711 async: true, 712 cache: false, 713 dataType: 'json', 714 data: 'controller=cart' 715 + '&ajax=true' 716 + '&add=true' 717 + '&getproductprice=true' 718 + '&summary=true' 719 + '&id_product='+productId 720 + '&ipa='+productAttributeId 721 + '&id_address_delivery='+id_address_delivery 722 + '&op=down' 723 + ((customizationId !== 0) ? '&id_customization='+customizationId : '') 724 + '&qty='+qty 725 + '&token='+static_token 726 + '&allow_refresh=1', 727 success: function(jsonData) 728 { 729 if (jsonData.hasError) 730 { 731 var errors = ''; 732 for(var error in jsonData.errors) 733 //IE6 bug fix 734 if(error !== 'indexOf') 735 errors += $('<div />').html(jsonData.errors[error]).text() + "\n"; 736 if (!!$.prototype.fancybox) 737 $.fancybox.open([ 738 { 739 type: 'inline', 740 autoScale: true, 741 minHeight: 30, 742 content: '<p class="fancybox-error">' + errors + '</p>' 743 }], 744 { 745 padding: 0 746 }); 747 else 748 alert(errors); 749 $('input[name=quantity_' + id + ']').val($('input[name=quantity_' + id + '_hidden]').val()); 750 } 751 else 752 { 753 if (jsonData.refresh) 754 window.location.href = window.location.href; 755 updateCartSummary(jsonData.summary); 756 757 if (window.ajaxCart !== undefined) 758 ajaxCart.updateCart(jsonData); 759 if (customizationId !== 0) 760 updateCustomizedDatas(jsonData.customizedDatas); 761 updateHookShoppingCart(jsonData.HOOK_SHOPPING_CART); 762 updateHookShoppingCartExtra(jsonData.HOOK_SHOPPING_CART_EXTRA); 763 764 if (newVal == 0) 765 $('#product_' + id).hide(); 766 767 if (typeof(getCarrierListAndUpdate) !== 'undefined') 768 getCarrierListAndUpdate(); 769 if (typeof(updatePaymentMethodsDisplay) !== 'undefined') 770 updatePaymentMethodsDisplay(); 771 } 772 }, 773 error: function(XMLHttpRequest, textStatus, errorThrown) { 774 if (textStatus !== 'abort') 775 alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 776 } 777 }); 778 779 } 780 else 781 { 782 deleteProductFromSummary(id); 783 } 784} 785 786function updateCartSummary(json) 787{ 788 var i; 789 var nbrProducts = 0; 790 var product_list = new Array(); 791 792 if (typeof json == 'undefined') 793 return; 794 795 $('div.alert-danger').fadeOut(); 796 797 for (i=0;i<json.products.length;i++) 798 product_list[json.products[i].id_product + '_' + json.products[i].id_product_attribute + '_' + json.products[i].id_address_delivery] = json.products[i]; 799 800 if (!$('.multishipping-cart:visible').length) 801 { 802 for (i=0;i<json.gift_products.length;i++) 803 if (typeof(product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery]) !== 'undefined') 804 product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery].quantity -= json.gift_products[i].cart_quantity; 805 } 806 else 807 for (i=0;i<json.gift_products.length;i++) 808 if (typeof(product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery]) == 'undefined') 809 product_list[json.gift_products[i].id_product + '_' + json.gift_products[i].id_product_attribute + '_' + json.gift_products[i].id_address_delivery] = json.gift_products[i]; 810 811 for (i in product_list) 812 { 813 // if reduction, we need to show it in the cart by showing the initial price above the current one 814 var reduction = product_list[i].reduction_applies; 815 var reduction_type = product_list[i].reduction_type; 816 var reduction_symbol = ''; 817 var initial_price_text = ''; 818 var initial_price = ''; 819 820 if (typeof(product_list[i].price_without_quantity_discount) !== 'undefined') 821 initial_price = formatCurrency(product_list[i].price_without_quantity_discount, currencyFormat, currencySign, currencyBlank); 822 823 var current_price = ''; 824 var product_total = ''; 825 var product_customization_total = ''; 826 827 if (priceDisplayMethod !== 0) 828 { 829 current_price = formatCurrency(product_list[i].price, currencyFormat, currencySign, currencyBlank); 830 product_total = product_list[i].total; 831 product_customization_total = product_list[i].total_customization; 832 } 833 else 834 { 835 current_price = formatCurrency(product_list[i].price_wt, currencyFormat, currencySign, currencyBlank); 836 product_total = product_list[i].total_wt; 837 product_customization_total = product_list[i].total_customization_wt; 838 } 839 840 var current_price_class ='price'; 841 var price_reduction = ''; 842 if (reduction && typeof(initial_price) !== 'undefined') 843 { 844 if (reduction_type == 'amount') 845 price_reduction = product_list[i].reduction_formatted; 846 else 847 {
848 var display_price = 0; 849 if (priceDisplayMethod !== 0) 850 display_price = product_list[i].price; 851 else 852 display_price = product_list[i].price_wt; 853 854 price_reduction = ps_round((product_list[i].price_without_quantity_discount - display_price)/product_list[i].price_without_quantity_discount * -100); 855 reduction_symbol = '%'; 856 } 857 858 if (initial_price !== '' && product_list[i].price_without_quantity_discount > product_list[i].price) 859 { 860 initial_price_text = '<span class="price-percent-reduction small"> '+price_reduction+reduction_symbol+' </span><span class="old-price">' + initial_price + '</span>'; 861 current_price_class += ' special-price'; 862 } 863 } 864 865 var key_for_blockcart = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + product_list[i].id_address_delivery; 866 var key_for_blockcart_nocustom = product_list[i].id_product + '_' + product_list[i].id_product_attribute + '_' + ((product_list[i].id_customization && product_list[i].quantity_without_customization != product_list[i].quantity)? 'nocustom' : '0') + '_' + product_list[i].id_address_delivery; 867 868 $('#product_price_' + key_for_blockcart).html('<span class="' + current_price_class + '">' + current_price + '</span>' + initial_price_text); 869 if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0) 870 $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_customization_total, currencyFormat, currencySign, currencyBlank)); 871 else 872 $('#total_product_price_' + key_for_blockcart).html(formatCurrency(product_total, currencyFormat, currencySign, currencyBlank)); 873 if (product_list[i].quantity_without_customization != product_list[i].quantity) 874 $('#total_product_price_' + key_for_blockcart_nocustom).html(formatCurrency(product_total, currencyFormat, currencySign, currencyBlank)); 875 876 $('input[name=quantity_' + key_for_blockcart_nocustom + ']').val(product_list[i].id_customization? product_list[i].quantity_without_customization : product_list[i].cart_quantity); 877 $('input[name=quantity_' + key_for_blockcart_nocustom + '_hidden]').val(product_list[i].id_customization? product_list[i].quantity_without_customization : product_list[i].cart_quantity); 878 if (typeof(product_list[i].customizationQuantityTotal) !== 'undefined' && product_list[i].customizationQuantityTotal > 0) 879 $('#cart_quantity_custom_' + key_for_blockcart).html(product_list[i].customizationQuantityTotal); 880 nbrProducts += parseInt(product_list[i].quantity); 881 } 882 883 // Update discounts 884 var discount_count = 0; 885 for(var e in json.discounts) 886 { 887 discount_count++; 888 break; 889 } 890 891 if (!discount_count) 892 { 893 $('.cart_discount').each(function(){$(this).remove();}); 894 $('.cart_total_voucher').remove(); 895 } 896 else 897 { 898 if ($('.cart_discount').length == 0) 899 { 900 location.reload(); 901 return; 902 } 903 904 if (priceDisplayMethod !== 0) 905 $('#total_discount').html('-' + formatCurrency(json.total_discounts_tax_exc, currencyFormat, currencySign, currencyBlank)); 906 else 907 $('#total_discount').html('-' + formatCurrency(json.total_discounts, currencyFormat, currencySign, currencyBlank)); 908 909 $('.cart_discount').each(function(){ 910 var idElmt = $(this).attr('id').replace('cart_discount_',''); 911 var toDelete = true; 912 913 for (var i in json.discounts) 914 if (json.discounts[i].id_discount == idElmt) 915 { 916 if (json.discounts[i].value_real !== '!') 917 { 918 if (priceDisplayMethod !== 0) 919 $('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_tax_exc * -1, currencyFormat, currencySign, currencyBlank)); 920 else 921 $('#cart_discount_' + idElmt + ' td.cart_discount_price span.price-discount').html(formatCurrency(json.discounts[i].value_real * -1, currencyFormat, currencySign, currencyBlank)); 922 } 923 toDelete = false; 924 } 925 if (toDelete) 926 $('#cart_discount_' + idElmt + ', #cart_total_voucher').fadeTo('fast', 0, function(){ $(this).remove(); }); 927 }); 928 } 929 930 // Block cart 931 if (typeof(orderProcess) !== 'undefined' && orderProcess == 'order-opc') 932 $('.ajax_cart_shipping_cost').parent().find('.unvisible').show(); 933 if (json.total_shipping > 0) 934 { 935 if (priceDisplayMethod !== 0) 936 { 937 $('.cart_block_shipping_cost').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank)); 938 $('.cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping_tax_exc, currencyFormat, currencySign, currencyBlank)); 939 $('.cart_block_total').html(formatCurrency(json.total_price_without_tax, currencyFormat, currencySign, currencyBlank)); 940 } 941 else 942 { 943 $('.cart_block_shipping_cost').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank)); 944 $('.cart_block_wrapping_cost').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank)); 945 $('.cart_block_total').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); 946 } 947 } 948 else 949 { 950 if (parseFloat(json.total_shipping) > 0) 951 $('.ajax_cart_shipping_cost').text(jsonData.shippingCost); 952 else if (json.carrier.id == null && typeof(toBeDetermined) !== 'undefined' && !json.free_ship) 953 $('.ajax_cart_shipping_cost').html(toBeDetermined); 954 else if (typeof(freeShippingTranslation) != 'undefined') 955 $('.ajax_cart_shipping_cost').html(freeShippingTranslation); 956 } 957 958 $('.cart_block_tax_cost').html(formatCurrency(json.total_tax, currencyFormat, currencySign, currencyBlank)); 959 $('.ajax_cart_quantity').html(nbrProducts); 960 961 // Cart summary 962 $('#summary_products_quantity').html(nbrProducts + ' ' + (nbrProducts > 1 ? txtProducts : txtProduct)); 963 if (priceDisplayMethod !== 0) 964 $('#total_product').html(formatCurrency(json.total_products, currencyFormat, currencySign, currencyBlank)); 965 else 966 $('#total_product').html(formatCurrency(json.total_products_wt, currencyFormat, currencySign, currencyBlank)); 967 $('#total_price').html(formatCurrency(json.total_price, currencyFormat, currencySign, currencyBlank)); 968 $('#total_price_without_tax').html(formatCurrency(json.total_price_without_tax, currencyFormat, currencySign, currencyBlank)); 969 $('#total_tax').html(formatCurrency(json.total_tax, currencyFormat, currencySign, currencyBlank)); 970 971 $('.cart_total_delivery').show(); 972 if (json.total_shipping > 0) 973 { 974 if (priceDisplayMethod !== 0) 975 $('#total_shipping').html(formatCurrency(json.total_shipping_tax_exc, currencyFormat, currencySign, currencyBlank)); 976 else 977 $('#total_shipping').html(formatCurrency(json.total_shipping, currencyFormat, currencySign, currencyBlank)); 978 } 979 else 980 { 981 if (json.carrier.id != null || json.free_ship) 982 { 983 $('#total_shipping').html(freeShippingTranslation); 984 if (json.is_virtual_cart) 985 $('.cart_total_delivery').hide(); 986 } 987 988 } 989 990 if (json.total_wrapping > 0) 991 { 992 $('#total_wrapping').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank)); 993 $('#total_wrapping').parent().show(); 994 } 995 else 996 { 997 $('#total_wrapping').html(formatCurrency(json.total_wrapping, currencyFormat, currencySign, currencyBlank)); 998 $('#total_wrapping').parent().hide(); 999 } 1000} 1001 1002function updateCustomizedDatas(json) 1003{ 1004 for(var i in json) 1005 for(var j in json[i]) 1006 for(var k in json[i][j])
1007 for(var l in json[i][j][k]) 1008 { 1009 var quantity = json[i][j][k][l]['quantity']; 1010 $('input[name=quantity_' + i + '_' + j + '_' + l + '_' + k + '_hidden]').val(quantity); 1011 $('input[name=quantity_' + i + '_' + j + '_' + l + '_' + k + ']').val(quantity); 1012 } 1013} 1014 1015function updateHookShoppingCart(html) 1016{ 1017 $('#HOOK_SHOPPING_CART').html(html); 1018 if (typeof initCrossSellingbxSlider !== 'undefined') 1019 initCrossSellingbxSlider(); 1020} 1021 1022function updateHookShoppingCartExtra(html) 1023{ 1024 $('#HOOK_SHOPPING_CART_EXTRA').html(html); 1025} 1026function refreshDeliveryOptions() 1027{ 1028 $.each($('.delivery_option_radio'), function() { 1029 if ($(this).prop('checked')) 1030 { 1031 if ($(this).parent().find('.delivery_option_carrier.not-displayable').length == 0) 1032 $(this).parent().find('.delivery_option_carrier').show(); 1033 var carrier_id_list = $(this).val().split(','); 1034 carrier_id_list.pop(); 1035 var it = this; 1036 $(carrier_id_list).each(function() { 1037 $(it).closest('.delivery_options').find('input[value="' + this.toString() + '"]').change(); 1038 }); 1039 } 1040 else 1041 $(this).parent().find('.delivery_option_carrier').hide(); 1042 }); 1043} 1044 1045function updateExtraCarrier(id_delivery_option, id_address) 1046{ 1047 var url = ""; 1048 1049 if(typeof(orderOpcUrl) !== 'undefined') 1050 url = orderOpcUrl; 1051 else 1052 url = orderUrl; 1053 1054 $.ajax({ 1055 type: 'POST', 1056 headers: { "cache-control": "no-cache" }, 1057 url: url + '?rand=' + new Date().getTime(), 1058 async: true, 1059 cache: false, 1060 dataType : "json", 1061 data: 'ajax=true' 1062 + '&method=updateExtraCarrier' 1063 + '&id_address='+id_address 1064 + '&id_delivery_option='+id_delivery_option 1065 + '&token='+static_token 1066 + '&allow_refresh=1', 1067 success: function(jsonData) 1068 { 1069 $('#HOOK_EXTRACARRIER_' + id_address).html(jsonData['content']); 1070 } 1071 }); 1072}
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.