2

When I use a bullet to increase qty then I use ajax to update cart. After call ajax how to update cart summary. I am stuck here please help me out from this.

also, I used

$("#cart-totals").trigger('contentUpdated');

line in response but its not working :( :(

2

2 Answers 2

8

Update cart summary in ajax response has been solved, we need to call getTotalsAction() javascript function as i mentioned below code :

demo.js

 define([
        'jquery',
        'Magento_Checkout/js/action/get-totals'
        ], function ($, getTotalsAction) {
        "use strict";

          $.ajax({
                method: "post",
                url: demoUrl, //your ajax Url
                data: {/*here post data*/},
                dataType: "html",
                success: function (resp) {
                   //below two lines refershing cart summary
                    var deferred = $.Deferred();
                    getTotalsAction([], deferred); //this function already created in Magento_Checkout/js/action/get-totals.js file
                }

            });

});
7
  • where i need to put this js? Jan 24, 2017 at 13:39
  • 6
    please enhance your answer or you deserve a down vote
    – LucScu
    Feb 2, 2017 at 10:44
  • Can you please write full code to update table and summary when change quantity from cat page?
    – Magecode
    Aug 29, 2017 at 11:04
  • @Lucky Awesome this is exactly what I needed to know! thanks. Mar 12, 2018 at 14:49
  • I try this solution but on console show TypeError: options is undefined error . please help to solve this error Feb 27, 2019 at 14:20
0

You can refresh the summary block, by simply triggering the Magento estimateTotals function, by using the following code:

require(
[
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/cart/totals-processor/default'
   ],

    function(
        quote,
        totalsDefaultProvider
    ) {
        totalsDefaultProvider.estimateTotals(quote.shippingAddress());
    }
);

References:

https://www.mexbs.com/magento-blog/magento2-triggering-totals-refresh-in-cart/

https://github.com/magento/magento2/blob/ac1e74c87bae0bf99f427f3279c4a90856142590/app/code/Magento/Checkout/view/frontend/web/js/model/cart/estimate-service.js#L55

1
  • This is not working
    – Dinesh
    Oct 30, 2020 at 9:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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