April 2020
Intermediate to advanced
716 pages
18h 55m
English
At the bottom of the CartItems component, we will display the total price of the items in the cart. It will be rendered with the following code.
mern-marketplace/client/cart/CartItems.js:
<span className={classes.total}>Total: ${getTotal()}</span>
The getTotal method will calculate the total price while taking the unit price and quantity of each item in the cartItems array into consideration. This method is defined as follows.
mern-marketplace/client/cart/CartItems.js:
const getTotal = () => { return cartItems.reduce((a, b) => { return a + (b.quantity*b.product.price) }, 0)}
With this, the users will have an overview of what they are buying and how much it will cost before they are ready to check out and place the ...
Read now
Unlock full access