1

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 :( :(

4

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
                }

            });

});

don't forget to vote up this anwer.

  • where i need to put this js? – Alin Lupoiu Jan 24 '17 at 13:39
  • 4
    please enhance your answer or you deserve a down vote – LucScu Feb 2 '17 at 10:44
  • Can you please write full code to update table and summary when change quantity from cat page? – Magecode Aug 29 '17 at 11:04
  • @Lucky Awesome this is exactly what I needed to know! thanks. – Juliano Vargas Mar 12 '18 at 14:49
  • I try this solution but on console show TypeError: options is undefined error . please help to solve this error – Chirag Gondaliya Feb 27 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

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.