2017-03-26 21 views
1

我想不加載與AJAX的幫助頁面即更新購物車中物品。 任何人都可以告訴我,我把這個代碼放在哪個文件中。UPDATE車中的物品使用Ajax在Magento

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() 
     }); 
    } 
); 

});

+0

任何人都可以幫助我.. ???? –

回答

1

最簡單的辦法就是把這個代碼在的Javascript腳本標籤進入結賬車模板:的Magento /應用程序/設計/前端/基/默認/模板/結算/ 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 
}); 
+0

你可以給我)的行動updatePostAction的overridded cartController(代碼。 –

+0

您不需要重寫cartController。只需將update_cart_action的值推送到您的ajax數據中即可: – Jouby

相關問題