/** * @version 1.0 * @author 202-ecommerce * @copyright 2014-2017 202-ecommerce * * ██████╗ ██████╗ ██████╗ * ╚════██╗██╔═████╗╚════██╗ * █████╔╝██║██╔██║ █████╔╝ * ██╔═══╝ ████╔╝██║██╔═══╝ * ███████╗╚██████╔╝███████╗ * ╚══════╝ ╚═════╝ ╚══════╝ * * e - c o m m e r c e * * ========================= * http://202-ecommerce.com * ========================= * */ $(document).ready(function() { // On product quantity update, update points. $(document).on('change', '.js-cart-line-product-quantity', function() { console.log('qty chabged'); var qty = $(this).val(); var productId = $(this).data('product-id'); totLoyaltyAdvancedCart.update(qty, productId); }); // On product deletion, update points. $(document).on('click', '.remove-from-cart', function() { var productId = $(this).data('id-product'); totLoyaltyAdvancedCart.update(0, productId); }); // On click on convert points to voucher, ask user to confirm. $(document).on('click', '[data-js-convert-points]', function(e) { e.preventDefault(); var href = $(this).attr('href'); if (confirm(confirmConvertPoints_txt)) { window.location.href = href; } }); }); var totLoyaltyAdvancedCart = { updateView: function(json) { if (json == undefined || !json.points) { return; } $('[data-js-points-count]').html(json.points); $('[data-js-voucher]').html(json.voucher); if (json.points == 1) { $('[data-js-point-txt]').show(); $('[data-js-points-txt]').hide(); } else { $('[data-js-point-txt]').hide(); $('[data-js-points-txt]').show(); } }, update: function(qty, idProduct) { if (qty == undefined || idProduct == undefined) { return; } var qty = String(qty); var idProduct = String(idProduct); console.log('call update', qty, idProduct); $.ajax({ type : 'POST', url : prestashop.urls.base_url + linkLoyaltyAjax, data : 'loyalty_qnt=' + qty + '&loyalty_product_id=' + idProduct + '&updateLoyaltyPointsInCart=1', dataType: 'json', success : function (json) { totLoyaltyAdvancedCart.updateView(json); }, error : function (xhr, ajaxOptions, thrownError) {} }); } };