1

I want to update the cart page when the quantity goes below 1, it works fine if the quantity is above 1, but it does not change the cart if the quantity is below zero as shown in the picture below, any idea, thanks. enter image description here

1 Answer 1

0

I've used this script and it solves the problem, but it takes more time while loading

<script>
require ([
    '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");

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

                    // The mini cart reloading
                    var sections = ['cart'];
                    customerData.invalidate(sections);
                    customerData.reload(sections, true);

                    //The totals summary block reloading
                    var deferred = $.Deferred();
                    getTotalsAction([], deferred);
                    location.reload();
                },
                error: function (xhr, status, error) {
                    var err = eval("(" + xhr.responseText + ")");
                    console.log(err.Message);
                }
            });

        });
    });
});

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.