-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathproduct-page.js
281 lines (211 loc) · 8.08 KB
/
product-page.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
var Products_page = [
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1649963382/f6t1ibz3qh3ag0o486xv.jpg",
name: "Tata 1mg Immunity & Wellness Supplement Tablet ",
quantity: "bottle of 60 capsules",
Ratings: "4.6☆",
strikedoffprice: 99,
offprice: '10 % Off',
price: 89,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1642507775/gmkrpf1imjj9djwvq4gq.jpg",
name: "Tata 1mg Multivitamin Supreme,Zinc, Calcium and Vitamin D...",
quantity: "bottle of 60 capsules",
Ratings: "4.1☆",
strikedoffprice: 995,
offprice: '55 % Off',
price: 448,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1637323384/niilbcbb6dm0tkxvjzvg.jpg",
name: "NutriBears Multivitamin Growth & Immunity Support Gummies..",
quantity: "bottle of 30 gummies ",
Ratings: "4.7☆",
strikedoffprice: 399,
offprice: '5 % Off',
price: 376,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1653417013/ibcufhk27uqhpgy9kfcg.jpg",
name: "Zincovit Tablets",
quantity: "Strip of 15 Tablets",
Ratings: "4.5☆",
strikedoffprice: 105,
offprice: '15 % Off',
price: 89,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1653417158/rjl5upkgyuexb7pl1olo.jpg",
name: "Shelcal 500 Tablet",
quantity: "Strip of 15 Tablets",
Ratings: "4.5☆",
strikedoffprice: 119.5,
offprice: '16 % Off',
price: 100,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1642507827/fwram2p7rbkoigjg6zas.jpg",
name: "Tata 1mg Salmon Omega 3 Fish Oil Capsule",
quantity: "bottle of 60 capsules",
Ratings: "4.4☆",
strikedoffprice: 995,
offprice: '55 % Off',
price: 448,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1632312417/sftqra1arzgoufnxvfgz.jpg",
name: "Evion 400mg Capsules",
quantity: "strip of 10 capsules",
Ratings: "4.3☆",
strikedoffprice: 50,
offprice: '21 % Off',
price: 35.9,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1632312844/jpr9uwzjgcnvmspmqwgp.jpg",
name: "Neurobion XT Tablets",
quantity: "strip of 30 tablets",
Ratings: "4.2☆",
strikedoffprice: 172.5,
offprice: '15 % Off',
price: 146,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1600084831/cropped/fx9yieiiwdk6t3fbwii1.jpg",
name: "Orofer XT Capsule",
quantity: "strip of 10 tablets",
Ratings: "4.2☆",
strikedoffprice: 51,
offprice: '22 % Off',
price: 34.7,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1653417142/dqsctsosbmzve5bhnlkj.jpg",
name: "New A to z Gold Soft Gelatin Capsule",
quantity: "strip of 15 soft gelatin capsules",
Ratings: "4.5☆",
strikedoffprice: 180,
offprice: '15 % Off',
price: 153,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1632312306/r4bjtkdzxnzlrfvdmaps.jpg",
name: "Seven Seas Original Cod-Liver oil Capsule",
quantity: "bottle of 100 soft gelatin capsules",
Ratings: "4.5☆",
strikedoffprice: 320.9,
offprice: "7 % Off",
price: 298,
button: "ADD",
},
{
image_url:
"https://onemg.gumlet.io/image/upload/a_ignore,w_380,h_380,c_fit,q_auto,f_auto/v1625118755/lnokjri7seuxwnv2qbwy.jpg",
name: "Revital H Capsule",
quantity: "bottle of 60 soft gelatin capsules",
Ratings: "4.4☆",
strikedoffprice: 550,
offprice: "12 % Off",
price: 484,
button: "ADD",
},
]
function handleSort() {
let selected = document.querySelector("#sort").value;
if (selected == "dec") {
Products_page.sort(function (a, b) {
return ((+b.price) - (+a.price))
})
displaydiv(Products_page)
}
if (selected == "inc") {
Products_page.sort(function (a, b) {
return ((+a.price) - (+b.price))
})
displaydiv(Products_page)
}
}
displaydiv(Products_page)
let cartArr = JSON.parse(localStorage.getItem("Pcart")) || []
function displaydiv(Products_page) {
document.querySelector("#container").innerHTML = "";
let maindiv = document.querySelector("#container")
Products_page.forEach(function (el) {
let innerdiv = document.createElement("div")
let productPic = document.createElement("img");
productPic.src = el.image_url;
let productName = document.createElement("h4");
productName.innerText = el.name
let productQuantity = document.createElement("p");
productQuantity.innerText = el.quantity
let rating = document.createElement("h4");
rating.innerText = el.Ratings
let productPrice = document.createElement("div");
let str = document.createElement("p")
str.innerText = "MRP "
let strikeprice = document.createElement("p")
strikeprice.innerText = el.strikedoffprice
let dis = document.createElement("p")
dis.innerText = el.offprice
productPrice.append(str, strikeprice, dis)
let bottomdiv = document.createElement("div")
let pprice = document.createElement("p")
pprice.innerText = "₹ " + el.price
let btn = document.createElement("p");
btn.innerText = el.button
bottomdiv.append(pprice, btn)
btn.addEventListener("click", function () {
cartFunction(el)
})
innerdiv.append(productPic, productName, productQuantity, rating, productPrice, bottomdiv)
maindiv.append(innerdiv)
})
document.querySelector("body").append(maindiv)
}
function cartFunction(el) {
let cartObj = {
pic: el.image_url,
pname: el.name,
price: el.price
}
if (checkCart(cartObj.pname) === true) {
cartArr.push(cartObj);
localStorage.setItem("Pcart", JSON.stringify(cartArr))
alert("Product Added to Cart Successfully")
} else {
alert("Product Already in the Cart")
}
}
function checkCart(name) {
let filtered = cartArr.filter(function (el) {
return name === el.pname
});
if (filtered.length > 0) {
return false;
}
else {
return true;
}
}