1/* global $, prestashop */ 2 3/** 4 * This module exposes an extension point in the form of the `showModal` function. 5 * 6 * If you want to override the way the modal window is displayed, simply define: 7 * 8 * prestashop.blockcart = prestashop.blockcart || {}; 9 * prestashop.blockcart.showModal = function myOwnShowModal (modalHTML) { 10 * // your own code 11 * // please not that it is your responsibility to handle closing the modal too 12 * }; 13 * 14 * Attention: your "override" JS needs to be included **before** this file. 15 * The safest way to do so is to place your "override" inside the theme's main JS file. 16 * 17 */ 18 19$(document).ready(function () { 20 21 prestashop.buy_now_cart = false; 22 23 $('body').on('click', '[data-button-action=add-to-cart]', function (event) { 24 if($(this).closest('form').find('input[name=qty]').val() > 0){ 25 if($(this).hasClass('js-buy-now')){ 26 prestashop.buy_now_cart = true; 27 } 28 $(this).addClass('loading'); 29 } 30 }); 31 32 $('body').on('click', '[data-link-action="delete-from-cart"], [data-link-action="remove-voucher"]', function (event) { 33 $('body').addClass('cart-processing'); 34 }); 35 36 $('body').on('click', '[data-link-action="delete-all-cart"]', function (event) { 37 var refreshURL = opShoppingCart.ajax; 38 var requestData = {}; 39 requestData = { 40 action: 'delete-all-cart' 41 }; 42 $('body').addClass('cart-processing'); 43 $.post(refreshURL, requestData).then(function (resp) { 44 $('[data-link-action="delete-from-cart"]').first().click(); 45 }); 46 }); 47 48 $('.js-cart-nbr').text(prestashop.cart.products_count); 49 50 $('.js-cart-amount').text(prestashop.cart.subtotals.products.value); 51 52 prestashop.on('updatedCart',function (event) { 53 if($(event.resp.cart_detailed).find('.empty-products').length > 0){ 54 $('body').addClass('cart-is-empty'); 55 if(typeof (prestashop.page.page_name) != 'undefined' && prestashop.page.page_name == 'checkout'){ 56 location.assign(prestashop.urls.pages.index); 57 } 58 }else{ 59 $('body').removeClass('cart-is-empty'); 60 } 61 }); 62 63 prestashop.on( 64 'updateCart', 65 function (event) { 66 var refreshURL = opShoppingCart.ajax; 67 var requestData = {}; 68 69 if (event && event.reason && typeof event.resp !== 'undefined' && !event.resp.hasError) { 70 requestData = { 71 id_customization: event.reason.idCustomization, 72 id_product_attribute: event.reason.idProductAttribute, 73 id_product: event.reason.idProduct, 74 action: event.reason.linkAction 75 }; 76 } 77 78 if(prestashop.buy_now_cart || (!opShoppingCart.has_ajax && event.reason.linkAction == 'add-to-cart')){ 79 location.assign(prestashop.urls.pages.order); 80 }else{ 81 82 $('body').addClass('cart-processing'); 83 84 if (event && event.resp && event.resp.hasError) { 85 prestashop.emit('showErrorNextToAddtoCartButton', { errorMessage: event.resp.errors.join('<br/>')}); 86 } 87 88 $.post(refreshURL, requestData).then(function (resp) { 89 90 $('body').removeClass('cart-processing'); 91 92 $('[data-button-action="add-to-cart"]').removeClass('loading'); 93 94 $('.js-shopping-cart').replaceWith($(resp.canvas).find('.js-shopping-cart')); 95 96 $('.js-cart-canvans-title').replaceWith($(resp.canvas).find('.js-cart-canvans-title')); 97 98 $('.js-cart-nbr').replaceWith($(resp.preview).find('.js-cart-nbr')); 99 100 $('.js-cart-amount').replaceWith($(resp.preview).find('.js-cart-amount')); 101 102 if($('#quantity_wanted').length){ 103 $('#quantity_wanted').change(); 104 } 105 106 prestashop.emit('updateCarted', null); 107 108 if (resp.modal) { 109 if( opShoppingCart.action_after == 'canvas' ){ 110 $('.modal').modal('hide'); 111 setTimeout(function(){ 112 prestashop.emit('show_canvas_widget', $('#canvas-mini-cart')); 113 }, 250); 114 }else{ 115 if($(resp.modal).find('span').length){ 116 toastr["success"](resp.modal); 117 }else{ 118 toastr["error"](resp.modal); 119 } 120 } 121 122 prestashop.emit('mustUpdateLazyLoad', null); 123 } 124 125 }).fail(function (resp) { 126 $('[data-button-action="add-to-cart"]').removeClass('loading'); 127 prestashop.emit('handleError', {eventType: 'updateShoppingCart', resp: resp}); 128 }); 129 130 } 131 } 132 ); 133});
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.