monishrafi wrote:Hi,
Please any body help on this as we need to add increment decrement button inline with quantity box so that user can change quantity through mouse click
we are using motion responsive theme and nop ajax cart
Here is a script you can use for that, but you have to initialize it (and style the new elements) on your own, since this is not a part of the theme:
function incrementQuantityValue(event) {
event.preventDefault();
event.stopPropagation();
var input = $(this).siblings('.qty-input');
var value = parseInt(input.val());
if (isNaN(value)) {
input.val(1);
return;
}
value++;
input.val(value);
input.trigger('input');
}
function decrementQuantityValue(event) {
event.preventDefault();
event.stopPropagation();
var input = $(this).siblings('.qty-input');
var value = parseInt(input.val());
if (isNaN(value)) {
input.val(1);
return;
}
if (value <= 1) {
return;
}
value--;
input.val(value);
input.trigger('input');
}
function handlePurchaseQuantityValue() {
$(document).on('click', '.add-to-cart .increase, .cart .increase', incrementQuantityValue);
$(document).on('click', '.add-to-cart .decrease, .cart .decrease', decrementQuantityValue);
}
You have to add 2 new elements (e.g. <span>) around your quantity input text box in all possible scenarios (product templates, shopping cart table, plugins...) and use the class names "increase" and "decrease" to get them targeted by the above script. When ready, initialize the handlePurchaseQuantityValue() function and test.
Regards