fix des prix promo et des images lors du delete dans le cart
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user