1/* 2* 2007-2011 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-2011 PrestaShop SA 22* @version Release: $Revision: 7009 $ 23* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) 24* International Registered Trademark & Property of PrestaShop SA 25*/ 26 27 28//JS Object : update the cart by ajax actions 29var ajaxCart = { 30 31 hideLoaders : function(addedFromProductPage) { 32 if (addedFromProductPage) { 33 $('#add_to_cart').removeClass('loading'); 34 $('#add_to_cart input').removeAttr('disabled', 'disabled'); 35 } 36 else { 37 $('.ajax_add_to_cart_button').removeAttr('disabled'); 38 $('.ajax_add_to_cart_button').closest('div').removeClass('loading'); 39 } 40 }, 41 42 showLoaders : function(callerElement, addedFromProductPage) { 43 if (addedFromProductPage) { 44 $('#add_to_cart').addClass('loading'); 45 $('#add_to_cart input').attr('disabled', 'disabled'); 46 $('.filled').removeClass('filled'); 47 } 48 else { 49 $(callerElement).closest('div').addClass('loading'); 50 $(callerElement).attr('disabled', 'disabled'); 51 } 52 }, 53 54 ensureAddToCartModal: function() { 55 if ($('#add-to-cart-modal').length) { 56 return $('#add-to-cart-modal'); 57 } 58 59 var $modal = $('<div>', {id: 'add-to-cart-modal', class: 'add-to-cart-modal'}); 60 var $window = $('<div>', {class: 'add-to-cart-modal-window'}); 61 var $close = $('<button>', {type: 'button', class: 'add-to-cart-modal-close close-add-to-cart', 'aria-label': 'Close'}); 62 var $content = $('<div>', {class: 'add-to-cart-modal-content'}); 63 64 $window.append($close).append($content); 65 $modal.append($window); 66 $('body').append($modal); 67 68 return $modal; 69 }, 70 71 openAddToCartModal: function() { 72 var $modal = ajaxCart.ensureAddToCartModal(); 73 var $content = $modal.find('.add-to-cart-modal-content'); 74 75 clearTimeout($modal.data('close-timeout')); 76 $('#added-product-popup-content').remove(); 77 $content.html('<div class="loading prepare-fancy"></div><div id="algoliaCartRecommended" style="display: none;"></div>'); 78 $modal.addClass('is-visible'); 79 $('body').addClass('no-scroll'); 80 setTimeout(function() { 81 $modal.addClass('animate'); 82 }, 10); 83 }, 84 85 closeAddToCartModal: function(forceImmediate) { 86 var $modal = $('#add-to-cart-modal'); 87 88 if (!$modal.length) { 89 $('body').removeClass('no-scroll'); 90 return; 91 } 92 93 $modal.removeClass('animate'); 94 $('body').removeClass('no-scroll'); 95 96 clearTimeout($modal.data('close-timeout')); 97 var completeClose = function() { 98 $modal.removeClass('is-visible'); 99 $modal.find('.add-to-cart-modal-content').empty(); 100 $('#added-product-popup-content').remove(); 101 }; 102 103 if (forceImmediate) { 104 completeClose(); 105 return; 106 } 107 108 $modal.data('close-timeout', setTimeout(completeClose, 300)); 109 }, 110 111 //override every button in the page in relation to the cart 112 overrideButtonsInThePage : function(v){ 113 114 if (typeof blockUserInfo !== 'undefined') { 115 blockUserInfo.init() 116 } 117 118 // PDP: Product Added to Cart / PDP: Product Added to Cart after Search 119 var algoliaPDPEvent = function () { 120 if (typeof algolia_query_id !== 'undefined') { 121 var type = 'product'; 122 if (typeof algolia_query_id_from_category !== 'undefined') { 123 type = 'product_from_category'; 124 } 125 if (typeof algolia_autocomplete_search !== 'undefined') { 126 type = 'autocomplete'; 127 } 128 var data = { 129 'query_id': algolia_query_id, 130 'type': type, 131 } 132 algolia.saveEventData(data); 133 } 134 else if (typeof algolia !== 'undefined') { 135 algolia.saveEventData({'type': 'product_simple'}); 136 } 137 } 138 139 //for every 'add' buttons... 140 $('.ajax_add_to_cart_button').unbind('click.ac').on('click.ac', function(){ 141 var idProduct = $(this).data("id_product"); 142 var productQuantity = 1; 143 if ($(this).data('tier-error')) { 144 return; 145 } 146 147 var idCombination = null; 148 if ($(this).closest('.js-add-to-cart-wrap').length) { 149 if ($(this).closest('.js-add-to-cart-wrap').find('.ipa_id').length) { 150 idCombination = $(this).closest('.js-add-to-cart-wrap').find('.ipa_id').first().val() 151 } 152 else { 153 if ($('#ipa_id_for_' + idProduct).length) { 154 idCombination = $('#ipa_id_for_' + idProduct).val(); 155 } 156 else { 157 idCombination = null; 158 } 159 } 160 } 161 162 if ($('body#product').length && idProduct == $('#product_page_product_id').val()) { // sticky headers button click 163 algoliaPDPEvent(); 164 } 165 // PLP: Product Added to Cart 166 else { 167 var $product = $(this).closest('.ajax_block_product'); 168 let type = 'listing' 169 if (typeof algolia_category_page !== 'undefined') { 170 type = 'category_listing'; 171 } 172 if ($product.length && $product.data('algolia_item_position')) { 173 var data = { 174 'query_id': $('#product_list').data('algolia_query_id'), 175 'position': $product.data('algolia_item_position'), 176 'type': type, 177 }; 178 algolia.saveEventData(data); 179 } 180 } 181 182 var categoryProduct = $(this).data("ga-category"); 183 var withPopup = true; 184 if ($(this).hasClass('recommended-product-add-to-cart')) { 185 withPopup = false;
186 $(this).addClass('add-to-cart-green'); 187 $(this).parents('.add-to-cart-wrap').addClass('add-to-cart-checked'); 188 189 ajaxCart.AddedProductPopup.showAddedRecommendedProductTitle($(this).parents('.recommended-product')); 190 } 191 if ($(this).closest('.recommended-product').length) { 192 productQuantity = $(this).closest('.recommended-product').find('.cart_quantity_value').val(); 193 } 194 if ($(this).attr('disabled') != 'disabled') { 195 ajaxCart.add(idProduct, idCombination, false, this, productQuantity, null, categoryProduct, withPopup); 196 } 197 return false; 198 }); 199 200 //for product page 'add' button... 201 $('body#product #add_to_cart input').unbind('click.ac').on('click.ac', function() { 202 if ($(this).data('tier-error')) { 203 return; 204 } 205 algoliaPDPEvent(); 206 207 ajaxCart.add( $('#product_page_product_id').val(), $('#idCombination').val(), true, null, $('#quantity_wanted').val(), null); 208 return false; 209 }); 210 211 $('#header_user .ajax_cart_block_remove_link, #cart_block_list .ajax_cart_block_remove_link').unbind('click').click(function (e) { 212 e.preventDefault(); 213 var customizationId = $(this).data('id-customization'); 214 var productId = $(this).data('product-id'); 215 var productAttributeId = $(this).data('combination-id'); 216 var pay_with_points = $(this).data('pay_with_points'); 217 var idGift = $(this).data('gift-id'); 218 ajaxCart.remove(productId, productAttributeId, customizationId, idGift, pay_with_points); 219 }); 220 221 // Refresh order page if we are there 222 $('.close-add-to-cart').off('click.acClose').on('click.acClose', function (e) { 223 e.preventDefault(); 224 ajaxCart.closeAddToCartModal(); 225 }); 226 $('#add-to-cart-modal').off('click.acBackdrop').on('click.acBackdrop', function (e) { 227 if (e.target === this) { 228 ajaxCart.closeAddToCartModal(); 229 } 230 }); 231 $('.add-to-cart-popup-added-close').off('click.acClose').on('click.acClose', function (e) { 232 e.preventDefault(); 233 ajaxCart.AddedProductPopup.closeAddedRecommendedProductTitle(); 234 }); 235 }, 236 237 // cart to fix display when using back and previous browsers buttons 238 refresh : function(get_products_splio_data){ 239 var extraParamsStr = ''; 240 if (!$('body').hasClass('orderPage')) { 241 extraParamsStr += '&from_global_script=1'; 242 } 243 //send the ajax request to the server 244 $.ajax({ 245 type: 'GET', 246 url: baseDir + 'cart.php', 247 async: true, 248 cache: false, 249 dataType : "json", 250 data: 'ajax=true'+ extraParamsStr +'&summary&token=' + static_token + (typeof get_products_splio_data != 'undefined' && get_products_splio_data ? '&get_products_splio_data=1' : ''), 251 success: function(jsonData) 252 { 253 ajaxCart.updateCart(jsonData); 254 $('.shopping_cart .dropdown-block').removeClass('load'); 255 }, 256 error: function(XMLHttpRequest, textStatus, errorThrown) { 257 console.log("TECHNICAL ERROR: unable to refresh the cart.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus); 258 } 259 }); 260 }, 261 262 // add a product in the cart via ajax 263 add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, wishlist, categoryProduct, addWithShow = true) { 264 var self = this; 265 if (addedFromProductPage && !checkCustomizations()) { 266 alert(fieldRequired); 267 return ; 268 } 269 270 var isCheckoutPage = $('body').hasClass('orderPage') || $('body').hasClass('order-opcPage'); // Refresh order page if we are there 271 272 if (typeof algoliaCartProducts !== 'undefined' && !isCheckoutPage) { 273 var cartProducts = JSON.parse(window.algoliaCartProducts); 274 cartProducts.push(idProduct.toString()); 275 window.algoliaCartProducts = JSON.stringify(cartProducts); 276 document.dispatchEvent(new CustomEvent('onCartUpdate')); 277 } 278 279 emptyCustomizations(); 280 281 //disabled the button when adding to do not double add if user double click 282 ajaxCart.showLoaders(callerElement, addedFromProductPage); 283 284 //hide chatbot btn 285 const host = document.querySelector('[data-support-chat-widget-v1-root]'); 286 if (host) { 287 host.style.display = 'none'; 288 } 289 290 var qty = (quantity && quantity != null) ? quantity : '1'; 291 292 if (!$('#add-to-cart-modal').hasClass('is-visible') && !$('body').hasClass('orderPage')) { 293 ajaxCart.openAddToCartModal(); 294 document.dispatchEvent(new CustomEvent('onInitProductPopup', { 295 detail: { 296 idProduct: JSON.stringify([idProduct.toString()]) 297 } 298 })); 299 300 //recommend server logic - trigger along with start popup show in order to execute only once and preload 301 if ($('#recommended_server_tmp').length) { 302 $.ajax({ 303 type: 'POST', 304 url: baseDir + 'modules/recommendserver/ajax.php?page_name=add_to_cart&id_product=' + idProduct + ((parseInt(idCombination) && idCombination != null) ? '&id_product_attribute=' + parseInt(idCombination) : ''), 305 data: [], 306 async: true, 307 success: function (data) { 308 let parsedJson = JSON.parse(data) 309 $('#recommended_server_tmp').html('<div class="recomendServerRecommended">'+parsedJson.content+'</div>'); 310 $('#recommended_server_tmp .recommended-product').each(function(){ 311 var checkbox = $(this).find(':radio.star'); 312 if (jQuery(checkbox).rating) { 313 jQuery(checkbox).rating( 314 { 315 readOnly : true, 316 starGif : "/modules/gsnippetsreviews/img/hook/star.gif", 317 half: !!$(checkbox).data('half'), 318 starWidth: $(checkbox).data('starWidth') 319 }); 320 } 321 }); 322 ajaxCart.overrideButtonsInThePage(); 323 324 let recommendedList; 325 if ($('#recommended_server_tmp .recommended-product').length) { 326 recommendedList = $('#recommended_server_tmp .recommended-product'); 327 } 328 329 // if popup was uploaded earlier 330 if ($('#recommended-products-container').length) { 331 $($('#recommended_server_tmp .recomendServerRecommended').detach()).appendTo('#recommended-products-container'); 332 } 333 334 let recommendedArr = Array(); 335 let query_id; 336 if (recommendedList) { 337 recommendedList.each(function(i, item) { 338 recommendedArr.push($(item).attr('data-id_product')); 339 if (!query_id) { 340 query_id = $(item).attr('data-query_id') 341 } 342 }) 343 344 $.ajax({ 345 type: 'POST', 346 url: baseDir + 'modules/recommendedstats/ajax.php', 347 data: {viewed_cart: recommendedArr, query_id: query_id}, 348 async: true, 349 success: function (data) { 350 351 } 352 }); 353 } 354 } 355 }); 356 } 357 358 }
359 //send the ajax request to the server 360 $.ajax({ 361 type: 'POST', 362 url: baseDir + 'cart.php', 363 async: true, 364 cache: false, 365 dataType : "json", 366 data: 'add=1&ajax=true&summary&from_global_script=1&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): '') + '¤t_page=' + $('body').attr('id'), 367 success: function(jsonData) 368 { 369 if ((jsonData.hasError && jsonData.productsLimit) || typeof jsonData.seedsLimit !== 'undefined') { 370 ajaxCart.hideLoaders(addedFromProductPage); 371 $('#add-to-cart-popup').find('#added-product-container, .quantity-wrap').removeClass('loading'); 372 $('.shopping_cart .dropdown-block').removeClass('load'); 373 ajaxCart.closeAddToCartModal(true); 374 return; 375 } 376 if (!jsonData.errors) { 377 if (typeof googleAnalyticsAddRemoveAction === 'function') { 378 googleAnalyticsAddRemoveAction(idProduct, idCombination, qty, false, categoryProduct, callerElement); 379 } 380 } 381 if (!jsonData.hasError && !$('body').hasClass('orderPage') && addWithShow) { 382 ajaxCart.AddedProductPopup.show(idProduct, idCombination, addedFromProductPage, quantity, callerElement); 383 } 384 if ($('.top-block .cart_quantity_value').val() > 1) { 385 $('.top-block .quantity-wrap .cart_quantity_down').prop('disabled' , false); 386 } 387 388 var reloadPage = $('body').hasClass('orderPage') || (typeof cartIsEmpty !== 'undefined' && cartIsEmpty); 389 if (reloadPage) { 390 if (!$(callerElement).attr('data-recommended-product')) { 391 window.location.reload(); 392 } else { 393 self.trackRecommendedAddToCart(idProduct, idCombination, quantity, callerElement, reloadPage); 394 } 395 } else { 396 // add appliance to whishlist module 397 if (wishlist && !jsonData.errors) { 398 WishlistAddProductCart(wishlist[0], idProduct, idCombination, wishlist[1]); 399 } 400 401 ajaxCart.updateCart(jsonData, addedFromProductPage); 402 403 if (!jsonData.errors) { 404 //reactive the button when adding has finished 405 if (addedFromProductPage) { 406 $('#add_to_cart').removeClass('loading'); 407 $('#add_to_cart input').removeAttr('disabled', 'disabled'); 408 } 409 else { 410 $('.ajax_add_to_cart_button').removeAttr('disabled'); 411 $('.ajax_add_to_cart_button').closest('div').removeClass('loading'); 412 } 413 } 414 else { 415 ajaxCart.closeAddToCartModal(true); 416 } 417 418 if ($('.algolia_ajax_add_to_cart_button').length) { 419 $('.algolia_ajax_add_to_cart_button').removeAttr('disabled'); 420 $('.algolia_ajax_add_to_cart_button').closest('div').removeClass('loading'); 421 } 422 423 self.removeFromRecommended(idProduct); 424 425 if ($('body').hasClass('order-opcPage') && ($(callerElement).attr('data-recommended-product') || $(callerElement).hasClass('algolia_ajax_add_to_cart_button'))) { 426 $.ajax({ 427 type: 'GET', 428 url: baseDir + 'cart.php', 429 async: true, 430 cache: false, 431 dataType: 'json', 432 data: 'ajax=true&summary&token=' + static_token, 433 success: function (jsonData) { 434 updateCartErrors(jsonData) 435 if (typeof opcPage !== 'undefined') { 436 opcPage.updateOpcCartPage(jsonData); 437 } 438 } 439 }); 440 } 441 442 self.trackRecommendedAddToCart(idProduct, idCombination, quantity, callerElement, reloadPage); 443 } 444 }, 445 error: function(XMLHttpRequest, textStatus) 446 { 447 console.log('Unable to add the product.\n\nDetails:\nError thrown: ' + XMLHttpRequest + '\n' + 'Text status: ' + textStatus); 448 ajaxCart.hideLoaders(addedFromProductPage); 449 } 450 }); 451 }, 452 453 //remove a product from the cart via ajax 454 remove : function(idProduct, idCombination, customizationId, idGift, pay_with_points){ 455 456 var self = this; 457 var qty = parseInt($('#cart_quantity_down_'+idProduct+'_'+idCombination).closest('.quantity').find('.cart_quantity').text()); 458 459 $('.shopping_cart .dropdown-block').addClass('load'); 460 var bodyId = $('body').attr('id'); 461 var extraParamsStr = (bodyId == 'order' || bodyId == 'order-opc') ? '' : '&from_global_script=1';
462 //send the ajax request to the server 463 $.ajax({ 464 type: 'POST', 465 url: baseDir + 'cart.php', 466 async: true, 467 cache: false, 468 dataType : "json", 469 data: 'delete=1' + extraParamsStr + '&summary&id_product=' + idProduct + '&ipa=' + ((idCombination != null && parseInt(idCombination)) ? idCombination : '') + ((customizationId && customizationId != null) ? '&id_customization=' + customizationId : '') +'&pay_with_points='+pay_with_points + '&token=' + static_token + '&ajax=true' + ('undefined' != typeof(idGift) ? '&gift=' + idGift : ''), 470 success: function(jsonData) { 471 ajaxCart.updateCart(jsonData); 472 $('.shopping_cart .dropdown-block').removeClass('load'); 473 if ($('body').attr('id') == 'order' || $('body').attr('id') == 'order-opc') { 474 deletProductFromSummary(idProduct+'_'+idCombination, idGift); 475 } 476 if (typeof googleAnalyticsAddRemoveAction === 'function') { 477 googleAnalyticsAddRemoveAction(idProduct, idCombination, qty, true); 478 } 479 480 self.addToRecommended(idProduct); 481 if (typeof algoliaCartProducts !== 'undefined') { 482 var cartProducts = JSON.parse(window.algoliaCartProducts); 483 cartProducts = cartProducts.filter(function(item) { 484 return item !== idProduct.toString() 485 }); 486 window.algoliaCartProducts = JSON.stringify(cartProducts); 487 document.dispatchEvent(new CustomEvent('onCartUpdate')); 488 } 489 }, 490 error: function() {console.log('ERROR: unable to delete the product');} 491 }); 492 }, 493 494 trackRecommendedAddToCart: function (idProduct, idCombination, quantity, callerElement, reloadPage) { 495 if ($(callerElement).attr('data-recommended-product')) { 496 let async = !reloadPage; // on checkout run not async in order execute ajax before reload page 497 let algolia = 0; 498 let query_id = ''; 499 if (typeof $(callerElement).attr('data-algolia-item') !== 'undefined') { 500 algolia = 1; 501 } 502 if (typeof $(callerElement).attr('data-query_id') !== 'undefined') { 503 query_id = $(callerElement).attr('data-query_id'); 504 } 505 if (!idCombination && typeof $(callerElement).attr('data-attribute-id') !== 'undefined') { 506 idCombination = parseInt($(callerElement).attr('data-attribute-id')); 507 } 508 $.ajax({ 509 type: 'POST', 510 url: baseDir + 'modules/recommendedstats/ajax.php', 511 data: {added: idProduct, id_attribute: idCombination, quantity: quantity, algolia: algolia, query_id: query_id}, 512 async: async, 513 success: function (data) { 514 if (reloadPage) { 515 window.location.reload(); 516 } 517 } 518 }); 519 } 520 }, 521 522 removeFromRecommended: function(idProduct) { 523 const windowSliderController = window.sliders(); 524 const recommendedSelectors = windowSliderController.getRecommendedSelectors(); 525 recommendedSelectors.forEach(function (selector) { 526 if ($(selector).length && typeof detachedRecommended !== 'undefined') { 527 if ($('[data-id-recommended|="'+idProduct+'"]').length) { 528 if (typeof detachedRecommended[selector] === 'undefined') { 529 detachedRecommended[selector] = []; 530 } 531 532 detachedRecommended[selector][idProduct] = { 533 index: $(selector + ' [data-id-recommended|="'+idProduct+'"]').attr('data-recommended-index'), 534 el: $(selector + ' [data-id-recommended|="'+idProduct+'"]').detach() 535 }; 536 if (windowSliderController.swiperInstances[selector]) { 537 windowSliderController.swiperInstances[selector].update(); 538 539 let slidesPerView = windowSliderController.getRecommendedSlidesPerView(selector); 540 let slideTo = 0; 541 if (windowSliderController.swiperInstances[selector].clickedIndex+1 > slidesPerView) { 542 slideTo = windowSliderController.swiperInstances[selector].clickedIndex - slidesPerView; 543 } 544 windowSliderController.swiperInstances[selector].slideTo(slideTo); 545 } 546 if (!$(selector + ' .swiper-wrapper li').length) { 547 $(selector).closest('.recommended-block').hide(); 548 } 549 } 550 } 551 }); 552 }, 553 554 addToRecommended: function(idProduct) { 555 const self = this; 556 const windowSliderController = window.sliders(); 557 const recommendedSelectors = windowSliderController.getRecommendedSelectors();
558 recommendedSelectors.forEach(function (selector) { 559 if ($(selector).length && typeof detachedRecommended !== 'undefined') { 560 if (detachedRecommended[selector] && detachedRecommended[selector][idProduct]) { 561 let detachedObj = detachedRecommended[selector][idProduct]; 562 let liRecommended = $(selector + ' .swiper-wrapper li'); 563 let insertAfter = 0; 564 565 if (liRecommended.length) { 566 let elementsBefore = []; 567 let elementsAfter = []; 568 liRecommended.each(function () { 569 let index = $(this).attr('data-recommended-index'); 570 if (parseInt(index) > parseInt(detachedObj.index)) { 571 elementsAfter.push(index); 572 } else { 573 elementsBefore.push(index); 574 } 575 }); 576 577 if (!elementsBefore.length) { 578 $(selector + ' .swiper-wrapper [data-recommended-index|="' + Math.min(...elementsAfter) + '"]').before(detachedObj.el); 579 } else { 580 elementsBefore.forEach(function (elBefore) { 581 if (parseInt(elBefore) == detachedObj.index-1) { 582 insertAfter = elBefore; 583 return false; 584 } 585 if (parseInt(elBefore) > parseInt(insertAfter)) { 586 insertAfter = elBefore; 587 } 588 }); 589 $(selector + ' .swiper-wrapper [data-recommended-index|="' + insertAfter + '"]').after(detachedObj.el); 590 } 591 592 } else { 593 detachedObj.el.prependTo(selector + ' .swiper-wrapper'); 594 } 595 596 if ($(selector).closest('.recommended-block').is(':hidden')) { 597 $(selector).closest('.recommended-block').show(); 598 } 599 delete detachedRecommended[selector][idProduct]; 600 if (windowSliderController.swiperInstances[selector]) { 601 windowSliderController.swiperInstances[selector].update(); 602 let slidesPerView = windowSliderController.getRecommendedSlidesPerView(selector); 603 let slideTo = $(selector + ' .swiper-wrapper [data-recommended-index|="' + insertAfter + '"]').index()+1 - (Math.round(slidesPerView)-1); 604 windowSliderController.swiperInstances[selector].slideTo(slideTo < 0 ? 0 : slideTo); 605 } 606 self.overrideButtonsInThePage(); 607 } 608 } 609 }); 610 }, 611 612 //hide the products displayed in the page but no more in the json data 613 hideOldProducts : function(jsonData) { 614 615 }, 616 617 hideOldProductCustomizations : function (product, domIdProduct) 618 { 619 620 }, 621 622 doesCustomizationStillExist : function (product, customizationId) 623 { 624 625 }, 626 627 //refresh display of vouchers (needed for vouchers in % of the total) 628 refreshVouchers : function (jsonData) { 629 630 }, 631 632 // Update product quantity 633 updateProductQuantity : function (product, quantity) { 634 635 }, 636 637 638 //display the products witch are in json data but not already displayed 639 displayNewProducts : function(jsonData) { 640 641 }, 642 643 displayNewCustomizedDatas : function(product) 644 { 645 646 }, 647 648 //genarally update the display of the cart 649 updateCart : function(jsonData, addedFromProductPage) { 650 if ('undefined' === typeof addedFromProductPage) { 651 addedFromProductPage = false; 652 } 653 //user errors display 654 if (jsonData.hasError) 655 { 656 var errors = ''; 657 for(error in jsonData.errors) 658 //IE6 bug fix 659 if(error != 'indexOf') 660 errors += jsonData.errors[error] + "\n"; 661 if (errors.length) { 662 alert(errors); 663 } 664 ajaxCart.hideLoaders(addedFromProductPage); 665 } 666 else 667 { 668 ajaxCart.refreshMiniCart(jsonData); 669 //reset the onlick events in relation to the cart block (it allow to bind the onclick event to the new 'delete' buttons added) 670 ajaxCart.overrideButtonsInThePage(); 671 } 672 }, 673 674 //update general cart informations everywhere in the page 675 updateCartEverywhere : function(jsonData) { 676 677 }, 678 679 generateMinicartProductBlock: function(product) { 680 681 }, 682 683 generateMinicartFooter: function (jsonData) { 684 685 }, 686 687 refreshMiniCart : function (jsonData) { 688 if (typeof jsonData.minicart_html !== 'undefined') { 689 $('.js-wrap-minicart').html(jsonData.minicart_html) 690 if (typeof blockUserInfo !== 'undefined') { 691 if (blockUserInfo.view === 'minicart') { 692 document.dispatchEvent(new CustomEvent('onChangeMiniCart')); 693 } 694 blockUserInfo.recalculatePadding() 695 } 696 697 $('.ajax_cart_quantity').text(jsonData.summary.cart_qties) 698 if (jsonData.summary.cart_qties) { 699 $('.ajax_cart_quantity').removeClass('hiddenLight') 700 } else { 701 $('.ajax_cart_quantity').addClass('hiddenLight') 702 } 703 704 if (jsonData.summary.splio_points_deferred && $('.js-wrap-minicart .splio-block').length) { 705 ajaxCart.loadMinicartSplioBlock(); 706 } 707 } 708 }, 709 710 // Cart requests sent with from_global_script skip Splio data to stay fast, so the mini cart points come from a separate request 711 minicartSplioXhr: null, 712 loadMinicartSplioBlock: function () { 713 if (ajaxCart.minicartSplioXhr) { 714 ajaxCart.minicartSplioXhr.abort(); 715 } 716 ajaxCart.minicartSplioXhr = $.ajax({ 717 type: 'GET', 718 url: baseDir + 'modules/splio/ajax.php', 719 cache: false, 720 dataType: 'json', 721 data: 'action=get_products_splio_data&minicart_splio_block=1', 722 success: function (jsonData) { 723 if (jsonData && jsonData.html) { 724 $('.js-wrap-minicart .splio-block').replaceWith($.trim(jsonData.html)); 725 if (typeof blockUserInfo !== 'undefined') { 726 blockUserInfo.recalculatePadding(); 727 } 728 } 729 },
730 complete: function () { 731 ajaxCart.minicartSplioXhr = null; 732 } 733 }); 734 }, 735 736 processQtyChange: function () { 737 var identifier = $(this.el).attr('name'); 738 var newQty = $(this.el).val(); 739 var exp = new RegExp("^[0-9]+$"); 740 if (exp.test(newQty) == true && newQty > 0) { 741 var oldQty = $('input[name='+ identifier +'_old]').val(); 742 var QtyToUp = parseInt(newQty) - parseInt(oldQty); 743 744 $('#add-to-cart-popup').find('#added-product-container').addClass('loading'); 745 746 var operator = QtyToUp > 0 ? 'up' : 'down'; 747 var ids = identifier.split('_'); 748 var inputElement = $(this.el); 749 ajaxCart.updateQty(ids[2], ids[3], oldQty, QtyToUp, operator, function() { 750 $('input[name='+ identifier +'_old]').val(newQty); 751 ajaxCart.refresh(); 752 ajaxCart.AddedProductPopup.setQuantity(inputElement, newQty, 1); 753 }); 754 } 755 else { 756 $('input[name='+ identifier +']').val($('input[name='+ identifier +'_old]').val()); 757 } 758 }, 759 760 updateQty: function (idProduct, idAttribute, qty, qtyChange, operator, onSuccess) { 761 idProduct = parseInt(idProduct); 762 if (!idProduct) { 763 return; 764 } 765 idAttribute = parseInt(idAttribute) || 0; 766 qtyChange = parseInt(qtyChange) || 1; 767 if (qtyChange < 0) { 768 qtyChange = -qtyChange; 769 } 770 let pay_with_points = $('.ajax_add_to_cart_button[data-id_product="' + idProduct + '"]').data('only_points_price'); 771 772 if (typeof algolia_query_id !== 'undefined') { 773 var type = 'listing'; 774 if (typeof algolia_category_page !== 'undefined') { 775 type = 'category_listing'; 776 } 777 if (typeof algolia_autocomplete_search !== 'undefined') { 778 type = 'autocomplete'; 779 } 780 var data = { 781 'query_id': algolia_query_id, 782 'type': type, 783 } 784 algolia.saveEventData(data); 785 } 786 787 $.ajax({ 788 type: 'GET', 789 url: baseDir + 'cart.php', 790 async: true, 791 cache: false, 792 dataType: 'json', 793 data: 'ajax=true' + (typeof pay_with_points != "undefined" ? '&pay_with_points=' + pay_with_points : '') + '&add&summary&from_global_script=1&id_product='+idProduct+'&ipa='+idAttribute+'&qty='+qtyChange+'&op='+operator+'&token=' + static_token , 794 success: function(jsonData) 795 { 796 if (jsonData.hasError) 797 { 798 var errors = ''; 799 for(error in jsonData.errors) 800 //IE6 bug fix 801 if(error != 'indexOf') 802 errors += jsonData.errors[error] + "\n"; 803 804 805 if (errors.length) { 806 alert(errors); 807 } 808 809 $('#added-product-container').removeClass('loading'); 810 $('#added-product-container .cart_quantity_value').val(qty); 811 812 } 813 else 814 { 815 if (typeof onSuccess !== 'undefined') { 816 onSuccess.call(); 817 } 818 819 if (jsonData.shopping_cart_gift_tribe_sidebar_html && $('#add-to-cart-popup .middle-block').length) { 820 $('#add-to-cart-popup .middle-block').html(jsonData.shopping_cart_gift_tribe_sidebar_html) 821 } else { 822 $('#add-to-cart-popup .middle-block').html('') 823 } 824 } 825 }, 826 error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} 827 }); 828 }, 829 830 AddedProductPopup: { 831 only_points_price: null, 832 show: function (idProduct, idCombination, addedFromProductPage, quantity, callerElement) { 833 $('body').append($('<div id="added-product-popup-content" class="hidden">')); 834 var only_points_price = $(callerElement).data('only_points_price') || 0; 835 this.only_points_price = only_points_price; 836 var id_lang = $('#id_lang').val(); 837 838 $('#added-product-popup-content').load(baseDir + 'modules/blockcart/ajax.php?addedProductPopup=1&id_product=' + idProduct + '&id_combination=' + idCombination + '&quantity=' + quantity + '&only_points_price=' + only_points_price + '&id_lang=' + id_lang + '&algolia_recommended=' + window.algoliaRecommended, function () { 839 var $modalContent = ajaxCart.ensureAddToCartModal().find('.add-to-cart-modal-content'); 840 $modalContent.find('.prepare-fancy').replaceWith($('#added-product-popup-content').html()); 841 842 // insert preloaded recommended server data to popup 843 if ($('#recommended_server_tmp .recomendServerRecommended').length) { 844 $($('#recommended_server_tmp .recomendServerRecommended').detach()).appendTo('#recommended-products-container'); 845 } 846 847 if ($('#algoliaCartRecommended').length) { 848 $('#algoliaCartRecommended').appendTo('#recommended-products-container').show(); 849 } 850 851 document.dispatchEvent(new CustomEvent('onCompleteProductPopup')); 852 ajaxCart.overrideButtonsInThePage(); 853 854 $('#add-to-cart-popup').find('.cart_quantity_value').off('keydown paste cut input') 855 .typeWatch({ 856 highlight: true, 857 wait: 600, 858 captureLength: 0, 859 callback: ajaxCart.processQtyChange 860 }); 861 $('[name=pay_with_points]').off('change').on('change', function () { 862 var idProduct = $("#add-to-cart-popup").data("id_product"); 863 var idCombination = $("#cart_attribute_"+idProduct).data("attribute-id"); 864 ajaxCart.AddedProductPopup.changePaymentMethod(Number($(this).prop('checked')), idProduct, idCombination); 865 ajaxCart.refresh(); 866 }); 867 if ($('.sl-tier-info.sl-points-info').length) { 868 $('.top-block .price_quantity .cart_quantity_up').prop('disabled', 1); 869 } 870 }); 871 }, 872
873 // plus - minus quantity click 874 refreshQuantity: function ($elem, qtyChange, minimalValue = 0) { 875 if (!$elem.closest('#add-to-cart-popup').length) { 876 return; 877 } 878 var prevQty = parseInt($elem.parent('form').siblings('.cart_quantity').val()); 879 var newQty = prevQty + qtyChange; 880 newQty = newQty > minimalValue ? newQty : minimalValue; 881 if (newQty <= minimalValue) { 882 $elem.parents('.quantity-wrap').find('.cart_quantity_down.cart_quantity_down').attr('disabled', 'disabled'); 883 } else { 884 $elem.parents('.quantity-wrap').find('.cart_quantity_down.cart_quantity_down').prop('disabled', false); 885 } 886 if ($elem.parents('#add-to-cart-popup .recommended-product').length > 0) { 887 var idProduct = $elem.parents('#add-to-cart-popup .recommended-product').data("id_product"); 888 var idCombination = $elem.parents('#add-to-cart-popup .recommended-product').data("attribute-id"); 889 } 890 else { 891 var idProduct = $("#add-to-cart-popup").data("id_product"); 892 var idCombination = $("#cart_attribute_"+idProduct).data("attribute-id"); 893 } 894 $elem.parent('form').siblings('.cart_quantity').val(newQty); 895 ajaxCart.AddedProductPopup.updatePrice(idProduct, idCombination, newQty, $elem); 896 }, 897 898 // manually change qty value 899 setQuantity: function ($input, newQty, minimalValue = 0) { 900 var idProduct = $("#add-to-cart-popup").data("id_product"); 901 var idCombination = $("#cart_attribute_"+idProduct).data("attribute-id"); 902 var addedFromProductPage = false; 903 if ($("#quantity_wanted").length) { 904 addedFromProductPage = true; 905 } 906 if (newQty <= minimalValue) { 907 $input.parents('.quantity-wrap').find('.cart_quantity_down.cart_quantity_down').attr('disabled', 'disabled'); 908 } else { 909 $input.parents('.quantity-wrap').find('.cart_quantity_down.cart_quantity_down').prop('disabled', false); 910 } 911 if ($input.parents('#add-to-cart-popup .recommended-product').length > 0) { 912 idProduct = $input.parents('#add-to-cart-popup .recommended-product').data("id_product"); 913 idCombination = $input.parents('#add-to-cart-popup .recommended-product').data("attribute-id"); 914 } 915 else { 916 idProduct = $("#add-to-cart-popup").data("id_product"); 917 idCombination = $("#cart_attribute_"+idProduct).data("attribute-id"); 918 } 919 ajaxCart.AddedProductPopup.updatePrice(idProduct, idCombination, newQty); 920 }, 921 updatePrice: function (idProduct, idCombination, newQty, elem = null) { 922 var pointsError = 0; 923 if ($('.sl-tier-info.sl-points-info').length) { 924 if ($('.top-block .quantity-wrap .cart_quantity_up').attr('disabled') == 'disabled') { 925 $('.top-block .quantity-wrap .cart_quantity_up').attr('disabled', false); 926 pointsError = 1; 927 } 928 } 929 var error_has = true; 930 if ($('.point_error').length) { 931 var value = parseInt($('.point_error').val(), 10) - 1; 932 if (+newQty > value) { 933 error_has = false; 934 } else if (+newQty == value){ 935 error_has = false; 936 $('.point_error').remove(); 937 $('.sl-tier-info').remove(); 938 $('.sl-link-wrap').remove(); 939 $('.top-block .quantity-wrap .cart_quantity_up').attr('disabled', false); 940 } 941 } 942 if (error_has) { 943 $.ajax({ 944 type: 'POST', 945 url: baseDir+'modules/blockcart/ajax.php', 946 async: true, 947 cache: false, 948 dataType: 'json', 949 data: 'refreshQuantity=1&pointsError='+pointsError+'&id_product=' + idProduct + '&id_combination=' + idCombination + '&quantity=' + newQty +'&token=' + static_token , 950 success: function(jsonData) 951 { 952 if ('error' in jsonData) { 953 if ($('.sl-points-info').length === 0) { 954 $('.top-block').after($(jsonData.error.layout)); 955 $('.top-block').append('<input class="point_error" type="hidden" value="'+newQty+'" />'); 956 } 957 } 958 959 var separator = ','; 960 if (typeof currencyFormat !== 'undefined' && currencyFormat == 1) { 961 separator = '.'; 962 } 963 var price_without_reduction = parseFloat(jsonData.price_without_reduction); 964 var displayed_price = parseFloat(jsonData.displayed_price); 965 price_without_reduction = Math.ceil((price_without_reduction)*100)/100;
966 displayed_price = Math.ceil((displayed_price)*100)/100; 967 if(price_without_reduction != displayed_price) { 968 969 if($("#recommended_product_" + idProduct + "_" + idCombination + " .product-old-price").length){ 970 $("#recommended_product_" + idProduct + "_" + idCombination + " .product-old-price").show(); 971 } 972 else { 973 974 if ($(elem).closest('.right-block').find('.product-old-price').length === 0) { 975 var currencySignAfter = currencyShowInDefaultEURFormat == 1 || (typeof currencyFormat !== 'undefined' && (currencyFormat == 5 || currencyFormat == 6)); 976 var htmlOldPrice = '<span class="price product-old-price">'+ (!currencySignAfter ? '<span class="currency_sign"></span>' : '') +'<span class="integer_part_of_price"></span><span class="fractial_part_of_price"></span>'+ (currencySignAfter ? '<span class="currency_sign"></span>' : '') +'</span>'; 977 $(htmlOldPrice).insertBefore($(elem).closest('.right-block').find(".product-current-price")); 978 } 979 } 980 price_without_reduction = price_without_reduction.toString(); 981 var price_without_reduction_int_price = price_without_reduction.split('.')[0] + separator; 982 var price_without_reduction_fract_price = price_without_reduction.split('.')[1]; 983 if(typeof price_without_reduction_fract_price == "undefined" ) { 984 price_without_reduction_fract_price = "00"; 985 } 986 else { 987 price_without_reduction_fract_price = price_without_reduction_fract_price.padEnd(2,'0'); 988 } 989 if (price_without_reduction_int_price) { 990 $(elem).closest('.right-block').find(".product-old-price .integer_part_of_price").text(price_without_reduction_int_price) 991 $(elem).closest('.right-block').find(".product-old-price .fractial_part_of_price").text(price_without_reduction_fract_price) 992 } 993 994 $("#recommended_product_" + idProduct + "_" + idCombination + " .product-old-price .integer_part_of_price").text(price_without_reduction_int_price); 995 $("#recommended_product_" + idProduct + "_" + idCombination + " .product-old-price .fractial_part_of_price").text(price_without_reduction_fract_price); 996 } 997 else { 998 $("#recommended_product_" + idProduct + "_" + idCombination + " .product-old-price").hide(); 999 $(elem).closest('.right-block').find(".product-old-price .integer_part_of_price").text('') 1000 $(elem).closest('.right-block').find(".product-old-price .fractial_part_of_price").text('') 1001 } 1002 1003 displayed_price = displayed_price.toString(); 1004 var displayed_price_int_price = displayed_price.split('.')[0] + separator; 1005 var displayed_price_fract_price = displayed_price.split('.')[1]; 1006 if(typeof displayed_price_fract_price == "undefined" ) { 1007 displayed_price_fract_price = "00"; 1008 } 1009 else { 1010 displayed_price_fract_price = displayed_price_fract_price.padEnd(2,'0'); 1011 } 1012 1013 $("#recommended_product_" + idProduct + "_" + idCombination + " .product-current-price .integer_part_of_price").text(displayed_price_int_price); 1014 $("#recommended_product_" + idProduct + "_" + idCombination + " .product-current-price .fractial_part_of_price").text(displayed_price_fract_price); 1015 1016 $(".added-product_" + idProduct + " .product-current-price .integer_part_of_price").text(displayed_price_int_price); 1017 $(".added-product_" + idProduct + " .product-current-price .fractial_part_of_price").text(displayed_price_fract_price); 1018 if ($(elem).closest('.right-block').find(".earn-points").length > 0) { 1019 let pointsElement = $(elem).closest('.right-block').find(".earn-points span").length > 0 ? $(elem).closest('.right-block').find(".earn-points span") : $(elem).closest('.right-block').find(".use-points"); 1020 if (pointsElement.length > 0) { 1021 let points = pointsElement.attr('data-points-price'); 1022 $(pointsElement).text(points * newQty) 1023 } 1024 } 1025 1026 $('#add-to-cart-popup').find('#added-product-container').removeClass('loading'); 1027 if ($(elem).closest('.right-block').find('.price-points.use.active').length) { 1028 $(elem).closest('.right-block').find('.product-price-wrap').hide(); 1029 } else { 1030 $(elem).closest('.right-block').find('.product-price-wrap').show(); 1031 } 1032 $('.shopping_cart .dropdown-block').removeClass('load'); 1033 }, 1034 error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} 1035 }); 1036 } 1037 }, 1038 refreshCombination: function ($elem, data) { 1039 if ($('#add-to-cart-popup .product-old-price').length) { 1040 $('#add-to-cart-popup .product-old-price .integer_part_of_price').text(data.price.price_without_reduction.toFixed(2)); 1041 $('#add-to-cart-popup .product-old-price .fractial_part_of_price').text(''); 1042 } 1043 1044 1045 $('#add-to-cart-popup .product-current-price .integer_part_of_price, #add-to-cart-popup .product-current-price .fractial_part_of_price').each(function() { 1046 if ($(this).closest('.recommended-product').length === 0) { 1047 if ($(this).hasClass('integer_part_of_price')) { 1048 $(this).text(data.price.price.toFixed(2)); 1049 } else if ($(this).hasClass('fractial_part_of_price')) { 1050 $(this).text(''); 1051 } 1052 } 1053 }); 1054 $('#add-to-cart-popup select.ipa_id').data('attribute-id', data.idCombination); 1055 if (data.idCombination) { 1056 var $popup = $elem.closest('#add-to-cart-popup'); 1057 $popup.find('.cart_quantity_up').data('id-attribute', data.idCombination); 1058 $popup.find('.cart_quantity_down').data('id-attribute', data.idCombination); 1059 } 1060 }, 1061 showAddedRecommendedProductTitle: function ($elem, $name) { 1062 let name; 1063 if ($name) { 1064 name = $name; 1065 } else { 1066 name = $elem.find('.product-title').text(); 1067 } 1068 $('.add-to-cart-popup-added-container .add-to-cart-popup-added-title .product-name').text(name); 1069 $('.add-to-cart-popup-added-container').slideDown(100); 1070 $('#add-to-cart-modal .add-to-cart-modal-close').hide(); 1071 if (typeof window.addToCartTimerId !== "undefined") { 1072 clearTimeout(window.addToCartTimerId); 1073 } 1074 window.addToCartTimerId = setTimeout(function() { 1075 $('.add-to-cart-popup-added-container').slideUp(100); 1076 $('#add-to-cart-modal .add-to-cart-modal-close').show(); 1077 }, 5000); 1078 }, 1079 closeAddedRecommendedProductTitle: function () { 1080 if (typeof window.addToCartTimerId !== "undefined") { 1081 clearTimeout(window.addToCartTimerId); 1082 } 1083 $('.add-to-cart-popup-added-container').slideUp(100); 1084 $('#add-to-cart-modal .add-to-cart-modal-close').show(); 1085 }, 1086 changePaymentMethod: function (pay_with_points, idProduct, idCombination) { 1087 $.ajax({ 1088 type: 'POST', 1089 url: baseDir+'modules/blockcart/ajax.php', 1090 async: true, 1091 cache: false, 1092 dataType: 'json', 1093 data: 'changePaymentMethod=1&pay_with_points=' + pay_with_points + '&id_product=' + idProduct + '&id_product_attribute=' + idCombination +'&token='
1093+ static_token , 1094 success: function(jsonData) { 1095 1096 }, 1097 }); 1098 }, 1099 } 1100 1101}; 1102 1103//when document is loaded... 1104$(document).ready(function(){ 1105 $('.shopping_cart .scroll-btn').on('click', function(){ 1106 var offset = $('.cart-products').scrollTop(); 1107 if ($(this).hasClass('up')) { 1108 offset -= $('.cart-products').find('.single-product').outerHeight(); 1109 } 1110 else { 1111 offset += $('.cart-products').find('.single-product').outerHeight(); 1112 } 1113 1114 $('.cart-products').animate({ 1115 scrollTop: (offset) 1116 },500); 1117 }); 1118 $('.shopping_cart .dropdown-block').on('showAfter', function(){ 1119 if ($('.shopping_cart .cart-products').length) { 1120 var productsElement = $('.cart-products')[0]; 1121 if (productsElement.offsetHeight < productsElement.scrollHeight) { // products block overflow 1122 $('.shopping_cart .scroll-btn').show(); 1123 } else { 1124 $('.shopping_cart .scroll-btn').hide(); 1125 } 1126 } 1127 }); 1128 1129 1130 $(document).on('click', '.cart_quantity_up', function(e) { 1131 e.preventDefault(); 1132 1133 var $self = $(this); 1134 $('#add-to-cart-popup').find('#added-product-container').addClass('loading'); 1135 $('.shopping_cart .dropdown-block').addClass('load'); 1136 var productId = 0; 1137 var productAttributeId = 0; 1138 var pay_with_points = 0; 1139 var ids = 0; 1140 var ajaxAction = 1; 1141 ids = $(this).attr('id').replace('cart_quantity_up_', '').split('_'); 1142 productId = parseInt(ids[0]); 1143 if ($(this).data('id-attribute')) { 1144 productAttributeId = parseInt($(this).data('id-attribute')); 1145 } 1146 else if (typeof(ids[1]) !== 'undefined') { 1147 productAttributeId = parseInt(ids[1]); 1148 } 1149 if (typeof(ids[2]) != 'undefined') 1150 pay_with_points = parseInt(ids[2]); 1151 if ($self.closest('#add-to-cart-popup') && ajaxCart.AddedProductPopup.only_points_price) { 1152 pay_with_points = 1; 1153 } 1154 1155 if (typeof algolia_query_id !== 'undefined') { 1156 var type = 'listing'; 1157 if (typeof algolia_category_page !== 'undefined') { 1158 type = 'category_listing'; 1159 } 1160 if (typeof algolia_autocomplete_search !== 'undefined') { 1161 type = 'autocomplete'; 1162 } 1163 var data = { 1164 'query_id': algolia_query_id, 1165 'type': type, 1166 } 1167 algolia.saveEventData(data); 1168 } 1169 if ($(this).data('noaction')) { 1170 ajaxAction = 0; 1171 } 1172 1173 var error_has = false; 1174 var newQty = false; 1175 if ($('.point_error').length) { 1176 var value = parseInt($('.point_error').val(), 10) - 1; 1177 newQty = parseInt($('.top-block .quantity-wrap .cart_quantity_value').val(), 10); 1178 if (newQty >= value) { 1179 error_has = true; 1180 } 1181 } 1182 1183 if (ajaxAction && !error_has) { 1184 $.ajax({ 1185 type: 'GET', 1186 url: baseDir + 'cart.php', 1187 async: true, 1188 cache: false, 1189 dataType: 'json', 1190 data: 'ajax=true&add&summary&from_global_script=1&id_product='+productId+'&ipa='+productAttributeId+'&pay_with_points='+pay_with_points + '&qty=1&token=' + static_token , 1191 success: function(jsonData) 1192 { 1193 if ((jsonData.hasError && jsonData.productsLimit) || typeof jsonData.seedsLimit !== 'undefined') { 1194 $('#add-to-cart-popup').find('#added-product-container, .quantity-wrap').removeClass('loading'); 1195 $('.shopping_cart .dropdown-block').removeClass('load'); 1196 ajaxCart.closeAddToCartModal(); 1197 return; 1198 } 1199 newQty = parseInt($('.top-block .quantity-wrap .cart_quantity_value').val(), 10) + 1; 1200 if (typeof jsonData !== 'undefined' && jsonData.vip_errors) { 1201 $('.top-block .quantity-wrap .cart_quantity_up').attr('disabled', true) 1202 $.ajax({ 1203 type: 'POST', 1204 url: baseDir+'modules/blockcart/ajax.php', 1205 async: true, 1206 cache: false, 1207 dataType: 'json', 1208 data: 'refreshQuantity=1&pointsError=1&id_product=' + productId + '&id_combination=' + productAttributeId + '&quantity=' + newQty +'&token=' + static_token , 1209 success: function(jsonData) 1210 { 1211 if ('error' in jsonData) { 1212 if ($('.sl-points-info').length === 0) { 1213 $('.top-block').after($(jsonData.error.layout)); 1214 $('.top-block').append('<input class="point_error" type="hidden" value="'+ newQty +'" />'); 1215 } 1216 } 1217 }, 1218 error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to3 save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} 1219 }); 1220 } 1221 1222 if (jsonData.shopping_cart_gift_tribe_sidebar_html && $('#add-to-cart-popup .middle-block').length) { 1223 $('#add-to-cart-popup .middle-block').html(jsonData.shopping_cart_gift_tribe_sidebar_html) 1224 } else { 1225 $('#add-to-cart-popup .middle-block').html('') 1226 } 1227 1228 if (jsonData.hasError) 1229 { 1230 var errors = ''; 1231 for(error in jsonData.errors) 1232 //IE6 bug fix 1233 if(error != 'indexOf') 1234 errors += jsonData.errors[error] + "\n"; 1235 1236 1237 if (errors.length) { 1238 alert(errors); 1239 $('.shopping_cart .dropdown-block').removeClass('load'); 1240 } 1241 } 1242 else 1243 { 1244 ajaxCart.refresh(!$self.closest('#add-to-cart-popup').length); 1245 ajaxCart.AddedProductPopup.refreshQuantity($self, +1, 1); 1246 if (typeof opcPage !== 'undefined') { 1247 opcPage.updateOpcCartPage(jsonData); 1248 } 1249 } 1250 1251 if (typeof googleAnalyticsAddRemoveAction === 'function') { 1252 googleAnalyticsAddRemoveAction(productId, productAttributeId, 1, false); 1253 } 1254 }, 1255 error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} 1256 }); 1257 } else { 1258 $('#add-to-cart-popup').find('#added-product-container').removeClass('loading'); 1259 $('.shopping_cart .dropdown-block').removeClass('load'); 1260 ajaxCart.refresh(!$self.closest('#add-to-cart-popup').length); 1261 ajaxCart.AddedProductPopup.refreshQuantity($self, +1, 1); 1262 } 1263 }); 1264 $(document).on('click', '.cart_quantity_down', function(e) { 1265 e.preventDefault(); 1266 1267 var $self = $(this); 1268 $('#add-to-cart-popup').find('#added-product-container').addClass('loading'); 1269 $('.shopping_cart .dropdown-block').addClass('load'); 1270 var productId = 0; 1271 var productAttributeId = 0; 1272 var pay_with_points = 0; 1273 var ids = 0; 1274 var ajaxAction = 1; 1275 ids = ids = $(this).attr('id').replace('cart_quantity_down_', '').split('_'); 1276 productId = parseInt(ids[0]); 1277 if ($(this).data('id-attribute')) { 1278 productAttributeId = parseInt($(this).data('id-attribute')); 1279 } 1280 else if (typeof(ids[1]) !== 'undefined') { 1281 productAttributeId = parseInt(ids[1]); 1282 } 1283 if (typeof(ids[2]) != 'undefined') 1284 pay_with_points = parseInt(ids[2]); 1285 if ($self.closest('#add-to-cart-popup') && ajaxCart.AddedProductPopup.only_points_price) { 1286 pay_with_points = 1; 1287 } 1288 1289 if ($(this).data('noaction')) { 1290 ajaxAction = 0; 1291 } 1292 var newQty = parseInt($('.top-block .quantity-wrap .cart_quantity_value').val(), 10); 1293 var error_has = true; 1294 if ($('.point_error').length) { 1295 var value = parseInt($('.point_error').val(), 10) - 1; 1296 if (newQty > value) { 1297 error_has = false;
1298 } else if (newQty == value){ 1299 error_has = false; 1300 $('.point_error').remove(); 1301 $('.sl-tier-info').remove(); 1302 $('.sl-link-wrap').remove(); 1303 $('.top-block .quantity-wrap .cart_quantity_up').attr('disabled', false); 1304 } 1305 } 1306 if (ajaxAction && error_has) { 1307 $.ajax({ 1308 type: 'GET', 1309 url: baseDir + 'cart.php', 1310 async: true, 1311 cache: false, 1312 dataType: 'json', 1313 data: 'ajax=true&add&summary&from_global_script=1&id_product='+productId+'&ipa='+productAttributeId+'&pay_with_points='+pay_with_points+'&op=down' + '&qty=1&token=' + static_token , 1314 success: function(jsonData) 1315 { 1316 if (jsonData.hasError) 1317 { 1318 var errors = ''; 1319 for(error in jsonData.errors) 1320 //IE6 bug fix 1321 if(error != 'indexOf') 1322 errors += jsonData.errors[error] + "\n"; 1323 if (errors.length) { 1324 alert(errors); 1325 $('.shopping_cart .dropdown-block').removeClass('load'); 1326 } 1327 } 1328 else 1329 { 1330 if ($('.error-block').length && !$('.error-block').hasClass('d-none')) { 1331 $('.error-block').addClass('d-none'); 1332 $('#add-to-cart-popup #added-product-container .top-block').removeClass('auto-height'); 1333 $('#recommended-products-container').removeClass('error-height'); 1334 $('#recommended-products-container').removeClass('error-height-points'); 1335 } 1336 ajaxCart.refresh(!$self.closest('#add-to-cart-popup').length); 1337 ajaxCart.AddedProductPopup.refreshQuantity($self, -1, 1); 1338 if (typeof opcPage !== 'undefined') { 1339 opcPage.updateOpcCartPage(jsonData); 1340 } 1341 1342 if (jsonData.shopping_cart_gift_tribe_sidebar_html && $('#add-to-cart-popup .middle-block').length) { 1343 $('#add-to-cart-popup .middle-block').html(jsonData.shopping_cart_gift_tribe_sidebar_html) 1344 } else { 1345 $('#add-to-cart-popup .middle-block').html('') 1346 } 1347 1348 if (!jsonData.summary.products.map((product) => product.id_product == productId).includes(true)) { 1349 ajaxCart.addToRecommended(productId); 1350 } 1351 } 1352 1353 if (typeof googleAnalyticsAddRemoveAction === 'function') { 1354 googleAnalyticsAddRemoveAction(productId, productAttributeId, 1, true); 1355 } 1356 }, 1357 error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to save update quantity \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} 1358 }); 1359 } else { 1360 $('#add-to-cart-popup').find('#added-product-container').removeClass('loading'); 1361 $('.shopping_cart .dropdown-block').removeClass('load'); 1362 ajaxCart.refresh(!$self.closest('#add-to-cart-popup').length); 1363 ajaxCart.AddedProductPopup.refreshQuantity($self, -1, 1); 1364 } 1365 }); 1366 1367 1368 $(document).on('change', '#add-to-cart-popup .combinations-block .ipa_id', function(e) { 1369 var $self = $(this); 1370 $('#add-to-cart-popup').find('#added-product-container').addClass('loading'); 1371 $('.shopping_cart .dropdown-block').addClass('load'); 1372 var productId = 0; 1373 var productAttributeId = 0; 1374 var ids = 0; 1375 var only_points_price = parseInt($(this).find(':selected').data('only_points_price')) || 0; 1376 1377 ids = $(this).attr('id').replace('cart_attribute_', '').split('_'); 1378 productId = $(this).attr('id').replace('cart_attribute_', ''); 1379 if ($(this).data('attribute-id')) { 1380 productAttributeId = parseInt($(this).data('attribute-id')); 1381 } 1382 1383 $.ajax({ 1384 type: 'GET', 1385 url: baseDir + 'cart.php', 1386 async: true, 1387 cache: false, 1388 dataType: 'json', 1389 data: 'ajax=true&changeAttribute&summary&from_global_script=1&id_product='+productId+'&ipa='+productAttributeId+'&attributeNew=' + $self.val() + '&token=' + static_token + '&only_points_price=' + only_points_price + '&change_quantity=' + $('#added-product-container .cart_quantity_value').val() || 1, 1390 success: function(jsonData) 1391 { 1392 if (jsonData.summary.use_points) { 1393 $($self).closest('.right-block').find('.price-points .use-points').attr('data-points-price', jsonData.summary.use_points); 1394 } 1395 if (jsonData.hasError) 1396 { 1397 var errors = ''; 1398 for(error in jsonData.errors) 1399 //IE6 bug fix 1400 if(error != 'indexOf') 1401 errors += jsonData.errors[error] + "\n"; 1402 if (errors.length) { 1403 alert(errors); 1404 } 1405 } 1406 else 1407 { 1408 ajaxCart.refresh(); 1409 var idCombination = $self.val(); 1410 var newPrice = { 1411 price: 0, 1412 price_without_reduction: 0 1413 }; 1414 for (var i in jsonData.summary.products) { 1415 if (jsonData.summary.products[i].id_product_attribute == idCombination) { 1416 newPrice.price = priceDisplayMethod ? jsonData.summary.products[i].price : jsonData.summary.products[i].price_wt; 1417 newPrice.price_without_reduction = jsonData.summary.products[i].price_without_reduction; 1418 break; 1419 } 1420 } 1421 1422 var data = { 1423 idCombination: idCombination, 1424 price: newPrice, 1425 points_price: jsonData.summary.points_price, 1426 only_points_price: jsonData.summary.only_points_price, 1427 }; 1428 1429 ajaxCart.AddedProductPopup.refreshCombination($self, data); 1430 1431 if (jsonData.shopping_cart_gift_tribe_sidebar_html && $('#add-to-cart-popup .middle-block').length) { 1432 $('#add-to-cart-popup .middle-block').html(jsonData.shopping_cart_gift_tribe_sidebar_html) 1433 } else { 1434 $('#add-to-cart-popup .middle-block').html('') 1435 } 1436 } 1437 $('#add-to-cart-popup').find('#added-product-container').removeClass('loading'); 1438 $('.shopping_cart .dropdown-block').removeClass('load'); 1439 if (typeof jsonData.summary !== 'undefined' && jsonData.summary.use_points !== null) { 1440 var cart_quantity_value = $($self).closest('.right-block').find('.cart_quantity_value').val() || 1; 1441 $($self).closest('.right-block').find('.price-points .use-points').text(jsonData.summary.use_points * cart_quantity_value); 1442 1443 if (!$($self).closest('.right-block').find('.price-points.use').hasClass('active')) { 1444 $($self).closest('.right-block').find('.price-points.use').addClass('active') 1445 $($self).closest('.right-block').find('.price-points.earn').removeClass('active') 1446 } 1447 } else { 1448 $($self).closest('.right-block').find('.price-points.use').removeClass('active') 1449 } 1450 1451 if (only_points_price) { 1452 $($self).closest('.right-block').find('.product-price-wrap').removeClass('active'); 1453 $('.product-payment-method-change').hide(); 1454 } else { 1455 $($self).closest('.right-block').find('.product-price-wrap').addClass('active'); 1456 if (typeof data !== 'undefined' && data.points_price) { 1457 $('.product-payment-method-change').show(); 1458 if (only_points_price) { 1459 $('.product-payment-method-change input').prop('checked', 'true'); 1460 } 1461 else { 1462 $('.product-payment-method-change input').prop('checked', ''); 1463 } 1464 } 1465 } 1466 1467 if (typeof jsonData.summary !== 'undefined' && jsonData.summary.earn_points !== null) { 1468 $($self).closest('.right-block').find('.price-points.earn') 1469 $($self).closest('.right-block').find('.price-points .earn-points').text(jsonData.summary.earn_points); 1470 if (!$($self).closest('.right-block').find('.price-points.earn').hasClass('active')) { 1471 $($self).closest('.right-block').find('.price-points.earn').addClass('active') 1472 $($self).closest('.right-block').find('.price-points.use').removeClass('active') 1473 } 1474 } else { 1475 $($self).closest('.right-block').find('.price-points.earn').removeClass('active') 1476 } 1477 1478 if (typeof jsonData.summary !== 'undefined' && $($self).closest('.right-block').find('.active .earn-points').empty()) { 1479 $($self).closest('.right-block').find('.active .earn-points').text(jsonData.summary.earn_points); 1480 } 1481 if ($($self).closest('.right-block').find('.price-points.use.active').length) { 1482 $($self).closest('.right-block').find('.product-price-wrap').hide(); 1483 } else { 1484 $($self).closest('.right-block').find('.product-price-wrap').show(); 1485 } 1486 }, 1487 error: function(XMLHttpRequest, textStatus, errorThrown) {alert("TECHNICAL ERROR: unable to change attribute \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);} 1488 }); 1489 }); 1490 1491 ajaxCart.overrideButtonsInThePage(); 1492});
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.