-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCart.html
80 lines (69 loc) · 2.34 KB
/
Cart.html
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Special Offer On Skin Care |Rodan + Field</title>
<link rel="stylesheet" href="css/cart.css" />
<script
src="https://kit.fontawesome.com/24c494a6b6.js"
crossorigin="anonymous"
></script>
</head>
<body>
<div id="overviewcart">
<div id="cartHead">
<span><i class="fa-solid fa-bag-shopping"></i></span>
<span>Your Bag</span>
<span> <i class="fa-solid fa-xmark" id="cross"></i></span>
</div>
<hr />
<div id="cartItem"></div>
<p id="info" class="inf">
Savings, shipping costs and tax calculated at checkout
</p>
<div id="cartBottom">
<div id="total">
<span>SUBTOTAL</span>
<span id="amt"></span>
</div>
<button id="check">REVIEW BAG & CHECKOUT</button>
</div>
</div>
</body>
</html>
<script>
var cartData = JSON.parse(localStorage.getItem("cart"));
console.log(cartData);
var total = cartData.reduce(function (sum, elem, index, arr) {
return sum+=Number(elem.price.slice(1));
},0)
document.querySelector("#amt").innerHTML = '$'+total;
localStorage.setItem("cartTotalVal", JSON.stringify(total));
cartData.map(function (elem, index) {
var box = document.createElement("div");
box.setAttribute("id", "cartdiv");
var img = document.createElement("img");
img.src = elem.image;
img.setAttribute("id", "cartImg");
var name = document.createElement("p");
name.textContent = elem.name;
name.setAttribute("id", "cartName");
var price = document.createElement("p");
price.innerText = elem.price;
price.setAttribute("id", "cartprice");
var h = document.createElement("hr");
box.append(img, name, price);
document.querySelector("#cartItem").append(box);
});
document.querySelector("#cross").addEventListener("click", cancleFunction);
function cancleFunction(){
document.querySelector("#overviewcart").innerHTML = "";
window.location.href="index.html";
}
document.querySelector("#check").addEventListener("click", checkFunction);
function checkFunction(){
window.location.href="PaymentPage.html";
}
</script>