-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjewelry.js
290 lines (279 loc) · 7.52 KB
/
jewelry.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
let product_data=[
{
brand:"Saint Laurent",
pname:"Clip-on drop earings",
price:"669",
category:"earing",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/fb/P00647362_d2.jpg",
productID:"women1",
},
{
brand:"gucci",
pname:"Crystal embelished",
price:"389",
category:"bracelet",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/8a/P00675727_d2.jpg",
productID:"women2",
},
{
brand:"Saint Laurent",
pname:"Nautilus shell 14kt gold",
price:"745",
category:"necklace",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/db/P00680160_d2.jpg",
productID:"women3",
},
{
brand:"Bottega veneta",
pname:"Gold-platted silver ring",
price:"425",
category:"ring",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/c0/P00707376_d2.jpg",
productID:"women4",
},
{
brand:"Saint Laurent",
pname:"Opyum embellished",
price:"335",
category:"earing",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/d7/P00709568_d2.jpg",
productID:"women5",
},
{
brand:"Valentino",
pname:"Embellished volgo chain",
price:"215",
category:"bracelet",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/2c/P00705593_d2.jpg",
productID:"women6",
},
{
brand:"Sydney evan",
pname:"Clam shell small 14kt gold",
price:"559",
category:"necklace",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/e0/P00705564_d2.jpg",
productID:"women7",
},
{
brand:"Aliita",
pname:"Deco rombo",
price:"665",
category:"ring",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/83/P00688553_d2.jpg",
productID:"women8",
},
{
brand:"Magda butrym",
pname:"Pearl and crystal",
price:"335",
category:"earing",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/29/P00705064_d2.jpg",
productID:"women9",
},
{
brand:"Versace",
pname:"Medusa and greca",
price:"379",
category:"bracelet",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/b5/P00706290_d2.jpg",
productID:"women10",
},
{
brand:"Loewe",
pname:"Nappa twisted",
price:"549",
category:"necklace",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/aa/P00691106_d2.jpg",
productID:"women11",
},
{
brand:"Marni",
pname:"Trapeze enamel",
price:"195",
category:"ring",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/3a/P00695319_d2.jpg",
productID:"women12",
},
{
brand:"Dolcee & Gabbana",
pname:"logo faux pearl",
price:"295",
category:"earing",
img:"https://img.mytheresa.com/1088/1088/66/jpeg/catalog/product/61/P00694976.jpg",
productID:"women13",
},
{
brand:"Aliita",
pname:"Dragonfly 9kt gold",
price:"145",
category:"bracelet",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/be/P00688509_d2.jpg",
productID:"women14",
},
{
brand:"Aliita",
pname:"Corazon rayado",
price:"295",
category:"necklace",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/81/P00688526.jpg",
productID:"women15",
},
{
brand:"Sydney",
pname:"Happy face 14kt yellow",
price:"1995",
category:"ring",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/e2/P00692131_d2.jpg",
productID:"women16",
},
{
brand:"Valentinio",
pname:"Vlogo embellished",
price:"379",
category:"earing",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/5c/P00705656_d2.jpg",
productID:"women17",
},
{
brand:"Jw Anderson",
pname:"Chain bracelet",
price:"309",
category:"bracelet",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/30/P00698066_d2.jpg",
productID:"women18",
},
{
brand:"Paco Rabanne",
pname:"Sphere body chain",
price:"636",
category:"necklace",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/d3/P00685514_d2.jpg",
productID:"women19",
},
{
brand:"Sophie bille",
pname:"Grand ensemble ruban",
price:"6219",
category:"ring",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/ae/P00692105_d2.jpg",
productID:"women20",
},
{
brand:"Valentino",
pname:"Vlogo faux pearl",
price:"245",
category:"earing",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/59/P00705671_d2.jpg",
productID:"women21",
},
{
brand:"Christian Louboutin",
pname:"Carasky embellished",
price:"329",
category:"bracelet",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/06/P00713212_d2.jpg",
productID:"women22",
},
{
brand:"Sydney evan",
pname:"Happy face 14kt yellow",
price:"2009",
category:"necklace",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/08/P00680161.jpg",
productID:"women23",
},
{
brand:"Alighieri",
pname:"The inferno 9kt gold",
price:"1365",
category:"ring",
img:"https://img.mytheresa.com/560/560/33/jpeg/catalog/product/02/P00671418_d2.jpg",
productID:"women24",
},
];
let container=document.getElementById("container");
let filter=document.getElementById("filterjewel");
let cartLS=JSON.parse(localStorage.getItem("cart-page")) || [];
document.querySelector("#sortprice").addEventListener("change",handlePriceSort);
function handlePriceSort(){
let selected=document.querySelector("#sortprice").value;
if(selected=="price low-to-high")
{
product_data.sort(function(a,b)
{
return a.price-b.price;
});
console.log(product_data);
display(product_data)
}
if(selected=="price high-to-low")
{
product_data.sort(function(a,b)
{
return b.price-a.price;
});
console.log(product_data);
display(product_data)
}
}
function display(data)
{
container.innerHTML=null;
data.forEach(function (ele)
{
let product=document.createElement("div");
let img=document.createElement("img");
img.src=ele.img;
let brand=document.createElement("h2");
brand.innerText=ele.brand;
let name=document.createElement("h2");
name.innerText=ele.pname;
let price=document.createElement("h4");
name.innerText=ele.price;
let cart=document.createElement("button");
cart.innerText="Add To Shopping Bag";
cart.addEventListener("click",function(){
AddToCart(ele);
})
product.append(img,brand,name,price,cart);
container.append(product);
});
}
display(product_data);
filter.addEventListener("change",function()
{
if(filter.value==="")
{
display(product_data);
}
else{
let filtered=product_data.filter(function(ele)
{
return ele.category===filter.value;
})
display(filtered);
}
});
function AddToCart(product){
let iscartAdded=false;
for(let i=0;i<cartLS.length;i++)
{
if(cartLS[i].productID===product.productID)
{
alert("Product already in the bag");
iscartAdded=true;
return
}
}
if(iscartAdded===false)
{
cartLS.push(product);
alert("Product Added Successfully");
localStorage.setItem("cart-page",JSON.stringify(cartLS));
}
}
document.getElementById("sb").addEventListener("click",shop)
function shop(){
window.location.href="cart.html";
}