forked from vishal-girhepunje/Nordstrom-Clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew_arrivals_products.js
295 lines (239 loc) · 11.3 KB
/
new_arrivals_products.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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
let url = "https://long-plum-chicken-fez.cyclic.app/api/all"
let stack = []
let no_ofitems=localStorage.getItem("itemsno") || 0
let bag =JSON.parse(localStorage.getItem("bag"))||[]
fetch(url)
.then((res) => res.json())
.then((data) => {
stack = data;
displayProducts(data)
})
furniture = () => {
let url = "https://long-plum-chicken-fez.cyclic.app/api/furniture/"
fetch(url)
.then((res) => res.json())
.then((data) => {
stack = data;
displayProducts(data)
})
document.querySelector("#all_new>span:nth-child(4)").style.borderBottom = "5px solid black";
document.querySelector("#all_new>span:nth-child(1)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(2)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(3)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(5)").style.borderBottom = "none";
}
women = () => {
let url = "https://long-plum-chicken-fez.cyclic.app/api/women/"
fetch(url)
.then((res) => res.json())
.then((data) => {
stack = data;
displayProducts(data)
})
document.querySelector("#all_new>span:nth-child(3)").style.borderBottom = "5px solid black";
document.querySelector("#all_new>span:nth-child(1)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(2)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(4)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(5)").style.borderBottom = "none";
}
men = () => {
let url = "https://long-plum-chicken-fez.cyclic.app/api/men/"
fetch(url)
.then((res) => res.json())
.then((data) => {
stack = data;
displayProducts(data)
})
document.querySelector("#all_new>span:nth-child(1)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(5)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(3)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(4)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(2)").style.borderBottom = "5px solid black";
}
kid = () => {
let url = "https://long-plum-chicken-fez.cyclic.app/api/kid/"
fetch(url)
.then((res) => res.json())
.then((data) => {
stack = data;
displayProducts(data)
})
document.querySelector("#all_new>span:nth-child(1)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(2)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(3)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(4)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(5)").style.borderBottom = "5px solid black";
}
all_products = () => {
let url = "https://long-plum-chicken-fez.cyclic.app/api/all"
fetch(url)
.then((res) => res.json())
.then((data) => {
stack = data;
displayProducts(data)
});
document.querySelector("#all_new>span:nth-child(5)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(2)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(3)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(4)").style.borderBottom = "none";
document.querySelector("#all_new>span:nth-child(1)").style.borderBottom = "5px solid black";
}
displayProducts = (data) => {
let x = data.length;
document.querySelector("#all_products").innerHTML = "";
data.forEach(element => {
if (element.prod_img != undefined && element.pro_brand != undefined && element.curr_price != undefined && element.product_name != undefined)
{
let div = document.createElement("div");
let img = document.createElement("img")
img.setAttribute("src", element.prod_img)
let brand = document.createElement("h2")
brand.innerText= element.pro_brand
let string = document.createElement("p")
string.innerText= "Arrives Before Christmas"
string.setAttribute("id", "string")
let strong = document.createElement("strong")
let price = document.createElement("p")
price.innerText ="Current Price "+ element.curr_price;
price.style.color = "red";
strong.append(price)
let currentprice = document.createElement("p")
currentprice.setAttribute("id","price")
currentprice.innerText ="INR "+element.pro_price
let description = document.createElement("p")
description.setAttribute("id","desc")
description.innerText = element.product_name;
let button = document.createElement("button")
let icon = document.createElement("i")
icon.setAttribute("class", "fa-solid fa-bag-shopping")
button.innerText = "Add To Bag "
button.addEventListener("click", () => {
bag.push(element);
localStorage.setItem("bag", JSON.stringify(bag));
no_ofitems++
localStorage.setItem("itemsno",no_ofitems)
document.querySelector("#numOfItemInCart span").innerText=no_ofitems
alert("Item Added to Cart")
})
button.append(icon)
div.append(img,string, brand,description, currentprice,strong, button)
document.querySelector("#all_products").append(div)
}
});
document.querySelector("#loading_").innerText = x + " items";
}
// 88888888*******************************Sort Functionality**********************************
sortFunctionality = () => {
let selected = document.querySelector("select").value
if (selected == "low_to_high") {
stack.map((element) => {
element.pro_price = Math.floor(Math.random() * (8000 - 800) + 800)
element.curr_price = element.pro_price
return element
})
stack.sort((a, b) => {return a.pro_price - b.pro_price});
displayProducts(stack)
}
else if (selected == "high_to_low") {
stack.map((element) => {
element.pro_price = Math.floor(Math.random() * (8000 - 800) + 800)
element.curr_price = element.pro_price
return element
})
stack.sort((a, b) => {return b.pro_price - a.pro_price});
displayProducts(stack)
}
}
// 88888888888888888888888888888888888888888888888888888
//************************Moved Everything from new arrival.js**************************** */
let sount = 0;
let size = document.getElementById("size_size")
size.addEventListener("click", () => {
if (sount % 2 == 1) {
document.querySelector("#size").innerHTML = ""
sount++
}
else {
let menshoes = document.createElement("div")
menshoes.setAttribute("class", "empty")
let h3_men_shoes = document.createElement("h3")
h3_men_shoes.innerText = "vuori"
menshoes.append(h3_men_shoes)
menshoes.addEventListener("click", () => {
let x = stack.filter((element) => element.pro_brand == "vuori")
displayProducts(x)
})
let mensclothing = document.createElement("div")
mensclothing.setAttribute("class", "empty")
let h3_mens_clothing = document.createElement("h3")
h3_mens_clothing.innerText = "Zella"
mensclothing.append(h3_mens_clothing);
mensclothing.addEventListener("click", () => {
let x = stack.filter((element) => element.pro_brand == "Zella")
displayProducts(x)
})
let mens_dress_shirt = document.createElement("div")
mens_dress_shirt.setAttribute("class", "empty")
let h3_mens_dress_shirt = document.createElement("h3")
h3_mens_dress_shirt.innerText = "Zella Girl"
mens_dress_shirt.append(h3_mens_dress_shirt)
mens_dress_shirt.addEventListener("click", () => {
let x = stack.filter((element) => element.pro_brand == "Zella Girl")
displayProducts(x)
})
let menspants = document.createElement("div")
menspants.setAttribute("class", "empty")
let h3_mens_pants = document.createElement("h3")
h3_mens_pants.innerText = "Stokke"
menspants.append(h3_mens_pants)
menspants.addEventListener("click", () => {
let x = stack.filter((element) => element.pro_brand == "Stokke")
displayProducts(x)
})
let menssuits = document.createElement("div")
menssuits.setAttribute("class", "empty")
let h3_mens_suits = document.createElement("h3")
h3_mens_suits.innerText = "Nordstrom"
menssuits.append(h3_mens_suits)
menssuits.addEventListener("click", () => {
let x = stack.filter((element) => element.pro_brand == "Nordstrom")
displayProducts(x)
})
document.querySelector("#size").append(menshoes, mensclothing,mens_dress_shirt,menspants,menssuits)
sount++
}
});
// let color = document.querySelector("#color")
// color.addEventListener("click", () => {
// console.log("clicked")
// })
// let brand = document.querySelector("#brand")
// brand.addEventListener("click", () => {
// console.log("clicked")
// })
// let material = document.querySelector("#material")
// material.addEventListener("click", () => {
// console.log("clicked")
// })
// let occassion = document.querySelector("#occassion")
// occassion.addEventListener("click", () => {
// console.log("clicked")
// })
// let price = document.querySelector("#price_")
// price.addEventListener("click", () => {
// console.log("clicked")
// })
// let sale = document.querySelector("#sale")
// sale.addEventListener("click", () => {
// console.log("clicked")
// })
// let style = document.querySelector("#style")
// style.addEventListener("click", () => {
// console.log("clicked")
// })
// 88888888888888************SEARCH FUNCTIONALITY**************************
function searchall() {
let x = document.querySelector("input").value;
let filtered = stack.filter((element) => element.product_name!=undefined && element.product_name.toLowerCase().includes(x.toLowerCase())|| element.pro_brand!=undefined && element.pro_brand.toLowerCase().includes(x.toLowerCase())|| element.pro_price!=undefined && element.pro_price.toString().includes(x) || element.pro_color!=undefined && element.pro_color.toLowerCase().includes(x.toLowerCase()) || element.pro_material!=undefined && element.pro_material.toLowerCase().includes(x.toLowerCase()) || element.pro_occassion!=undefined && element.pro_occassion.toLowerCase().includes(x.toLowerCase()) || element.pro_style!=undefined && element.pro_style.toLowerCase().includes(x.toLowerCase()) || element.pro_size!=undefined && element.pro_size.toLowerCase().includes(x.toLowerCase()) );
displayProducts(filtered)
};