add new handlebars helper cartTotalItems and pass session.cart to it from layouts/layout.hbs to show cart total items including quantities
parent
4f7eeb87c8
commit
9662d341c8
6
app.js
6
app.js
|
@ -210,6 +210,12 @@ handlebars = handlebars.create({
|
||||||
return options.fn(this);
|
return options.fn(this);
|
||||||
}
|
}
|
||||||
return options.inverse(this);
|
return options.inverse(this);
|
||||||
|
},
|
||||||
|
cartTotalItems: function(cart){
|
||||||
|
if(cart) {
|
||||||
|
return cart.reduce((a, b) => +a + +b.quantity, 0);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -107,7 +107,7 @@
|
||||||
{{#ifCond page '!=' 'checkout'}}
|
{{#ifCond page '!=' 'checkout'}}
|
||||||
{{#ifCond page '!=' 'pay'}}
|
{{#ifCond page '!=' 'pay'}}
|
||||||
{{#if session.cart}}
|
{{#if session.cart}}
|
||||||
<li><a href="/cart" class="menu-btn"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Cart <span class="badge" id="cart-count">{{objectLength session.cart}}</span></a></li>
|
<li><a href="/cart" class="menu-btn"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Cart <span class="badge" id="cart-count">{{cartTotalItems session.cart}}</span></a></li>
|
||||||
{{else}}
|
{{else}}
|
||||||
<li><a href="/cart" class="menu-btn"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Cart <span class="badge" id="cart-count">0</span></a></li>
|
<li><a href="/cart" class="menu-btn"><i class="fa fa-shopping-cart" aria-hidden="true"></i> Cart <span class="badge" id="cart-count">0</span></a></li>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
Loading…
Reference in New Issue