/* global $, prestashop */ /** * This module exposes an extension point in the form of the `showModal` function. * * If you want to override the way the modal window is displayed, simply define: * * prestashop.blockcart = prestashop.blockcart || {}; * prestashop.blockcart.showModal = function myOwnShowModal (modalHTML) { * // your own code * // please not that it is your responsibility to handle closing the modal too * }; * * Attention: your "override" JS needs to be included **before** this file. * The safest way to do so is to place your "override" inside the theme's main JS file. * */ $(document).ready(function () { prestashop.blockcart = prestashop.blockcart || {}; var showModal = prestashop.blockcart.showModal || function (modal) { var $body = $('body'); $body.append(modal); $body.one('click', '#blockcart-modal', function (event) { if (event.target.id === 'blockcart-modal') { $(event.target).remove(); } }); }; $(document).ready(function () { prestashop.on( 'updateCart', function (event) { if($('.cart_mobilelayout').length > 0){ var refreshURL = $('.cart_mobilelayout').data('refresh-url'); }else{ var refreshURL = $('.spblockcart').data('refresh-url'); } var requestData = {}; if (event && event.reason) { requestData = { id_product_attribute: event.reason.idProductAttribute, id_product: event.reason.idProduct, action: event.reason.linkAction }; } $.post(refreshURL, requestData).then(function (resp) { if($('.cart_mobilelayout').length > 0){ var refreshURL = $('.cart_mobilelayout').data('refresh-url'); }else{ $('.spblockcart').replaceWith(resp.preview); } if (resp.modal) { showModal(resp.modal); } }).fail(function (resp) { prestashop.emit('handleError', {eventType: 'updateShoppingCart', resp: resp}); }); } ); }); $('body').on('click', '.ajax-add-to-cart', function (event) { event.preventDefault(); var query = 'id_product=' + $(this).attr('data-id-product') + '&qty='+ $(this).attr('data-minimal-quantity') +'&add=1&action=update&token='+prestashop['static_token']; //var actionURL = prestashop['urls']['base_url'] + 'index.php?controller=cart'; var actionURL = prestashop['urls']['pages']['cart']; $.post(actionURL, query, null, 'json').then(function (resp) { prestashop.emit('updateCart', { reason: { idProduct: resp.id_product, idProductAttribute: resp.id_product_attribute, linkAction: 'add-to-cart' } }); }).fail(function (resp) { prestashop.emit('handleError', { eventType: 'addProductToCart', resp: resp }); }); }); });