forked from Prathamesh52-28/Boat_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
product2.js
382 lines (326 loc) · 11.9 KB
/
product2.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
var productsList= [
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/1-2_300x.png?v=1653637007",
name: "Wave Neo",
rev: "4.7 | 19 reviews",
discount:"70%off",
price: "1799",
strikedoffprice: "5990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/blue_d8db0011-02f7-43d6-9fe7-7a71a9ed86d2_300x.png?v=1654312290",
name: "Wave Connect",
rev: "4.9 | 88 reviews",
discount:"57% off",
price: "2999",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/blue_58bd5e28-de95-4f31-909d-6bce484bdbd9_300x.png?v=1658294451",
name: "Wave Select",
rev: "5.0 | 13 reviews",
discount:"64% off",
price: "2499",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/Blaze-FI-Red04_300x.png?v=1658123186",
name: "Blaze",
rev: "5.0 | 20 reviews",
discount:"47% off",
price: "3699",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/main-images-2_300x.png?v=1655198531",
name: "Xtend Sport",
rev: "4.9 | 7 reviews",
discount:"64% off",
price: "2499",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/a6549acb-b075-4c3e-8ed3-9c9fcba32d42_300x.png?v=1625046216",
name: "Storm",
rev: "4.9 | 1010 reviews",
discount:"59% off",
price: "2449",
strikedoffprice: "5990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/5752f5e4-89e0-4f84-b7fe-4d9f85771046_300x.png?v=1625157753",
name: "Watch Flash",
rev: "4.8 | 48 reviews",
discount:"36% off",
price: "4499",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/xtend_black_300x.png?v=1650387008",
name: "Xtend",
rev: "4.8 | 146 reviews",
discount:"67% off",
price: "2659",
strikedoffprice: "7990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/main3.3_9198fbdb-47fc-4ba1-878f-10d3acdb3d9c_300x.png?v=1646394746",
name: "TRebel Blaze",
rev: "5.0 | 6 reviews",
discount:"43% off",
price: "3999",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/mainblack_300x.png?v=1658994702",
name: "Iris",
rev: "5.0 | 2 reviews",
discount:"63% off",
price: "4499",
strikedoffprice: "11999",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/main1_f30681d9-fddb-4997-bfcb-503fcc258a5c_300x.png?v=1646392933",
name: "Matrix",
rev: "5.0 | 11 reviews",
discount:"58% off ",
price: "4999",
strikedoffprice: "11990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/main6_2_8e1cdd84-4a34-4e92-97c5-0e1d4ba6da46_300x.png?v=1646393710",
name: "TRebel Xtend",
rev: "5.0 | 3 reviews",
discount:"56% off",
price: "3499",
strikedoffprice: "7990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/main_2b98dda1-57d3-40ee-80f0-4687b8f8a72b_300x.png?v=1662537789",
name: "Watch Xtend DC Edition",
rev: "Be the first to review",
discount:"12% off",
price: "3499",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/storm-black_82c0d3c8-da5c-49f1-8d13-08055d7afac8_300x.png?v=1623843234",
name: "Storm RTL",
rev: "5.0 | 3 reviews",
discount:"50% off",
price: "2999",
strikedoffprice: "5990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/Matrix-FI_Blue02_da7a821f-c621-4af6-aec2-7d647df3a5db_300x.png?v=1658994355",
name: "TRebel Matrix",
rev: "5.0 | 1 review",
discount:"58% off",
price: "4999",
strikedoffprice: "11990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/2_1e5f7cde-1976-4877-b92b-a685bed27233_300x.png?v=1662123878",
name: "Storm Pro Call",
rev: "5.0 | 10 reviews",
discount:"64% off",
price: "3499",
strikedoffprice: "9799",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/20dbeecf-4dc2-48c6-8dae-8a31f1746f44_300x.png?v=1625046513",
name: "Xplorer O2",
rev: "4.8 | 29 reviews",
discount:"33% off",
price: "3999",
strikedoffprice: "5990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/xtend_black_ae26d6cf-4552-45a6-8a61-42160e1b4407_300x.png?v=1658829594",
name: "Watch Xtend RTL",
rev: "Be the fist to review",
discount:"56% off",
price: "3499",
strikedoffprice: "7990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/5752f5e4-89e0-4f84-b7fe-4d9f85771046_44573016-8eae-4ed9-8fa7-57f96575ba8f_300x.png?v=1658829787",
name: "Watch Flash RTL",
rev: "Be the first to review",
discount:"57% off",
price: "2999",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/Green_4_300x.png?v=1651215796",
name: "Mystiq",
rev: "4.8 | 5 reviews",
discount:"64% off",
price: "2499",
strikedoffprice: "6990",
save: "Save ₹15 more on UPI payment",
},
];
//Function to append products//
showList(productsList);
function showList(productsList){
document.getElementById("parent").innerHTML = "";
productsList.map(function(elem, i){
var div = document.createElement("div");
div.setAttribute("class","card");
var img = document.createElement("img");
img.setAttribute("src",elem.img_link);
var imgBx = document.createElement("div");
imgBx.setAttribute("class","imgBx");
imgBx.append(img);
var name = document.createElement("h3");
name.textContent=elem.name;
name.setAttribute("class","name");
//
var stars = document.createElement("i");
stars.setAttribute("class", "fa-solid fa-star");
var rev = document.createElement("p");
rev.textContent=elem.rev;
rev.setAttribute("class","rev");
// Consists of star, rating, rev
reviewBox = document.createElement("div");
reviewBox.setAttribute("class","reviewBox");
reviewBox.append(stars, rev);
//
var x = document.createElement("hr");
var disc = document.createElement("p");
disc.textContent=elem.disc;
disc.setAttribute("class","disc");
var priceEle = document.createElement("p");
priceEle.setAttribute("class","price");
priceEle.textContent = "₹"+" "+elem.price;
var strikedoffprice = document.createElement("p");
strikedoffprice.setAttribute("class","strprice");
strikedoffprice.textContent = "₹"+" "+elem.strikedoffprice;
// Consists of Disc, Price & Striked Price
var priceparent = document.createElement("div");
priceparent.setAttribute("class","priceparent");
priceparent.append(disc,priceEle,strikedoffprice);
var save = document.createElement("p");
save.textContent=elem.save;
save.setAttribute("class","save");
var shopCartbtn = document.createElement("button");
shopCartbtn.textContent="ADD TO CART";
shopCartbtn.setAttribute("class","shopCartbtn");
shopCartbtn.addEventListener("click", function() {
addtocart(i);
});
// Constist of all contents in side of image
var description = document.createElement("div");
description.setAttribute("class","description");
description.append(name,reviewBox,x,priceparent,save,shopCartbtn); ///
div.append(imgBx,description);
document.getElementById("parent").append(div);
});
}
//Sorting
function sortFun(){
var selected=document.querySelector("#sort").value;
var sortProduct ;
if(selected=="Sort by Featured"){
console.log(productsList);
sortProduct = productsList;
}
else if(selected=="Price, low to high"){
sortProduct = productsList.sort(function(a,b){
return parseFloat(a.price)-parseFloat(b.price);
})
}
else if(selected=="Price, high to low"){
sortProduct = productsList.sort(function(a,b){
return parseFloat(b.price)-parseFloat(a.price);
})
}
else if(selected==="Alphabetically, A-Z"){
sortProduct = productsList.sort(function(a,b){
if(a.name>b.name) return 1;
if(a.name<b.name) return -1;
return 0;
});
}
else if(selected==="Alphabetically, Z-A"){
sortProduct = productsList.sort(function(a,b){
if(a.name>b.name) return -1;
if(a.name<b.name) return 1;
return 0;
})
}
console.log(sortProduct)
return showList(sortProduct);
}
// Add to Cart
var cartProduct = JSON.parse(localStorage.getItem("cart")) || [];
function addtocart(index){
event.preventDefault()
alert("Product added to cart sucessfully !")
var flag = 0
var ind = 0
var prod = productsList.filter(function(elem,i){
return i == index
})
var cartp = cartProduct.filter(function(elem,i){
if(elem.name === prod[0].name){
flag = 1
ind = i
}
})
if(flag == 0){
prod[0].qty = 1
cartProduct.push(prod[0])
}
else{
cartProduct[ind].qty++
flag = 0
}
localStorage.setItem("cart",JSON.stringify(cartProduct))
console.log(cartProduct)
var cartItems = JSON.parse(localStorage.getItem("cart")) || []
var items = cartItems.length
console.log(items)
if(items>0){
document.querySelector(".nitems").textContent = items
}
}
var cartItems = JSON.parse(localStorage.getItem("cart")) || [];
var items = cartItems.length;
console.log(items);
if(items>0){
document.querySelector(".nitems").textContent = items
}
// Mouse Moves
function displayData(){
var keep = document.querySelector(".curser")
keep.style.display = "grid";
keep.style.background = "white";
document.querySelector("body").addEventListener("mouseleave",removeData)
}
document.querySelector(".mouse").addEventListener("mouseover",displayData)
function removeData(){
var keep = document.querySelector(".curser")
keep.style.display = "none";
}
document.querySelector("body").addEventListener("mouseleave",removeData)