From a868cb73e65da99b7a6b480822a696f331664611 Mon Sep 17 00:00:00 2001 From: Victor Turgeon <76506447+Medenos@users.noreply.github.com> Date: Tue, 8 Nov 2022 01:16:33 -0500 Subject: [PATCH] fix des prix promo et des images lors du delete dans le cart --- .../grosses-mitaines-ui/src/components/Cart.js | 8 +++----- .../grosses-mitaines-ui/src/components/CartButton.js | 8 ++++++-- .../grosses-mitaines-ui/src/components/CartCard.js | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/Cart.js b/GrossesMitaines/grosses-mitaines-ui/src/components/Cart.js index 7e8e452..d4bde38 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/Cart.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/Cart.js @@ -14,7 +14,7 @@ export const CartContext = createContext({ export function CartProvider({ children }) { - const [cartCookie,setCartCookie] = useCookies(['cart']) + const [cartCookie, setCartCookie] = useCookies(['cart']) const [cartProducts, setCartProducts] = useState([]); function addToCart(product, qty) { @@ -72,16 +72,14 @@ export function CartProvider({ children }) { function deleteFromCart(id) { setCartProducts( - cartProducts => cartProducts.filter(currentProduct => { - return currentProduct.id != id; - }) + cartProducts => cartProducts.filter((currentProduct) => currentProduct.id !== id) ); }; function getTotalCost() { let totalCost = 0; cartProducts.map((cartItem) => { - totalCost += (parseFloat(cartItem.price) * parseFloat(cartItem.quantity)); + totalCost += (parseFloat(cartItem.status == 3 || cartItem.status == 4 ? cartItem.promoPrice : cartItem.price) * parseFloat(cartItem.quantity)); }); return totalCost; diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js b/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js index 946ded2..b2ea287 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/CartButton.js @@ -28,9 +28,13 @@ const CartButton = () => { {productsCount > 0 ? <> - {cart.items.map((item) => )} + {cart.items.map( + (item) => + ( + + ))}
- Total: {cart.getTotalCost().toFixed(2)}$ CAD + Sous-total: {cart.getTotalCost().toFixed(2)}$ CAD
diff --git a/GrossesMitaines/grosses-mitaines-ui/src/components/CartCard.js b/GrossesMitaines/grosses-mitaines-ui/src/components/CartCard.js index b5639f1..bf5dec8 100644 --- a/GrossesMitaines/grosses-mitaines-ui/src/components/CartCard.js +++ b/GrossesMitaines/grosses-mitaines-ui/src/components/CartCard.js @@ -25,7 +25,7 @@ export function CartCard({ product }) {
{product.title} - {product.price}$ CA + {product.status === 3 || product.status === 4 ? product.promoPrice : product.price}$ CA
Dans l'carosse: {productQuantity}