-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproduct.js
More file actions
629 lines (542 loc) · 15.5 KB
/
product.js
File metadata and controls
629 lines (542 loc) · 15.5 KB
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
console.log("test");
var arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
console.log(arrofobj);
//Filtering Function
//High to low
document.querySelector("#high").addEventListener("change", hightolowfunction);
function hightolowfunction() {
if (this.checked) {
arrofobj.sort(function (a, b) {
return b.price - a.price;
});
displayUi(arrofobj);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//low to high
document.querySelector("#low").addEventListener("change", lowtohighfunction);
function lowtohighfunction() {
if (this.checked) {
arrofobj.sort(function (a, b) {
return a.price - b.price;
});
displayUi(arrofobj);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
displayUi(arrofobj);
//All Products
document.querySelector("#all").addEventListener("change", allprioductfun);
function allprioductfun() {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
console.log("Test");
}
//Price bello 499
document.querySelector("#below499").addEventListener("change", below499fun);
function below499fun() {
if (this.checked) {
var storearr1 = arrofobj.filter(function (el) {
if (el.price <= 499) {
return el;
}
});
storearr1.sort(function (a, b) {
return a.price - b.price;
});
displayUi(storearr1);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Price between 500 to 999
document.querySelector("#p500to999").addEventListener("change", below999fun);
function below999fun() {
if (this.checked) {
var storearr2 = arrofobj.filter(function (el) {
if (el.price >= 500 && el.price <= 999) {
return el;
}
});
storearr2.sort(function (a, b) {
return a.price - b.price;
});
displayUi(storearr2);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Price between 1000 and 1999
document.querySelector("#p1000to1999").addEventListener("change", below1999fun);
function below1999fun() {
if (this.checked) {
var storearr3 = arrofobj.filter(function (el) {
if (el.price >= 1000 && el.price <= 1999) {
return el;
}
});
storearr3.sort(function (a, b) {
return a.price - b.price;
});
displayUi(storearr3);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Price above 2000
document.querySelector("#p2000").addEventListener("change", above2000fun);
function above2000fun() {
if (this.checked) {
var storearr4 = arrofobj.filter(function (el) {
if (el.price >= 2000) {
return el;
}
});
storearr4.sort(function (a, b) {
return a.price - b.price;
});
displayUi(storearr4);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Discount upto 20%
document.querySelector("#upto20").addEventListener("change", disupto20);
function disupto20() {
if (this.checked) {
var storearrdis1 = arrofobj.filter(function (el) {
if (el.discount <= 20) {
return el;
}
});
storearrdis1.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrdis1);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Discount upto 50%
document.querySelector("#upto50").addEventListener("change", disupto50);
function disupto50() {
if (this.checked) {
var storearrdis2 = arrofobj.filter(function (el) {
if (el.discount > 20 && el.discount <= 50) {
return el;
}
});
storearrdis2.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrdis2);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Discount upto 70
document.querySelector("#upto70").addEventListener("change", disupto70);
function disupto70() {
if (this.checked) {
var storearrdis3 = arrofobj.filter(function (el) {
if (el.discount > 50 && el.discount <= 70) {
return el;
}
});
storearrdis3.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrdis3);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Discount more than 70
document.querySelector("#more70").addEventListener("change", dismore70);
function dismore70() {
if (this.checked) {
var storearrdis4 = arrofobj.filter(function (el) {
if (el.discount > 70) {
return el;
}
});
storearrdis4.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrdis4);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Filter based on brand HRX
document.querySelector("#hrx").addEventListener("change", hrxfun);
function hrxfun() {
if (this.checked) {
var storearrbrand1 = arrofobj.filter(function (el) {
if (el.brand == "HRX") {
return el;
}
});
storearrbrand1.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrbrand1);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Filter based on brand WROGN
document.querySelector("#wrogn").addEventListener("change", wrognfun);
function wrognfun() {
if (this.checked) {
var storearrbrand2 = arrofobj.filter(function (el) {
if (el.brand == "WROGN") {
return el;
}
});
storearrbrand2.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrbrand2);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Filter Moda Rapido
//modarapido
document.querySelector("#modarapido").addEventListener("change", modarapidofun);
function modarapidofun() {
if (this.checked) {
var storearrbrand3 = arrofobj.filter(function (el) {
if (el.brand == "Moda Rapido") {
return el;
}
});
storearrbrand3.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrbrand3);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Filter Here & Now
//here&now
document.querySelector("#herenow").addEventListener("change", herenowfun);
function herenowfun() {
if (this.checked) {
var storearrbrand4 = arrofobj.filter(function (el) {
if (el.brand == "HERE & NOW") {
return el;
}
});
storearrbrand4.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrbrand4);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Filter Roadster
//roadster
document.querySelector("#roadster").addEventListener("change", roadsterfun);
function roadsterfun() {
if (this.checked) {
var storearrbrand5 = arrofobj.filter(function (el) {
if (el.brand == "Roadster") {
return el;
}
});
storearrbrand5.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrbrand5);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Filter by size
//sizes
document.querySelector("#sizes").addEventListener("change", sizesfun);
function sizesfun() {
if (this.checked) {
var storearrsize1 = arrofobj.filter(function (el) {
if (el.size == "S") {
return el;
}
});
storearrsize1.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrsize1);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//sizem
document.querySelector("#sizem").addEventListener("change", sizemfun);
function sizemfun() {
if (this.checked) {
var storearrsize2 = arrofobj.filter(function (el) {
if (el.size == "M") {
return el;
}
});
storearrsize2.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrsize2);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//sizel
document.querySelector("#sizel").addEventListener("change", sizelfun);
function sizelfun() {
if (this.checked) {
var storearrsize3 = arrofobj.filter(function (el) {
if (el.size == "L") {
return el;
}
});
storearrsize3.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrsize3);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Size xl
document.querySelector("#sizexl").addEventListener("change", sizexlfun);
function sizexlfun() {
if (this.checked) {
var storearrsize4 = arrofobj.filter(function (el) {
if (el.size == "XL") {
return el;
}
});
storearrsize4.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrsize4);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Filter by Color
//Red
document.querySelector("#cred").addEventListener("change", redfun);
function redfun() {
if (this.checked) {
var storearrclr1 = arrofobj.filter(function (el) {
if (el.color_family == "red") {
return el;
}
});
storearrclr1.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrclr1);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//blue
document.querySelector("#cred").addEventListener("change", redfun);
function redfun() {
if (this.checked) {
var storearrclr1 = arrofobj.filter(function (el) {
if (el.color_family == "red") {
return el;
}
});
storearrclr1.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrclr1);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Blue
document.querySelector("#cblue").addEventListener("change", bluefun);
function bluefun() {
if (this.checked) {
var storearrclr2 = arrofobj.filter(function (el) {
if (el.color_family == "blue") {
return el;
}
});
storearrclr2.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrclr2);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Green
document.querySelector("#cgreen").addEventListener("change", greenfun);
function greenfun() {
if (this.checked) {
var storearrclr3 = arrofobj.filter(function (el) {
if (el.color_family == "green") {
return el;
}
});
storearrclr3.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrclr3);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//Black
document.querySelector("#cblack").addEventListener("change", blackfun);
function blackfun() {
if (this.checked) {
var storearrclr4 = arrofobj.filter(function (el) {
if (el.color_family == "Black") {
return el;
}
});
storearrclr4.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrclr4);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
//White
document.querySelector("#cwhite").addEventListener("change", whitefun);
function whitefun() {
if (this.checked) {
var storearrclr5 = arrofobj.filter(function (el) {
if (el.color_family == "White") {
return el;
}
});
storearrclr5.sort(function (a, b) {
return b.discount - a.discount;
});
displayUi(storearrclr5);
} else {
arrofobj = JSON.parse(localStorage.getItem("lsproductdetails"));
displayUi(arrofobj);
}
}
function displayUi(arrofobj) {
document.querySelector("#jsproduct").innerHTML = "";
arrofobj.map(function (el, i) {
//Create all html tags
var singlemainbox = document.createElement("div");
var likebox = document.createElement("div");
var spanbox1 = document.createElement("span");
var mainproductbox = document.createElement("div");
var firstimagediv = document.createElement("div");
var innerimagediv = document.createElement("div");
var innerimagetag = document.createElement("img");
var namediv = document.createElement("div");
var priceanddisdiv = document.createElement("div");
var pricediv = document.createElement("div");
var discountdiv = document.createElement("div");
var mrpdiv = document.createElement("div");
var stardiv = document.createElement("div");
var spanbox2 = document.createElement("span");
var spanbox3 = document.createElement("span");
var spanbox4 = document.createElement("span");
var spanbox5 = document.createElement("span");
var spanbox6 = document.createElement("span");
var freeshipingdiv = document.createElement("div");
var lstdiv = document.createElement("div");
var branddiv = document.createElement("div");
var colordiv = document.createElement("div");
//creating attributes
spanbox1.setAttribute("id", "heart");
mainproductbox.setAttribute("id", "prod");
innerimagetag.setAttribute("src", el.imgURL);
spanbox2.setAttribute("class", "fa fa-star checked");
spanbox3.setAttribute("class", "fa fa-star checked");
spanbox4.setAttribute("class", "fa fa-star checked");
spanbox5.setAttribute("class", "fa fa-star");
spanbox6.setAttribute("class", "fa fa-star");
//Set all values
namediv.textContent = el.name;
// pricediv.textContent = "₹" + el.price;
pricediv.innerHTML = "₹" + el.price;
discountdiv.textContent = el.discount + "% Off";
mrpdiv.textContent = "₹" + el.mrp;
branddiv.textContent = "Brand: " + el.brand;
colordiv.textContent = "Color-Family: " + el.color_family;
freeshipingdiv.textContent = "Free Shipping";
//Append all the element
lstdiv.append(branddiv, colordiv);
stardiv.append(spanbox2, spanbox3, spanbox4, spanbox5, spanbox6);
priceanddisdiv.append(pricediv, discountdiv);
innerimagediv.append(innerimagetag);
firstimagediv.append(innerimagediv);
mainproductbox.append(
firstimagediv,
namediv,
priceanddisdiv,
mrpdiv,
stardiv,
freeshipingdiv,
lstdiv
);
likebox.append(spanbox1);
singlemainbox.append(likebox, mainproductbox);
document.querySelector("#jsproduct").append(singlemainbox);
//Click any single product
singlemainbox.addEventListener("click", function () {
//console.log(arrofobj[i]);
var singledata = arrofobj[i];
localStorage.setItem("SingleProd", JSON.stringify(singledata));
window.location.href = "singleprod.html";
});
});
document.querySelector("#logo").addEventListener("click", function () {
window.location.href = "index.html";
});
}
var cartArr = JSON.parse(localStorage.getItem("cartDatabase"));
var cartIcon = document.querySelector("#cartIcon");
cartIcon.addEventListener("click", cartPage);
function cartPage(){
if(cartArr.length == 0){
window.location.href = "cart.html";
}
else{
window.location.href = "cart1.html";
}
}