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.
1 Answer
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);
}
});
});
});
});