In Magento2 - We need to update main cart on change of quantity by Ajax without click on "Update Cart Button" and without reloading the page, Below my code in this code only update cart subtotal but not updated cart page summery sidebar subtotal.

 require(['jquery', 'Magento_Customer/js/customer-data',
    'jquery/jquery-storageapi'], function ($) {
    // $("#submitbutton").hide();
    var form = $('form#form-validate');
    var qtyfields = $('input.qty');
    $('.page.messages').each(function () {
        var thismessage = $(this);
        thismessage.attr('id', 'messages');

    form.find(qtyfields).each(function (e) {
        var thisfield = $(this);
        $(this).change(function () {
            console.log('change detected');

    $(document).on('submit','form#form-validate', function (e) {
        var thisfield = $(this);
        var thisiteminfo = thisfield.closest(".item-info");
        var thissubtotal = thisiteminfo.children(".subtotal");
        var formsubtotals = $(this).find('.subtotal');
            url: form.attr('action'),
            data: form.serialize(),
            type: 'post',
            success: function (res) {
                var parsedResponse = $.parseHTML(res);
                var result = $(parsedResponse).find("#form-validate");
                var totals = $(parsedResponse).find("#cart-totals");
            error: function () {
        console.log('form submitted');

Please help me for find best solution.

  • You can log parsedResponse? Nov 27, 2017 at 9:02
  • Yes, cart quantity updated correctly but cart subtotal and cat page summery section subtotal not updated. Nov 27, 2017 at 11:34
  • 1
    Did you find a solution?
    – Condor
    Mar 27, 2018 at 13:11

1 Answer 1


Have you tried deferred operation with getTotalsAction or totals-processor?

It's showing ajax process in your cart after calcul

you can use it like this (i minimize your code, just to show you how to use these functions.) :

require(["jquery", "Magento_Customer/js/customer-data","jquery/jquery-storageapi","Magento_Checkout/js/model/cart/totals-processor/default","Magento_Checkout/js/model/cart/cache","Magento_Checkout/js/model/quote","Magento_Checkout/js/action/get-totals"], function ($,defaultTotal,cartCache,quote,getTotalsAction) {
$(document).on("submit","form#form-validate", function (e) {
        url: form.attr("action"),
        data: form.serialize(),
        type: "post",
        success: function (res) {

    var deferred = $.Deferred();
    // this show ajax loader and reload price in cart
    getTotalsAction([], deferred);
    // this one too 
        error: function () {
    console.log("form submitted");

I suggest you to show this post for updating price in cart : How to add fee to order totals in Magento 2 and this one : https://github.com/sivajik34/Custom-Fee-Magento2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.