How can I decrease item quantity in popup cart using ajax?

Hi all,

I own a Shopify store that uses a popup cart before checkout. I am using the following code on the popup cart, in order to enable customers to increase or decrease the quantity of items in the cart:


  
  
  

As you might see I am using the Shopify.addItem() function when onclick is triggered in order to increase the amount of items per product in the cart.

Sadly I did not find any function to decrease the quantity so far… How can I realize the onclick to reduce the quantity? Or do I need some Jquery or so?

Thanks for helping out!

Hi,

Yes, you need to add some customer javascript functionality to do that.

PM me if you need help.

Hi so I already tried multiple commands, but I did not reach a success… This is the best I have. Probably there is a jQuery mistake…

$('.input-group').on('click', '.button-minus', function(e) {
    e.preventDefault();
    var fieldName = $(e.target).data('field');
    var parent = $(e.target).closest('div');
    var currentVariant = parseInt(parent.find('input[name=' + fieldName + ']').attr('id'), 10);
    jQuery.post('/cart/change.js', { quantity: currentVal - 1, id: currentVariant });
    
  });

I forgot the actual value line in the last post. But nothing changed. So it does not work

$('.input-group').on('click', '.button-minus', function(e) {
    e.preventDefault();
    var fieldName = $(e.target).data('field');
    var parent = $(e.target).closest('div');
    var currentVal = parseInt(parent.find('input[name=' + fieldName + ']').val(), 10);
    var currentVariant = parseInt(parent.find('input[name=' + fieldName + ']').attr('id'), 10);
    jQuery.post('/cart/change.js', { quantity: currentVal - 1, id: currentVariant });
    
  });