-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveProdFromCart.js
28 lines (22 loc) · 963 Bytes
/
removeProdFromCart.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { getCartProductFromLS } from "./getCartProducts";
import { showToast } from "./showToast";
import { updateCartProductTotal } from "./updateCartProductTotal";
import { updateCartValue } from "./updateCartValue";
export const removeProdFromCart = (id) => {
let cartProducts = getCartProductFromLS();
cartProducts = cartProducts.filter((curProd) => curProd.id !== id);
// update the localStorage after removing the item
localStorage.setItem("cartProductLS", JSON.stringify(cartProducts));
// to remove the div onclick
let removeDiv = document.getElementById(`card${id}`);
if (removeDiv) {
removeDiv.remove();
//show toast when product added to the cart
showToast("delete", id);
}
// -----------------------------------------------------
// calculating the card total in our cartProducts page
// --------------------------------------------------------
updateCartProductTotal();
updateCartValue(cartProducts);
};