fix des prix promo et des images lors du delete dans le cart
This commit is contained in:
parent
5cbf9e4137
commit
a868cb73e6
@ -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;
|
||||
|
@ -28,9 +28,13 @@ const CartButton = () => {
|
||||
<ModalBody>
|
||||
{productsCount > 0 ?
|
||||
<>
|
||||
{cart.items.map((item) => <CartCard product={item}></CartCard>)}
|
||||
{cart.items.map(
|
||||
(item) =>
|
||||
(
|
||||
<CartCard key={item.id} product={item} />
|
||||
))}
|
||||
<div className="payer">
|
||||
<h className="total">Total: {cart.getTotalCost().toFixed(2)}$ CAD</h>
|
||||
<h className="total">Sous-total: {cart.getTotalCost().toFixed(2)}$ CAD</h>
|
||||
<Button className="payer">Payer</Button>
|
||||
</div>
|
||||
</>
|
||||
|
@ -25,7 +25,7 @@ export function CartCard({ product }) {
|
||||
<div className={!imageSrc ? "cat-load" : "d-none cat-load"} />
|
||||
<Card.Img className="item-img" variant="top" src={imageSrc} />
|
||||
<Card.Title>{product.title}</Card.Title>
|
||||
<Card.Text>{product.price}$ CA</Card.Text>
|
||||
<Card.Text>{product.status === 3 || product.status === 4 ? product.promoPrice : product.price}$ CA</Card.Text>
|
||||
<Form as={Row}>
|
||||
<Form.Label column="true" sm="6">Dans l'carosse: {productQuantity}</Form.Label>
|
||||
<Col sm="6">
|
||||
|
Loading…
Reference in New Issue
Block a user