May 2018
Intermediate to advanced
470 pages
13h 54m
English
At the bottom of the CartItems component, we will display the total price of the items in the cart.
mern-marketplace/client/cart/CartItems.js:
<span className={classes.total}>Total: ${this.getTotal()}</span>
The getTotal method will calculate the total price taking into consideration the unit price and quantity of each item in the cartItems array.
mern-marketplace/client/cart/CartItems.js:
getTotal(){ return this.state.cartItems.reduce( function(a, b){ return a + (b.quantity*b.product.price) }, 0)}
Read now
Unlock full access