forked from Anjali280/SEPHORA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
haircaredata.js
365 lines (342 loc) · 11.8 KB
/
haircaredata.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
var haircare_array = [
{
tag: "Shampoo",
image_url: "https://cdn14.nnnow.com/web-images/medium/styles/ZXCZQG4LPA2/1586865417849/1.jpg",
brand: "Aveda",
description: "Cherry Almond Softening Shampoo",
price: 1300,
gender: "Female",
skin_type: "Normal",
},
{
tag: "Shampoo",
image_url: "https://cdn09.nnnow.com/web-images/medium/styles/DSHD0M5WT0Z/1586865417815/1.jpg",
brand: "Aveda",
description: "Shampure™ Nurturing Shampoo",
price: 1500,
gender: "Female",
skin_type: "Normal",
},
{
tag: "Shampoo",
image_url: "https://cdn19.nnnow.com/web-images/medium/styles/PDOEXQ0ITGY/1586865417839/1.jpg",
brand: "Aveda",
description: "Be Curly™ Shampoo",
price: 2250,
gender: "Female",
skin_type: "Normal",
},
{
tag: "Shampoo",
image_url: "https://cdn14.nnnow.com/web-images/medium/styles/ZXCZQG4LPA2/1586865417849/1.jpg",
brand: "Aveda",
description: "Cherry Almond Softening Shampoo",
price: 1300,
gender: "Male",
skin_type: "Normal",
},
{
tag: "Shampoo",
image_url: "https://cdn09.nnnow.com/web-images/medium/styles/DSHD0M5WT0Z/1586865417815/1.jpg",
brand: "Aveda",
description: "Shampure™ Nurturing Shampoo",
price: 1500,
gender: "Male",
skin_type: "Combination",
},
{
tag: "Shampoo",
image_url: "https://cdn03.nnnow.com/web-images/medium/styles/9YJY1PG9ERJ/1580451959421/1.jpg",
brand: "Aveda",
description: "Nutriplenish™ Shampoo Light Moisture",
price: 750,
gender: "Male",
skin_type: "Dry",
},
{
tag: "Shampoo",
image_url: "https://cdn17.nnnow.com/web-images/medium/styles/7Q8UUW0TDB4/1609913734081/1.jpg",
brand: "Aveda",
description: "Invati Advanced™ Exfoliating Shampoo: Light",
price: 2450,
gender: "Female",
skin_type: "Oily",
},
{
tag: "Shampoo",
image_url: "https://cdn13.nnnow.com/web-images/medium/styles/F8JPSETLF92/1586865417816/1.jpg",
brand: "Aveda",
description: "Sap Moss Weightless Hydration Shampoo",
price: 2250,
gender: "Male",
skin_type: "Normal",
},
{
tag: "Conditioner",
image_url: "https://cdn04.nnnow.com/web-images/medium/styles/1M1KRTW6BV5/1571036172269/1.jpg",
brand: "Aveda",
description: "Sap Moss Weightless Hydration Conditioner",
price: 2400,
gender: "Male",
skin_type: "Normal",
},
{
tag: "Conditioner",
image_url: "https://cdn17.nnnow.com/web-images/medium/styles/2A8YHU3CSEM/1586865417790/1.jpg",
brand: "Aveda",
description: "Cherry Almond Softening Conditioner",
price: 1750,
gender: "Female",
skin_type: "Combination",
},
{
tag: "Conditioner",
image_url: "https://cdn02.nnnow.com/web-images/medium/styles/HHE9KAXKW8L/1586865417823/1.jpg",
brand: "Aveda",
description: "Cherry Almond Softening Leave-In Conditioner",
price: 1750,
gender: "Male",
skin_type: "Dry",
},
{
tag: "Conditioner",
image_url: "https://cdn16.nnnow.com/web-images/medium/styles/1Z491AQYL9B/1580451959406/1.jpg",
brand: "Aveda",
description: "Nutriplenish™ Conditioner Light Moisture",
price: 750,
gender: "Male",
skin_type: "Oily",
},
{
tag: "Conditioner",
image_url: "https://cdn10.nnnow.com/web-images/medium/styles/B428LT1Z7YB/1580451959400/1.jpg",
brand: "Aveda",
description: "Nutriplenish™ Leave-In-Conditioner",
price: 2850,
gender: "Female",
skin_type: "Normal",
},
{
tag: "Conditioner",
image_url: "https://cdn15.nnnow.com/web-images/medium/styles/KOBW76KOJ54/1586865417830/1.jpg",
brand: "Aveda",
description: "Be Curly™ Conditioner",
price: 2350,
gender: "Male",
skin_type: "Combination",
},
{
tag: "Conditioner",
image_url: "https://cdn12.nnnow.com/web-images/medium/styles/HRR0YRUUCK4/1586865417824/1.jpg",
brand: "Aveda",
description: "Shampure™ Conditioner",
price: 750,
gender: "Female",
skin_type: "Dry",
},
{
tag: "Conditioner",
image_url: "https://cdn11.nnnow.com/web-images/medium/styles/GSYDXLHZLUU/1580451959414/1.jpg",
brand: "Aveda",
description: "Nutriplenish™ Conditioner Deep Moisture",
price: 750,
gender: "Male",
skin_type: "Oily",
},
{
tag: "HairStyling",
image_url: "https://cdn16.nnnow.com/web-images/medium/styles/WLNYC1O7H10/1652253085725/1.jpg",
brand: "Sephora collection",
description: "Protective Hair Oil With Moringa Oil",
price: 2000,
gender: "Male",
skin_type: "Normal",
},
{
tag: "HairStyling",
image_url: "https://cdn19.nnnow.com/web-images/medium/styles/X1XO2C0IMAC/1634886167233/1.jpg",
brand: "Moroccanoil",
description: "Mending Infusion",
price: 2700,
gender: "Male",
skin_type: "Combination",
},
{
tag: "HairStyling",
image_url: "https://cdn12.nnnow.com/web-images/medium/styles/TDFZTYEVKX4/1635244791517/1.jpg",
brand: "Moroccanoil",
description: "Beach Wave Hair Mousse",
price: 2160,
gender: "Male",
skin_type: "Oily",
},
{
tag: "HairStyling",
image_url: "https://cdn08.nnnow.com/web-images/medium/styles/0XBYOPD1N2D/1634886109094/1.jpg",
brand: "Moroccanoil",
description: "Restorative Hair Mask",
price: 3330,
gender: "Female",
skin_type: "Dry",
},
{
tag: "HairStyling",
image_url: "https://cdn11.nnnow.com/web-images/medium/styles/NXSX9L9VBBL/1652252632363/1.jpg",
brand: "Ouai",
description: "Matte Pomade",
price: 2700,
gender: "Female",
skin_type: "Normal",
},
{
tag: "HairStyling",
image_url: "https://cdn12.nnnow.com/web-images/medium/styles/QJ2QNWIE87T/1652252637863/1.jpg",
brand: "Ouai",
description: "Wave Spray",
price: 2200,
gender: "Female",
skin_type: "Combination",
},
{
tag: "HairStyling",
image_url: "https://cdn00.nnnow.com/web-images/medium/styles/644ZRGY12NH/1652252610548/1.jpg",
brand: "Ouai",
description: "Finishing Crème",
price: 2700,
gender: "Female",
skin_type: "Dry",
},
{
tag: "HairStyling",
image_url: "https://cdn00.nnnow.com/web-images/medium/styles/V73BE2NW20M/1652252643744/1.jpg",
brand: "Ouai",
description: "Volume Spray",
price: 2450,
gender: "Female",
skin_type: "Oily",
},
]
//let cartstore = JSON.parse(localStorage.getItem("cart_sephora")) || [];
// Brand -> Aveda , Ouai ,Moroccanoil
// let content = document.getElementById("content");
// haircaredata.forEach(function(elem,index){
// let prodBox = document.createElement("div");
// let image = document.createElement("img");
// let brand = document.createElement("h4");
// brand.innerText = (elem.brand).toUpperCase();
// brand.setAttribute("id","brandname");
// image.setAttribute("src",elem.image_url);
// image.setAttribute("id","prodimg");
// prodBox.append(image,brand);
// content.append(prodBox);
// if(index%4 == 0){
// cartstore.push(elem);
// }
//})
localStorage.setItem("haircare_products",JSON.stringify(haircare_array));
var haircare_obj = JSON.parse(localStorage.getItem("haircare_products")) || [];
display(haircare_obj);
function display(hair_array){
console.log(hair_array);
// console.log(hair_array.length);
document.getElementById("product_display").innerHTML = "";
hair_array.map(function(elem,index){
console.log(elem.brand);
var div2 = document.createElement("div");
var image = document.createElement("img");
image.setAttribute("src",elem.image_url);
image.setAttribute("atl",elem.brand);
var name = document.createElement("h4");
name.innerText = elem.brand;
var info = document.createElement("p");
info.innerText = elem.description;
var value = document.createElement("h4");
value.innerText = "Rs. "+ elem.price;
var add_to_cart = document.createElement("button");
add_to_cart.innerText = "Add to Cart";
add_to_cart.setAttribute("class","cart_bag");
add_to_cart.addEventListener("click",function(){
add_pro_cart_fun(elem);
});
var add_to_bag = document.createElement("button");
add_to_bag.innerText = "Add to Bag";
add_to_bag.addEventListener("click",function(){
add_pro_bag_fun(elem);
});
add_to_bag.setAttribute("class","cart_bag");
div2.append(image,name,info,value,add_to_cart);
document.getElementById("product_display").append(div2);
});
}
var cartProducts = JSON.parse(localStorage.getItem("cart_products"))|| [];
function add_pro_cart_fun(elem){
cartProducts.push(elem);
localStorage.setItem("cart_products",JSON.stringify(cartProducts));
}
var bagProducts = JSON.parse(localStorage.getItem("bag_products"))|| [];
function add_pro_bag_fun(elem){
bagProducts.push(elem);
localStorage.setItem("bag_products",JSON.stringify(bagProducts));
}
function filter_fun(){
filter_gender_fun();
filter_brand_fun();
filter_skintype_fun();
sort_price_fun();
var gender_filtered = haircare_obj;
function filter_gender_fun(){
selected_gender = document.getElementById("filter_gender").value;
gender_filtered = haircare_obj.filter(function(elem){
if(selected_gender === "all"){
return 1;
}
return elem.gender === selected_gender;
});
//display_skincare(gender_filtered);
}
var brand_filtered = gender_filtered;
function filter_brand_fun(){
var selected_brand = document.getElementById("filter_brand").value;
brand_filtered = gender_filtered.filter(function(elem){
if(selected_brand === "all"){
return 1;
}
return elem.brand === selected_brand;
});
//console.log(brand_filtered);
}
//display_skincare(brand_filtered);
var skintype_filtered = brand_filtered;
function filter_skintype_fun(){
var selected_skintype = document.getElementById("filter_skin_type").value;
skintype_filtered = brand_filtered.filter(function(elem){
if(selected_skintype === "all"){
return 1;
}
return elem.skin_type === selected_skintype;
});
//display_fragrance(skintype_filtered);
}
function sort_price_fun(){
if(document.getElementById("sort_price").value == 'high'){
skintype_filtered.sort(function(a,b){
if(parseInt(a.price)>parseInt(b.price)) return -1;
if(parseInt(a.price)<parseInt(b.price)) return 1;
return 0;
});
}
if(document.getElementById("sort_price").value == 'low'){
skintype_filtered.sort(function(a,b){
if(parseInt(a.price)>parseInt(b.price)) return 1;
if(parseInt(a.price)<parseInt(b.price)) return -1;
return 0;
});
}
display(skintype_filtered);
}
}
// go to top button function
function gotoTop(){
document.body.scrollTop = 0;
document.documentElement.scrollTop = 0;
}