-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbadmintonProducts.js
644 lines (571 loc) · 26.4 KB
/
badmintonProducts.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
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
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
var badmintonproddata = [
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXAS01FLBKYL.jpg",
category:"Badminton Rackets",
name:"YONEX Astrox 01 Feel Badminton",
strikedOffPrice:3150,
price:1999,
description: "A Badminton racket with good grip and strong strings",
brand:"YONEX",
size: "Medium",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXAS01ABLTYBKPU.jpg",
category:"Badminton Rackets",
name:"YONEX Astrox 02 Ability Badminton",
strikedOffPrice:3150,
price:1999,
description: "YONEX Astrox 01 Ability Badminton Racket (Black/Purple, Strung)",
brand:"YONEX",
size: "Small",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=80,height=80,quality=75,format=auto/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXAS01CLRBKRD.jpg",
category:"Badminton Rackets",
name:"YONEX Astrox 01 Clear Badminton Racket",
strikedOffPrice:3150,
price:1999,
description: "YONEX Astrox 01 Clear Badminton Racket (Black/Red, Strung)",
brand:"YONEX",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXEXBLT63.jpg",
category:"Badminton Strings",
name:"YONEX BG EXBOLT 63 Badminton String",
strikedOffPrice:1030,
price:799,
description: "YONEX BG EXBOLT 63 Badminton String",
brand:"YONEX",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXBDSHM600SUPY.jpg",
category:"Badminton Shuttlecock",
name:"YONEX Mavis 500 Super Yellow Badminton Shuttlecock",
strikedOffPrice:1120,
price:849,
description: "YONEX Mavis 500 Super Yellow Badminton Shuttlecock",
brand:"YONEX",
size: "Small",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXBDSHM600SUPY3.jpg",
category:"Badminton Shuttlecock",
name:"YONEX MAVIS 500 Supre Yellow Badminton Shuttlecock (3 Tubes)",
strikedOffPrice:3360,
price:2499,
description: "YONEX mavis 500 Supre Yellow Badminton Shuttlecock (3 tubes)",
brand:"YONEX",
size: "Medium",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXBDSHM600SUPY10.jpg",
category:"Badminton Shuttlecock",
name:"YONEX MAVIS 500 Super Yellow",
strikedOffPrice:11200,
price:7999,
description: "YONEX MAVIS 500 Super Yellow Badminton Shuttlecock (10 tubes)",
brand:"YONEX",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/VCSH910FBLPWH.jpg",
category:"Badminton Shoes",
name:"Victor SH910F",
strikedOffPrice:6600,
price:2649,
description: "Vicotr SH910F Indoor Court Shoes (Blue/Pearl White) \n Clearance Sale! Buy 1 Get 1 Free. Please add any 2 Victor Shoes to get the lower priced pair free! \n Product warranty not applicable on Clearance Sale items. No Refund No Replacement applicable on this Shoes",
brand:"Victor",
size: "Small",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/BB30F21052033.jpg",
category:"Badminton Shoes",
name:"Babolat Shadow Team Mens Indoor Court Shoes",
strikedOffPrice:4699,
price:3749,
description: "Babolat Shadow Team Mens Indoor Court Shoes (Black/Blue)",
brand:"Babolat",
size: "Multi",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/BB30F21034060.jpg",
category:"Badminton Shoes",
name:"Babolat Shadow Spirit Mens Indoor Court Shoes (Dark Blue)",
strikedOffPrice:5799,
price:4649,
description: "Babolat Shadow Spirit Mens Indoor Court Shoes (Dark Blue)",
brand:"Babolat",
size: "Multi",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/BB31F21041068.jpg",
category:"Badminton Shoes",
name:"Babolat Shadow Spirit Womens Indoor Court Shoes (White/Light Blue)",
strikedOffPrice:5799,
price:4649,
description: "Babolat Shadow Spirit Womens Indoor Court Shoes (White/Light Blue)",
brand:"Babolat",
size: "Multi",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/BB31F21062035.jpg",
category:"Badminton Shoes",
name:"Babolat Shadow Team Womens Indoor Court Shoes (Black/Pink)",
strikedOffPrice:4699,
price:3749,
description: "Babolat Shadow Team Womens Indoor Court Shoes (Black/Pink)",
brand:"Babolat",
size: "Small",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXBDGRAC102T.jpg",
category:"Badminton Grip",
name:"YONEX AC102T Overgrip",
strikedOffPrice:6300,
price:5199,
description: "YONEX AC102T Overgrip",
brand:"YONEX",
size: "Medium",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YXBDGRTCH501B.jpg",
category:"Badminton Grip",
name:"Yonex Tech 501B Overgrip",
strikedOffPrice:4500,
price:2700,
description: "Yonex Tech 501B Overgrip",
brand:"YONEX",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/BBBD24319113.jpg",
category:"Badminton Strings",
name:"Babolat IFEEL 70 Badminton String",
strikedOffPrice:11500,
price:5750,
description: "Babolat IFEEL 70 Badminton String",
brand:"Babolat",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/BBBD24319136.jpg",
category:"Badminton Strings",
name:"Babolat IFEEL 70 Badminton String",
strikedOffPrice:11500,
price:5750,
description: "Babolat IFEEL 70 Badminton String Reel (Blue, 200M)",
brand:"Babolat",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/BBBD24319105.jpg",
category:"Badminton Strings",
name:"Babolat IFEEL 70 Badminton String",
strikedOffPrice:11500,
price:5750,
description: "Babolat IFEEL 70 Badminton String Reel (Black 200M)",
brand:"Babolat",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/HDBRI500.jpg",
category:"Badminton Rackets",
name:"Head Ignition 500 Badminton Racket",
strikedOffPrice:4790,
price:2899,
description: "Head Ignition 500 Badminton Racket (White/Blue)",
brand:"Head",
size: "Small",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/HDBRX22.jpg",
category:"Badminton Rackets",
name:"Head Xenon 2.2 Badminton Racket",
strikedOffPrice:5190,
price:3099,
description: "Head Xenon 2.2 Badminton Racket (Black)",
brand:"Head",
size: "Small",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YNBRMP55L.jpg",
category:"Badminton Rackets",
name:"Head Xenon 1.1 Badminton Racket",
strikedOffPrice:2299,
price:1599,
description: "Head Xenon 1.1 is an ideal badminton racket for beginner and intermediate players. Head Xenon comes with blue colour surface and multicoloured pattern, which enhances its overall appearance.",
brand:"Head",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YNBRMP22L.jpg",
category:"Badminton Rackets",
name:"YONEX Muslce Power 22 Light",
strikedOffPrice:3190,
price:2299,
description: "Yonex Muscle Power 22 Light is an excellent racquet for professional badminton players at the beginner to intermediate level. Muscle Power 22 Light comes in a unique combination of orange, white and black colours.",
brand:"YONEX",
size: "Large",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YNBRMP29L.jpg",
category:"Badminton Rackets",
name:"YONEX Muscle Power 29 Light",
strikedOffPrice:4200,
price:2699,
description: "YONEX Muscle Power 29 Light is a perfect badminton racket for beginner to intermediate level players. Muscle Power 29 Light comes with a vibrant combination of blue, black and white colours that gives the racquet a dynamic look.",
brand:"YONEX",
size: "Medium",
},
{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/YNBRMP55L.jpg",
category:"Badminton Rackets",
name:"YONEX Muscle Power 55 Light",
strikedOffPrice:4825,
price:2899,
description: "YONEX Muscle Power 55 Light is an excellent badminton racket for players looking for explosive power and fast manoeuvrability. Muscle Power 55 Light comes in a beautiful combination of black, grey and gold colours.",
brand:"YONEX",
size: "Medium",
},{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/VCSH910SGSLFG.jpg",
category:"Badminton Shoes",
name:"VIctor SH 910 Indoor Court Shoes",
strikedOffPrice:6600,
price:2649,
description: "Victor SH 910 Indoor Court Shoes (Silver/Fluorescent Green) \nMonsoon Clearance Sale! Buy 1 Get 1 Free. Please add any 2 Victor Shoes to get the lower priced pair free! \nProduct warranty not applicable on Clearance Sale items. No Refund No Replacement applicable on this Shoes",
brand:"Victor",
size: "Multi",
},{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/VCSHS80EYLBL.jpg",
category:"Badminton Shoes",
name:"Victor SH-S80-E Indoor Court Shoes",
strikedOffPrice:9600,
price:3849,
description: "Victor SH-S80-E Indoor Court Shoes (Yellow/Blue). \nMonsoon Clearance Sale! Buy 1 Get 1 Free. Please add any 2 Victor Shoes to get the lower priced pair free! \nProduct warranty not applicable on Clearance Sale items. No Refund No Replacement applicable on this Shoes",
brand:"Victor",
size: "Multi",
},{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/VCSHA930OORRD.jpg",
category:"Badminton Shoes",
name:"Victor SH-A930 Indoor Court Shoes",
strikedOffPrice:10400,
price:4199,
description: "Victor SH-A930 Indoor Court Shoes (Orange/Red). \nMonsoon Clearance Sale! Buy 1 Get 1 Free. Please add any 2 Victor Shoes to get the lower priced pair free! \nProduct warranty not applicable on Clearance Sale items. No Refund No Replacement applicable on this Shoes",
brand:"Victor",
size: "Multi",
},{
imgUrl:"https://storage.sg.content-cdn.io/cdn-cgi/image/width=500,height=500,quality=75,format=auto,fit=cover,g=top/in-resources/b368029c-a4dd-448a-a888-58348cb1b144/Images/ProductImages/Source/VCSHA710DERYL-2.jpg",
category:"Badminton Shoes",
name:"Victor SH-A710 INdoor Court Shoes",
strikedOffPrice:7300,
price:2949,
description: "Victor SH-A710 Indoor Court Shoes (Red/Black). \nMonsoon Clearance Sale! Buy 1 Get 1 Free. Please add any 2 Victor Shoes to get the lower priced pair free! \nProduct warranty not applicable on Clearance Sale items. No Refund No Replacement applicable on this Shoes",
brand:"Victor",
size: "Multi",
}
]
var prodData = JSON.parse(localStorage.getItem("badmintonDatabase"));
var cart = JSON.parse(localStorage.getItem("shoppingCart"))||[];
displayProducts(prodData);
function displayProducts(arr){
document.querySelector(".displayProducts").innerHTML = "";
arr.map(function(elem, index){
var div = document.createElement("div");
div.setAttribute("class","productDiv");
var wishlistIcon = document.createElement("img");
wishlistIcon.setAttribute("src","https://cdn-icons-png.flaticon.com/512/1077/1077035.png")
wishlistIcon.setAttribute("class","wlIcon")
var image = document.createElement("img");
image.setAttribute("src",elem.imgUrl);
//Clicking on image takes you to product page
image.addEventListener("click", function(){
localStorage.setItem("quickViewProduct",JSON.stringify(elem));
window.location.href = "../individualProduct.html"
})
var prodName = document.createElement("h3");
prodName.textContent = elem.name;
var strikedOffPrice = document.createElement("p");
strikedOffPrice.textContent = "₹"+elem.strikedOffPrice;
strikedOffPrice.style.textDecoration = "line-through";
strikedOffPrice.style.color = "grey"
var price = document.createElement("p");
price.textContent = "₹"+elem.price;
var discPercent = document.createElement('p');
var discount= Math.floor(((elem.strikedOffPrice-elem.price)/elem.strikedOffPrice)*100);
discPercent.textContent = discount + "% off"
discPercent.style.color="orange";
var star = document.createElement("img");
star.setAttribute("src","https://winonan.org/wp-content/uploads/2018/04/5-stars-900x225.jpg");
star.style.width = "80px";
var innerDiv = document.createElement("div");
var quickviewbtn = document.createElement("button");
quickviewbtn.setAttribute("class","quickviewbtn");
quickviewbtn.textContent = "Quick View";
innerDiv.append(strikedOffPrice, price, discPercent, star);
div.append(wishlistIcon,image, quickviewbtn,prodName, innerDiv);
var prodDiv = document.querySelector(".displayProducts");
prodDiv.append(div);
if(window.matchMedia("(min-width:800px)").matches){
div.addEventListener("mouseenter",function(){
quickviewbtn.style.display = "block"
})
div.addEventListener("mouseleave",function(){
quickviewbtn.style.display = "none"
})
quickviewbtn.addEventListener("click",function(){
localStorage.setItem("quickViewProduct",JSON.stringify(elem));
document.querySelector(".quickview").style.display = "block";
showQuickView();
})
}
})
document.querySelector("#itemsFound").textContent = "Found "+arr.length + " item(s)";
}
function discount(num1, num2){
var disc = Math.floor(((num1-num2)/num1)*100);
return disc;
}
document.querySelector("#sortBy").addEventListener("change",sortBy);
//Sorting Function
function sortBy(){
var val = document.querySelector("#sortBy").value;
if(val == "priceAsc"){
prodData.sort(function(a,b){
return a.price-b.price
})
}
else if(val == "priceDesc"){
prodData.sort(function(a,b){
return b.price-a.price
})
}
else if(val == "discount"){
prodData.sort(function(a,b){
var x = Math.floor(((a.strikedOffPrice-a.price)/a.strikedOffPrice)*100);
var y = Math.floor(((b.strikedOffPrice-b.price)/b.strikedOffPrice)*100);
return y-x;
})
}
displayProducts(prodData);
}
//Trying to create the filter categories on their own without need for hardcoding them into the html page
function getAllCategories(arr){
var uniq = {};
for(var i =0; i<arr.length; i++){
if(uniq[arr[i].category]===undefined){
uniq[arr[i].category] =1;
}
else{
uniq[arr[i].category]++;
}
}
console.log(uniq)
return uniq;
}
function getAllBrand(arr){
var uniq = {};
for(var i =0; i<arr.length; i++){
if(uniq[arr[i].brand]===undefined){
uniq[arr[i].brand] =1;
}
else{
uniq[arr[i].brand]++;
}
}
console.log(uniq)
return uniq;
}
function getAllSize(arr){
var uniq = {};
for(var i =0; i<arr.length; i++){
if(uniq[arr[i].size]===undefined){
uniq[arr[i].size] =1;
}
else{
uniq[arr[i].size]++;
}
}
console.log(uniq)
return uniq;
}
//Filteration Part
var filterCategories = [];
var filterBrand = [];
var filterSize = [];
var uniqCategoriesobj = getAllCategories(prodData);
var uniqBrandsobj = getAllBrand(prodData);
var uniqSizesobj = getAllSize(prodData)
var uniqCategoriesArr = [];
for(var key in uniqCategoriesobj){
uniqCategoriesArr.push(key);
}
var uniqBrandArr = [];
for(var key in uniqBrandsobj){
uniqBrandArr.push(key);
}
var uniqSizeArr = [];
for(var key in uniqSizesobj){
uniqSizeArr.push(key);
}
var fil = document.querySelector("#filter")
uniqCategoriesArr.map(function(elem){
var ckbox = document.createElement("input");
ckbox.setAttribute("type","checkbox");
ckbox.setAttribute("value", elem);
ckbox.setAttribute("name","category");
var elem_count = 0;
ckbox.addEventListener("change",function(event){
if(elem_count%2==0){
filterCategories.push(elem);
}
else{
for(var i =0; i<filterCategories.length; i++){
if(filterCategories[i]==elem){
filterCategories.splice(i,1);
break;
}
}
}
elem_count++;
console.log(filterCategories);
displayFilteredProducts(filterCategories);
})
var label = document.createElement("label");
label.setAttribute("for",elem);
label.textContent = `${elem} (${uniqCategoriesobj[elem]})`;
var br = document.createElement("br")
fil.append(ckbox, label, br);
})
//BRands
uniqBrandArr.map(function(elem){
var ckbox = document.createElement("input");
ckbox.setAttribute("type","checkbox");
ckbox.setAttribute("value", elem);
ckbox.setAttribute("name","brand");
var elem_count = 0;
ckbox.addEventListener("change",function(event){
if(elem_count%2==0){
filterBrand.push(elem);
}
else{
for(var i =0; i<filterBrand.length; i++){
if(filterBrand[i]==elem){
filterBrand.splice(i,1);
break;
}
}
}
elem_count++;
console.log(filterBrand);
displayFilteredProducts(filterBrand);
})
var label = document.createElement("label");
label.setAttribute("for",elem);
label.textContent = `${elem} (${uniqBrandsobj[elem]})`;
var br = document.createElement("br")
document.querySelector("#filterbrand").append(ckbox, label, br);
})
//Sizes
uniqSizeArr.map(function(elem){
var ckbox = document.createElement("input");
ckbox.setAttribute("type","checkbox");
ckbox.setAttribute("value", elem);
ckbox.setAttribute("name","size");
var elem_count = 0;
ckbox.addEventListener("change",function(event){
if(elem_count%2==0){
filterSize.push(elem);
}
else{
for(var i =0; i<filterSize.length; i++){
if(filterSize[i]==elem){
filterSize.splice(i,1);
break;
}
}
}
elem_count++;
console.log(filterSize);
displayFilteredProducts(filterSize);
})
var label = document.createElement("label");
label.setAttribute("for",elem);
label.textContent = `${elem} (${uniqSizesobj[elem]})`;
var br = document.createElement("br")
document.querySelector("#filtersize").append(ckbox, label, br);
})
function displayFilteredProducts(arr){
var total_filtered_prods = []
displayProducts(prodData);
for(var i =0; i<arr.length;i++){
var filtered= prodData.filter(function(elem){
return (elem.category == arr[i]||elem.brand == arr[i]||elem.size==arr[i]);
})
total_filtered_prods = total_filtered_prods.concat(filtered)
//console.log(total_filtered_prods)
displayProducts(total_filtered_prods);
}
}
//Changing the view of the page from 3 to 4 or vice-versa//
document.querySelector("#flexofThree").addEventListener("click", function(){
console.log("30%");
for(var i =0; i<prodData.length; i++){
document.querySelectorAll(".productDiv")[i].style.flex = "25%"
document.querySelector("#flexOfFour").style.backgroundColor = "lightgrey";
document.querySelector("#flexofThree").style.backgroundColor="black";
}
});
document.querySelector("#flexOfFour").addEventListener("click", function(){
for(var i =0; i<prodData.length; i++){
document.querySelectorAll(".productDiv")[i].style.flex = "20%"
document.querySelector("#flexOfFour").style.backgroundColor = "black";
document.querySelector("#flexofThree").style.backgroundColor="lightgrey";
}
})
function showQuickView(){
document.querySelector(".quickViewImg").innerHTML = ""
document.querySelector(".quickdesc").innerHTML = ""
document.querySelector(".quantityPriceDisc").innerHTML = ""
var product = JSON.parse(localStorage.getItem("quickViewProduct"));
var prodName = document.createElement("p");
prodName.textContent = product.name;
var img = document.createElement("img");
img.setAttribute("src",product.imgUrl);
var strikedprc = document.createElement("p");
strikedprc.textContent = "₹"+product.strikedOffPrice;
strikedprc.style.textDecoration = "line-through";
var prc = document.createElement("p");
prc.textContent = "₹"+product.price;
var discount = document.createElement("p");
var x = Math.floor(((product.strikedOffPrice-product.price)/product.strikedOffPrice)*100)
discount.textContent = x+ "%";
discount.style.color = "orange";
var description = document.createElement("p");
description.textContent = product.description;
// document.querySelector(".quickview").append();
document.querySelector(".quickViewImg").append(prodName,img);
document.querySelector(".quickdesc").append(description);
document.querySelector(".quantityPriceDisc").append(strikedprc, prc, discount);
document.querySelector("#addToCart").addEventListener("click",function(){
var qty = document.querySelector("#qty").value
if(qty==null||qty==""){
qty =1;
}
var cartobj = {
image: product.imgUrl,
product_name: product.name,
product_price: product.price,
quantity: qty,
}
cart.push(cartobj);
localStorage.setItem("shoppingCart",JSON.stringify(cart));
document.querySelector(".quickview").style.display = "none";
})
}
document.querySelector("#closequickview").addEventListener("click", function(){
console.log("close")
document.querySelector(".quickview").style.display = "none";
})
document.querySelector("#counter").textContent = cart.length;