I'm playing around with showing the customer how many items they have in their cart. I've followed the unofficial mini-cart hack:
<script type="text/javascript">
var EJConfig = {}
EJConfig.onload = cartLoaded
function cartLoaded(x){
if(typeof x !== "undefined"){
if(x.Cart.Items)
document.querySelectorAll(".EJ-CartItemsNum").forEach(function(y){ y.innerHTML = x.Cart.Items.length; })
else
document.querySelectorAll(".EJ-CartItemsNum").forEach(function(y){ y.innerHTML = "0"; })
}
}
window.onload = function(){
EJCart.getCartJSON("12345678", cartLoaded)
}
</script>
The issue I'm having is that it's only calculating the number of individual products in my cart, not the total quantity of products in my cart.
Example:
Product A with 2 qty
Product B with 3 qty
It's currently showing I have 2 items in my cart instead of 5.
<b class="EJ-CartItemsNum">2</b>
Any insight would be appreciated.
Thanks.