-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremoveProdFromCart.js
34 lines (27 loc) · 1.13 KB
/
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
29
30
31
32
33
34
/*!
* © 2024 Arnab Paul. All rights reserved.
* This file is part of Mega Tech Arn_x.b.
* Licensed under the MIT License. See LICENSE file in the project root for full license information.
*/
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);
};