diff --git a/ecom-frontend/src/components/cart/Cart.jsx b/ecom-frontend/src/components/cart/Cart.jsx index 4c93130..61d8fc9 100644 --- a/ecom-frontend/src/components/cart/Cart.jsx +++ b/ecom-frontend/src/components/cart/Cart.jsx @@ -4,12 +4,18 @@ import { Link } from "react-router-dom"; import ItemContent from "./ItemContent"; import CartEmpty from "./CartEmpty"; import { formatPrice } from "../../utils/formatPrice"; +import { fetchProducts } from "../../store/actions/index.js"; +import { useEffect } from "react"; const Cart = () => { const dispatch = useDispatch(); const { cart } = useSelector((state) => state.carts); const newCart = { ...cart }; + useEffect(() => { + dispatch(fetchProducts()) + }, []); + newCart.totalPrice = cart?.reduce( (acc, cur) => acc + Number(cur?.specialPrice) * Number(cur?.quantity), 0 ); @@ -80,4 +86,4 @@ const Cart = () => { ); }; -export default Cart; \ No newline at end of file +export default Cart;