在 MAGENTO 中使用 AJAX 更新购物车商品

UPDATE CART ITEMS USING AJAX IN MAGENTO

我想在不加载页面的情况下更新购物车项目,即在 ajax 的帮助下。 谁能告诉我我把这段代码放在了哪个文件中。

    jQuery(document).ready(function(){

    jQuery('#shopping-cart-table')
     .on(
          'change',
          'input[name$="[qty]"]',
           function(){
            var form = jQuery(jQuery(this).closest('form'));

             // we'll extract the action and method attributes out of the form

              // kick off an ajax request using the form's action and method,
        // with the form data as payload
        jQuery.ajax({
            url: form.attr('action'),
            method: form.attr('method'),
            data: form.serializeArray()
        });
    }
);

});

最简单的方法是将这段代码放在 Javascript 脚本标签中,放入结帐购物车模板中:magento/app/design/frontend/base/default/template/checkout/cart.phtml

注意,您必须将 update_cart_action 数据设置为 "update_qty",才能进入更新数量模式。

var formData = form.serializeArray();
formData.push({'update_cart_action' : 'update_qty'})

jQuery.ajax({
    url: form.attr('action'),
     method: form.attr('method'),
     data: formData
});