forked from Prathamesh52-28/Boat_project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
product1.js
343 lines (308 loc) · 11.2 KB
/
product1.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
var productsList= [
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/m1_dac5a6b1-7937-4cdf-be70-76bb5a1fcf49_600x.png?v=1639153081",
name: "Rockerz 333 Pro",
rev: "4.9 | 154 reviews",
disc:"40% off",
price: "1799",
strikedoffprice: "2990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/1_5_600x.png?v=1655534211",
name: "Rockerz 450 DC edition",
rev: "5.0 | 4 reviews",
disc:"62% off",
price: "1499",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/2_3_f3ee5c27-4f14-4159-9fb2-dc60e7d6ec66_600x.png?v=1655536230",
name: "Rockerz 450",
rev: "4.9 | 8 reviews",
disc:"62% off",
price: "1499",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/0cfa4417-0213-4b49-b78e-0ae68aeb7057_600x.png?v=1625046144",
name: "Rockerz 550",
rev: "4.8 | 354 reviews",
disc:"64% off",
price: "1799",
strikedoffprice: "4999",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/m2_600x.png?v=1639124121",
name: "Rockerz 330 Pro",
rev: "4.9 | 47 reviews",
disc:"40% off",
price: "1799",
strikedoffprice: "2990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/rockerz-518-blue_600x.png?v=1613731627",
name: "Rockerz 518",
rev: "4.9 | 154 reviews",
disc:"67% off",
price: "1299",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/3_6cd803a8-4aa4-48bd-95a7-b11d1f9fdeda_600x.png?v=1655888225",
name: "Rockerz 460",
rev: "4.9 | 27 reviews",
disc:"28% off",
price: "1799",
strikedoffprice: "2490",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/5d5377dc-d3dd-48ba-8ec9-2a1630146d8d_600x.png?v=1625045983",
name: "Rockerz 510",
rev: "4.8 | 142 reviews",
disc:"54% off",
price: "1599",
strikedoffprice: "3490",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/eb8e0fbd-c412-48b3-9c91-5b49ddf35800_17432771-6821-4dbf-86ac-9cb7c8dfe460_600x.png?v=1658829303",
name: "Rockerz 450R",
rev: "5.0 | 10 reviews",
disc:"67% off",
price: "1299",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/e5881832-36f8-4c1c-a767-10f2c2a55a02_600x.png?v=1625046573",
name: "Rockerz 370",
rev: "4.8 | 89 reviews",
disc:"52% off",
price: "1199",
strikedoffprice: "2499",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/0cfa4417-0213-4b49-b78e-0ae68aeb7057_18fb3b69-5601-4680-a06c-b2a4c1a1343e_600x.png?v=1629538793",
name: "Rockerz 558",
rev: "5.0 | 2 reviews",
disc:"60% off",
price: "2999",
strikedoffprice: "4990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/main-img3_600x.png?v=1616562632",
name: "Rockerz 450 Pro",
rev: "4.7 | 67 reviews",
disc:"50% off",
price: "1999",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/06bd8915-8db7-4575-9558-c97bf050d8d7_600x.png?v=1625044994",
name: "Rockerz 400",
rev: "4.8 | 95 reviews",
disc:"50% off",
price: "1499",
strikedoffprice: "2990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/eb8e0fbd-c412-48b3-9c91-5b49ddf35800_600x.png?v=1625045744",
name: "Rockerz 450",
rev: "4.8 | 266 reviews",
disc:"67% off",
price: "1299",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/1acf35c5-1ef2-4d34-859f-e085681e6d08_600x.png?v=1625046395",
name: "Rockerz 560",
rev: "4.8 | 18 reviews",
disc:"57% off",
price: "1699",
strikedoffprice: "3990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/main2_b66dce6b-710d-49cb-9d1c-2bc8c9c0ab15_600x.png?v=1645698328",
name: "Rockerz 425",
rev: "4.9 | 22 reviews",
disc:"53% off",
price: "1399",
strikedoffprice: "2990",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/48b829ed-bee6-492e-b9bc-1824d5c63bd4_1aa0a835-9bbd-432c-ad92-76d0c2b7a36d_600x.png?v=1646390147",
name: "TRebel Rockerz 550",
rev: "5.0 | 6 reviews",
disc:"60% off",
price: "1999",
strikedoffprice: "4999",
save: "Save ₹15 more on UPI payment",
},
{
img_link: "https://cdn.shopify.com/s/files/1/0057/8938/4802/products/fd0e55b0-ca9e-4aa8-b94f-5cca99189951_600x.png?v=1625045647",
name: "Rockerz 600",
rev: "4.8 | 34 reviews",
disc:"50% off",
price: "1999",
strikedoffprice: "3990",
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)