Skip to content

Instantly share code, notes, and snippets.

@gitSambhal
Last active September 26, 2018 19:17
Show Gist options
  • Save gitSambhal/e3f6fd2c0e4e473bbb8c90a2c3a816aa to your computer and use it in GitHub Desktop.
Save gitSambhal/e3f6fd2c0e4e473bbb8c90a2c3a816aa to your computer and use it in GitHub Desktop.
jQuery(($) => {
//Set quantity to 0 by default on product category page
if (location.href.match(/product-category/)) {
$('.input-text.qty.text').val(0);
}
//Hide the quantity dropdown
$('.quantity-cat').hide();
//Event for value change of quantity and update the dropdown value
$('.input-text.qty').on("change paste keyup", function() {
oval = $(this).val();
newq = $(this).parents('.product').find('.quantity-cat').val(oval);
console.log(oval)
if (oval > 0) {
console.log('Add check ')
$(this).parents('.col-inner').find('.check')[0].checked = true;
} else {
console.log('remove check ')
$(this).parents('.col-inner').find('.check')[0].checked = false;
}
});
// Checkall button click to check all product to add to cart
$('.checkall').change((ex) => {
isChecked = ex.target.checked
console.log(isChecked);
// Only if the checkbox is checked
if (isChecked) {
// Now check all products quantity, if it is 0 then make it 1 otherwise leave it same
$('.plus').each((i, e) => {
var qty = parseInt($(e).parents('.product').find('.qty').val())
console.log(qty);
if (qty == 0) {
$(e)[0].click()
}
})
} else {
// Set all product's quantity to 0
$('.qty').val(0);
}
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment