fix des prix promo et des images lors du delete dans le cart
This commit is contained in:
parent
5cbf9e4137
commit
a868cb73e6
@ -14,7 +14,7 @@ export const CartContext = createContext({
|
|||||||
|
|
||||||
export function CartProvider({ children }) {
|
export function CartProvider({ children }) {
|
||||||
|
|
||||||
const [cartCookie,setCartCookie] = useCookies(['cart'])
|
const [cartCookie, setCartCookie] = useCookies(['cart'])
|
||||||
const [cartProducts, setCartProducts] = useState([]);
|
const [cartProducts, setCartProducts] = useState([]);
|
||||||
|
|
||||||
function addToCart(product, qty) {
|
function addToCart(product, qty) {
|
||||||
@ -72,16 +72,14 @@ export function CartProvider({ children }) {
|
|||||||
|
|
||||||
function deleteFromCart(id) {
|
function deleteFromCart(id) {
|
||||||
setCartProducts(
|
setCartProducts(
|
||||||
cartProducts => cartProducts.filter(currentProduct => {
|
cartProducts => cartProducts.filter((currentProduct) => currentProduct.id !== id)
|
||||||
return currentProduct.id != id;
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
function getTotalCost() {
|
function getTotalCost() {
|
||||||
let totalCost = 0;
|
let totalCost = 0;
|
||||||
cartProducts.map((cartItem) => {
|
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;
|
return totalCost;
|
||||||
|
@ -28,9 +28,13 @@ const CartButton = () => {
|
|||||||
<ModalBody>
|
<ModalBody>
|
||||||
{productsCount > 0 ?
|
{productsCount > 0 ?
|
||||||
<>
|
<>
|
||||||
{cart.items.map((item) => <CartCard product={item}></CartCard>)}
|
{cart.items.map(
|
||||||
|
(item) =>
|
||||||
|
(
|
||||||
|
<CartCard key={item.id} product={item} />
|
||||||
|
))}
|
||||||
<div className="payer">
|
<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>
|
<Button className="payer">Payer</Button>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
|
@ -25,7 +25,7 @@ export function CartCard({ product }) {
|
|||||||
<div className={!imageSrc ? "cat-load" : "d-none cat-load"} />
|
<div className={!imageSrc ? "cat-load" : "d-none cat-load"} />
|
||||||
<Card.Img className="item-img" variant="top" src={imageSrc} />
|
<Card.Img className="item-img" variant="top" src={imageSrc} />
|
||||||
<Card.Title>{product.title}</Card.Title>
|
<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 as={Row}>
|
||||||
<Form.Label column="true" sm="6">Dans l'carosse: {productQuantity}</Form.Label>
|
<Form.Label column="true" sm="6">Dans l'carosse: {productQuantity}</Form.Label>
|
||||||
<Col sm="6">
|
<Col sm="6">
|
||||||
|
Loading…
Reference in New Issue
Block a user