-
Notifications
You must be signed in to change notification settings - Fork 0
/
cart.html
135 lines (98 loc) · 4.31 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!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">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link
href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css"
integrity="sha384-Bfad6CLCknfcloXFOyFnlgtENryhrpZCe29RTifKEixXQZ38WheV+i/6YWSzkz3V" crossorigin="anonymous" />
<title>Document</title>
<link rel="stylesheet" href="styles/normalize.css">
<link rel="stylesheet" href="styles/navbar.css">
<link rel="stylesheet" href="styles/footer.css">
<link rel="stylesheet" href="styles/cart.css">
</head>
<body>
<div id="navbar"></div>
<div class="total-price-box">
<h3 class="total-price"></h3>
</div>
<div id="product-container">
</div>
<div class="checkout-box">
<a href="checkout.html"> <button class="checkout-btn"> Proceed Checkout</button> </a>
</div>
<div id="footer"></div>
</body>
</html>
<script type="module">
import categories from "./categories.js"
import { navbar, createDropdown, updateCart,checkLogStatus } from "./components/navbar.js"
import footer from "./components/footer.js"
document.getElementById("navbar").innerHTML = navbar()
createDropdown(categories)
document.getElementById("footer").innerHTML = footer()
let cartProducts = JSON.parse(localStorage.getItem("cartProducts")) ?? [];
let product_container = document.getElementById("product-container");
showproduct()
updateCart("cartpage")
checkLogStatus()
function showproduct() {
let data = JSON.parse(localStorage.getItem("cartProducts")) ?? [];
// to show only HL and LH data
let parent = document.getElementById("product-container")
parent.innerHTML = null;
if (data.length == 0) {
let img = document.createElement("img")
img.src = "./assets/empty.png"
parent.append(img)
}
else {
data.forEach(function (product,index) {
console.log(product.price)
let div = document.createElement("div");
div.setAttribute("class", "product-box")
let img = document.createElement("img")
img.setAttribute("class", "product-img")
img.src = product.img;
let money_div = document.createElement("div")
money_div.setAttribute("class", "product-price-box")
let product_price = document.createElement("p");
product_price.textContent = `Price ${product.price??product.mrp}`
let discount = document.createElement("p")
discount.innerText = `${product.discount??0}`;
money_div.append(product_price, discount)
let product_name = document.createElement("p")
product_name.textContent = product.name ?? product.title;
let addtoCart_btn = document.createElement("button")
addtoCart_btn.setAttribute("class", "add-to-cart-btn")
addtoCart_btn.innerText = "Remove"
addtoCart_btn.onclick = function () {
updateCart("remove",showproduct,product,index)
}
div.append(img, money_div, product_name, addtoCart_btn);
parent.append(div)
})
}
}
document.getElementById("logInBtn").addEventListener("click",()=>{
let logInBtn = document.getElementById("logInBtn")
if(logInBtn.innerText=="Log Out") {
localStorage.setItem("userData",JSON.stringify({}))
window.location.reload();
} else{
window.location.href = "signin.html"
checkLogStatus()
}
})
document.getElementById("createUser").addEventListener("click",()=>{
let createUserBtn = document.getElementById("createUser");
if(createUserBtn.innerText=="Create Account") {
window.location.href = "signup.html"
}
})
</script>