$(document).ready(function () { validateOnlineProduct(); addMaskInFields() }); function validateOnlineProduct() { if (typeof validateOnline !== "undefined" && validateOnline === false) { let buttonElement = $('.purchase-button'); buttonElement.addClass('disabled'); buttonElement.attr('href', 'javascript:void(0)'); } } function updateCart (data) { const cartDetail = $('.cart-detail'); /* the section requires the $section variable to be rendered correctly, * so this function encodes the variable to a JSON and sends it via AJAX * to the ShoppingCartController, so it can render the same view again * when the cart updates */ const cartWrapper = $('#cart-wrapper'); const cartLoading = $('#cart-loading'); $.ajax({ url: cartDetail.data('route'), data: data, beforeSend: function () { cartWrapper.hide(); cartLoading.show(); }, }).done(function (response) { cartWrapper.show(); cartLoading.hide(); cartDetail.empty(); cartDetail.html(response); validateOnlineProduct(); addMaskInFields(); }).catch(function (err) { // console.error(err); }); } /* * default-quantity-input and mobile-quantity-input contain ajax on file `cart-actions.js` */ $(document).on('change', '.default-quantity-input', function () { if ($(this).val() < 1) { $(this).val(1); } $(this).blur(); $(this).parent().submit(); }); $(document).on('change', '.mobile-quantity-input', function () { $(this).blur(); $(this).parent().submit(); });