0

Issue:-

Is there a ready solution to update shopping cart page by ajax url/checkout/cart/?

I found similar questions but there is no working solution, but as for me, it's very useful feature and should be some implementation.

I not ready to provide a code, trying to implement this solution for my needs https://magento.stackexchange.com/questions/187226/ajax-cart-validation-on-change-qty?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

1 Answer 1

1

i did this with such JS, if need ready solution ping me. not pretty cool, but was need to save compatibility with non default themes

define([
    'jquery',
    'Magento_Checkout/js/action/get-totals',
    'Magento_Customer/js/customer-data'
], function ($, getTotalsAction, customerData) {

    $(document).ready(function(){
        $(document).on('change', 'input[name$="[qty]"]', function(){
            var form = $('form#form-validate');
            $.ajax({
                url: form.attr('action'),
                data: form.serialize(),
                showLoader: true,
                success: function (res) {
                    var parsedResponse = $.parseHTML(res);
                    var result = $(parsedResponse).find("#form-validate");
                    var sections = ['cart'];

                    $("#form-validate").replaceWith(result);

                    // The mini cart reloading
                    customerData.reload(sections, true);

                    // The totals summary block reloading
                    var deferred = $.Deferred();
                    getTotalsAction([], deferred);
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });
        });
    });
});
3
  • Hello Maxim R. Please elaborate the answer. We are trying to achieve this.
    – Raghav
    Commented Aug 30, 2018 at 8:41
  • While doing this change, summary action is not updating properly. Commented Apr 29, 2020 at 15:15
  • i have added this for ajax qty update but i am trying to get subtotal customerData.get('cart')._latestValue.subtotalAmount is is gving me old subtotal , How to get updated total here Commented Aug 11, 2020 at 10:24

Your Answer

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

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