I am writing some code to grab product id's and quantities before adding to my cart. I am looping through each product where the quantity is greater than 0, and then getting some information stored in the data attributes.
The issue i am having is outputting all of the data. here is my code:
jQuery( ".productList .catQuantity" ).each(function( index ) {
var productID = jQuery(this).attr('data-product_id');
var productQu = jQuery(this).attr('data-quantity');
if(productQu > 0){
//console.log(productID+':'+productQu+',');
window.allProducts = (productID+':'+productQu+',');
}
});
console.log(allProducts);
So the above grabs the product id and quantity and stores it in a global variable. When i console.log the variable, only the last product added is included in the variable.
Any ideas why this is?