-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.html
199 lines (153 loc) · 5.25 KB
/
product.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!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>Document</title>
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.13.0/css/all.css"
integrity="sha384-Bfad6CLCknfcloXFOyFnlgtENryhrpZCe29RTifKEixXQZ38WheV+i/6YWSzkz3V"
crossorigin="anonymous"
/>
<link rel="stylesheet" href="styles/navbar.css">
<link rel="stylesheet" href="styles/footer.css">
<link rel="stylesheet" href="styles/product.css">
<link rel="stylesheet" href="styles/normalize.css">
<style>
</style>
</head>
<body>
<div id="navbar">
</div>
<div class="product-page-container">
<div class="filter-sidebar">
<div class="category-menu-box">
<h3 class="category-menu-title">
Category Menu
</h3>
<div class="category-menu">
</div>
</div>
</div>
<div class="main-area-box">
<div class="product-sorting-nav">
<div class="sorting-container">
<div class="show-as-container">
<h3 class="show-as-title">SHOW AS</h3>
<div class="choose-grid">
<div>3</div>
<div>4</div>
</div>
</div>
<select name="" id="sorting" >
<option value="sortby">Sort By</option>
<option value="lowtohigh">Low To High</option>
<option value="hightolow">High To Low</option>
<option value="discount">Discount</option>
</select>
</div>
</div>
<div id="product-container">
</div>
</div>
</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)
updateCart()
checkLogStatus()
document.getElementById("footer").innerHTML = footer()
let productLocalArr = JSON.parse(localStorage.getItem("productLocalArr")) ?? []
let product_container = document.getElementById("product-container");
showproduct(productLocalArr,product_container)
function showproduct(data,parent) {
// to show only HL and LH data
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) {
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}`;
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 = "Add To Cart"
addtoCart_btn.onclick = function () {
updateCart("add",null,product)
}
div.append(img, money_div, product_name, addtoCart_btn);
parent.append(div)
})
}
}
document.getElementById("sorting").addEventListener("click",()=>{
let value = document.getElementById("sorting").value;
if(value=="lowtohigh") {
lowToHigh()
}
if(value == "hightolow"){
highToLow()
}
if(value=="discount") {
discountSort()
}
})
function highToLow() {
productLocalArr = productLocalArr.sort(function (a, b) {
return (b.price ?? b.mrp) - (a.price ?? a.mrp)
})
showproduct(productLocalArr,product_container)
}
function discountSort() {
productLocalArr = productLocalArr.sort(function (a, b) {
return parseInt(b.discount) - parseInt(a.discount)
})
showproduct(productLocalArr,product_container)
}
function lowToHigh() {
productLocalArr = productLocalArr.sort(function (a, b) {
return (a.price ?? a.mrp) - (b.price ?? b.mrp)
})
showproduct(productLocalArr,product_container)
}
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>