This function returns the wrong grand total. When I add items to the cart, it returns a much higher grand total than is actually there. How can I fix it?
You can see the app in action at cart-64d3f.firebaseapp.com
In the component:
- totals = [];
-
- get grandTotal() {
-
- let i;
- let sub_total = 0;
- let grand_total = 0;
- if (this.isSubmitted == true) {
- if (typeof this.product_price !== "undefined" && typeof this.quantity !== "undefined") {
- sub_total = this.product_price * this.quantity;
- this.totals.push(sub_total);
- }
- }
- for (i = 0; i < this.totals.length; i++) {
- grand_total += this.totals[i];
- }
- return grand_total;
- }
In the HTML:
- <td>{{grandTotal | currency:'USD':true }}</td>