-
Notifications
You must be signed in to change notification settings - Fork 4
/
cart.html
414 lines (370 loc) · 14.4 KB
/
cart.html
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script
src="https://kit.fontawesome.com/e9a5a74c45.js"
crossorigin="anonymous"
></script>
<link rel="stylesheet" href="./style/cart.css" />
<link rel="stylesheet" href="./style/common.css" />
<title>Document</title>
</head>
<body>
<div id="head">
<header>
<svg height="32" width="181" color="#FF1F2C" viewBox="0 0 164 29">
<g fill="none" fill-rule="evenodd">
<g fill="#000">
<path
d="M164 23.126h-.274v-1.96h-.01l-.764 1.96h-.178l-.763-1.96H162v1.96h-.275v-2.188h.506l.631 1.617h.01l.622-1.617H164v2.188zm-2.684-1.98h-.705v1.98h-.274v-1.98h-.705v-.208h1.684v.208zM34.58 14.78c0 3.558 1.94 7.117 5.855 7.117 3.914 0 5.855-3.559 5.855-7.118 0-3.558-1.94-7.117-5.855-7.117-3.915 0-5.856 3.559-5.856 7.117m13.75 0c0 4.788-2.783 8.833-7.894 8.833-5.112 0-7.894-4.045-7.894-8.833s2.782-8.831 7.894-8.831c5.111 0 7.894 4.043 7.894 8.831M47.965 6.433h2.264l5.241 14.655h.065l5.176-14.655h2.103L56.57 23.126h-2.167zM75.506 13.615C75.409 10.54 73.5 7.662 70.2 7.662c-3.332 0-5.176 2.912-5.5 5.953h10.806zM64.7 15.329c.032 2.977 1.585 6.568 5.5 6.568 2.977 0 4.594-1.747 5.24-4.27h2.04c-.874 3.785-3.074 5.984-7.28 5.984-5.306 0-7.538-4.076-7.538-8.832 0-4.4 2.232-8.831 7.538-8.831 5.37 0 7.506 4.69 7.344 9.381H64.7zM98.486 11.318c-.097-2.524-2.038-3.656-4.367-3.656-1.812 0-3.947.712-3.947 2.88 0 1.811 2.07 2.458 3.462 2.814l2.717.615c2.33.355 4.756 1.714 4.756 4.626 0 3.623-3.591 5.015-6.697 5.015-3.883 0-6.535-1.812-6.859-5.889h2.039c.162 2.75 2.2 4.174 4.917 4.174 1.91 0 4.562-.841 4.562-3.17 0-1.941-1.812-2.589-3.656-3.042l-2.62-.582c-2.653-.712-4.66-1.618-4.66-4.465 0-3.397 3.333-4.69 6.277-4.69 3.332 0 5.985 1.747 6.114 5.37h-2.038zM106.109 6.433h3.397v1.714h-3.397v11.259c0 1.326.194 2.103 1.65 2.2.582 0 1.165-.033 1.747-.097v1.747c-.615 0-1.197.064-1.812.064-2.718 0-3.656-.905-3.623-3.752V8.148h-1.973V6.432h1.973V1.419h2.038v5.014zM111.924 14.78c0 3.558 1.941 7.117 5.856 7.117s5.856-3.559 5.856-7.118c0-3.558-1.941-7.117-5.856-7.117s-5.856 3.559-5.856 7.117m13.75 0c0 4.788-2.783 8.833-7.894 8.833-5.111 0-7.894-4.045-7.894-8.833s2.783-8.831 7.894-8.831c5.111 0 7.894 4.043 7.894 8.831M140.117 11.674c-.55-2.491-2.07-4.012-4.723-4.012-3.915 0-5.856 3.559-5.856 7.117 0 3.56 1.94 7.118 5.856 7.118 2.523 0 4.594-1.974 4.852-4.756h2.038c-.55 4.012-3.17 6.47-6.89 6.47-5.112 0-7.894-4.043-7.894-8.832 0-4.788 2.782-8.832 7.894-8.832 3.559 0 6.308 1.91 6.761 5.727h-2.038zM144.425.027h2.038v14.494l9.253-8.088h2.717l-7.117 6.179 7.603 10.514h-2.556l-6.6-9.09-3.3 2.75v6.34h-2.038zM87.083 6.28c-2.342.324-4.105 1.796-4.981 4.067h-.065V6.433H80.16v16.693H82.2V14.23c0-3.03 1.931-5.488 4.884-5.926V6.28z"
></path>
</g>
<g fill="#FF1F2C">
<path
d="M.666.06v14.66C2.828 8.896 8.816 4.443 14.9 4.443c6.74 0 11.04 5.464 9.609 12.202-1.105 5.195-5.295 9.628-10.243 11.388h14.374V.061H.666z"
></path>
<path
d="M20.04 16.645c0-5.824-3.463-10.547-7.734-10.547s-7.734 4.723-7.734 10.547c0 5.825 3.463 10.547 7.734 10.547s7.734-4.722 7.734-10.547"
></path>
</g>
</g>
</svg>
<div id="search">
<input type="text" placeholder="Search" />
<i class="fa-solid fa-magnifying-glass search-icon"></i>
</div>
<div id="user-account">
<i class="fa-regular fa-user user-icon"></i>
<p>Account</p>
<div id="tooltip">
<ul>
<li class="fullWidth">
<h2>
Sign In
<i class="fa-solid fa-chevron-right"></i>
</h2>
</li>
<li>View your account and check your order status.</li>
</ul>
<ul>
<li class="fullWidth">
<h2>
Create An Account
<i class="fa-solid fa-chevron-right"></i>
</h2>
</li>
<li>Track orders, save items to lists and more!</li>
</ul>
<ul>
<li>My Account</li>
<li>My Order</li>
<li>My Reviews</li>
<li>Help</li>
</ul>
</div>
</div>
<div id="user-list">
<i class="fa-regular fa-heart user-icon"></i>
<p>List</p>
<div id="tooltip">
<ul>
<li>Favourites</li>
<li>Save for Later</li>
</ul>
<ul>
<li>View All My Lists</li>
<li>Find My List</li>
</ul>
</div>
</div>
<div id="user-cart">
<i class="fa-solid fa-cart-shopping user-icon"></i>
<p>Cart</p>
</div>
</header>
<nav>
<ul>
<li>Furniture</li>
<li>Rugs</li>
<li>Decor</li>
<li>Bed & Bath</li>
<li>Home Improvement</li>
<li>Kitchen</li>
<li>Outdoor</li>
<li>Jewelry</li>
<li>Lighting</li>
<li>Kids & Baby</li>
<li>More</li>
</ul>
<div id="breakLine"></div>
<ul>
<li>Ideas</li>
<li class="crimson">Sales & Deals</li>
</ul>
</nav>
</div>
<!-- main content starts from here -->
<main>
<p style="width: 90%; margin: auto; font-size: 28px">Shopping Cart</p>
<div id="container">
<div id="cartList"></div>
<div id="otherInfos"></div>
</div>
</main>
<!-- main content ends here -->
<footer>
<div id="footlinks">
<ul>
<li><h2>MY ACCOUNT</h2></li>
<li>Orders & Returns</li>
<li>Email Preferences</li>
<li>Account Settings</li>
</ul>
<ul>
<li><h2>LET US HELP</h2></li>
<li>Customer Care</li>
<li>Shipping Information</li>
<li>Return Policy</li>
<li>International Help</li>
<li>Accessibility</li>
</ul>
<ul>
<li><h2>COMPANY INFORMATION</h2></li>
<li>About Overstock™</li>
<li>Contact Us</li>
<li>Careers</li>
<li>Investors Relations</li>
<li>Sell Your Products</li>
<li>Supply Chain Transparency</li>
</ul>
<ul>
<li><h2>MORE WAYS TO HELP</h2></li>
<li>Tips & Ideas</li>
<li>Deals</li>
<li>Clearance</li>
<li>New Arrivals</li>
</ul>
</div>
<div id="endCredits">
<div id="address">
<p>© Copyright 2022, Overstock.com®, Inc.</p>
<p>799 Coliseum Way Midvale, UT 84047 | 1-800-843-2446</p>
</div>
<div id="additionalLinks">
<ul>
<li>Privacy Policy</li>
<li>Terms & Conditions</li>
<li>*Promotion Terms</li>
<li>
Ship To:
<img
src="https://ak1.ostkcdn.com/img/mxc/intFlag_IN.gif"
alt=""
/>
</li>
</ul>
</div>
</div>
</footer>
</body>
</html>
<script>
var cartData = JSON.parse(localStorage.getItem("cartData")) || [];
// console.log(cartData);
displayData(cartData);
function displayData(cartData) {
document.querySelector("#cartList").innerHTML = "";
if (cartData.length == 0) {
var card = document.createElement("div");
card.style.height = "260px";
card.style.padding = "20px";
var emptyText = document.createElement("div");
emptyText.innerText = "Your cart is empty.";
emptyText.style.height = "100%";
emptyText.style.width = "100%";
emptyText.style.display = "flex";
emptyText.style.alignItems = "center";
emptyText.style.justifyContent = "center";
emptyText.style.fontSize = "24px";
card.append(emptyText);
document.querySelector("#cartList").append(card);
}
cartData.map(function (el, i) {
// this is for cartList
var card = document.createElement("div");
card.style.height = "260px";
card.style.padding = "20px";
var img = document.createElement("img");
img.src = el.img;
var div2 = document.createElement("div");
var name = document.createElement("p");
name.innerText = el.name;
var price = document.createElement("h2");
price.innerText = `Sale INR ${el.price}`;
price.style.color = "#ac1b25";
price.style.fontSize = "20px";
price.style.margin = "20px 0 40px";
var select = document.createElement("select");
var opt1 = document.createElement("option");
opt1.value = "1";
opt1.innerText = "Quantitiy: 1";
var opt2 = document.createElement("option");
opt2.value = "2";
opt2.innerText = "Quantitiy: 2";
var opt3 = document.createElement("option");
opt3.value = "3";
opt3.innerText = "Quantitiy: 3";
var opt4 = document.createElement("option");
opt4.value = "4";
opt4.innerText = "Quantitiy: 4";
var opt5 = document.createElement("option");
opt5.value = "5";
opt5.innerText = "Quantitiy: 5";
select.append(opt1, opt2, opt3, opt4, opt5);
select.style.width = "fit-content";
// select.style.margin = "20px 0";
select.value = el.qty;
select.addEventListener("change", function () {
changeQty(el);
});
div2.style.position = "relative";
var remove = document.createElement("button");
remove.innerText = "Remove";
remove.style.width = "fit-content";
remove.style.padding = "5px 10px";
remove.style.position = "absolute";
remove.style.bottom = "0";
remove.addEventListener("click", function () {
removeFromCart(i);
});
div2.append(name, price, select, remove);
card.append(img, div2);
document.querySelector("#cartList").append(card);
// this is for otherInfos
});
}
// function display()
function changeQty(el) {
el.qty = Number(event.target.value);
localStorage.setItem("cartData", JSON.stringify(cartData));
// console.log(cartData);
displayPrice();
}
// console.log(cartData);
function removeFromCart(i) {
cartData.splice(i, 1);
alert("Item removed from Cart.");
localStorage.setItem("cartData", JSON.stringify(cartData));
displayData(cartData);
displayPrice();
}
displayPrice();
function displayPrice() {
document.querySelector("#otherInfos").innerHTML = "";
var cartData = JSON.parse(localStorage.getItem("cartData"));
// console.log(cartData);
var total = cartData.reduce(function (a, b) {
return (a += b.price * b.qty);
}, 0);
var count = cartData.reduce(function (a, b) {
return (a += b.qty);
}, 0);
if (cartData.length == 0) {
var table = document.createElement("table");
var tr1 = document.createElement("tr");
var td1 = document.createElement("td");
td1.style.fontWeight = "bold";
var td2 = document.createElement("td");
td2.style.fontWeight = "bold";
td1.innerText = `(0) Items:`;
td2.innerText = `INR 0`;
var tr2 = document.createElement("tr");
var td3 = document.createElement("td");
var td4 = document.createElement("td");
td3.innerText = "Promotional Savings:";
td4.innerText = "-INR 0";
td4.style.color = "#c7202c";
var tr3 = document.createElement("tr");
var td5 = document.createElement("td");
var td6 = document.createElement("td");
td5.innerText = "Subtotal After Discounts:";
td6.innerText = `INR 0`;
var checkOut = document.createElement("button");
checkOut.innerHTML = "Check Out";
checkOut.style.color = "white";
checkOut.style.backgroundColor = "black";
checkOut.style.width = "100%";
checkOut.style.padding = "10px";
checkOut.style.fontSize = "20px";
checkOut.style.marginTop = "20px";
checkOut.style.marginBottom = "20px";
checkOut.addEventListener("click", function () {
alert("Your cart is empty.");
});
td5.style.fontWeight = "bold";
td6.style.fontWeight = "bold";
var finalPrice = document.createElement("h2");
finalPrice.style.textAlign = "center";
finalPrice.style.marginTop = "20px";
finalPrice.innerText = `Your Total: INR 0`;
tr1.append(td1, td2);
tr2.append(td3, td4);
tr3.append(td5, td6);
table.append(tr1, tr2, tr3);
document.querySelector("#otherInfos").append(table, finalPrice, checkOut);
}
// console.log(count);
cartData.map(function () {
document.querySelector("#otherInfos").innerHTML = "";
var table = document.createElement("table");
var tr1 = document.createElement("tr");
var td1 = document.createElement("td");
td1.style.fontWeight = "bold";
var td2 = document.createElement("td");
td2.style.fontWeight = "bold";
td1.innerText = `(${count}) Items:`;
td2.innerText = `INR ${total}`;
var tr2 = document.createElement("tr");
var td3 = document.createElement("td");
var td4 = document.createElement("td");
td3.innerText = "Promotional Savings:";
td4.innerText = "-INR 0";
td4.style.color = "#c7202c";
var tr3 = document.createElement("tr");
var td5 = document.createElement("td");
var td6 = document.createElement("td");
td5.innerText = "Subtotal After Discounts:";
td6.innerText = `INR ${total}`;
var checkOut = document.createElement("button");
checkOut.innerHTML = "Check Out";
checkOut.style.color = "white";
checkOut.style.backgroundColor = "black";
checkOut.style.width = "100%";
checkOut.style.padding = "10px";
checkOut.style.fontSize = "20px";
checkOut.style.marginTop = "20px";
checkOut.style.marginBottom = "20px";
checkOut.addEventListener("click", function () {
paymentPage(total);
});
td5.style.fontWeight = "bold";
td6.style.fontWeight = "bold";
var finalPrice = document.createElement("h2");
finalPrice.style.textAlign = "center";
finalPrice.style.marginTop = "20px";
finalPrice.innerText = `Your Total: INR ${total}`;
tr1.append(td1, td2);
tr2.append(td3, td4);
tr3.append(td5, td6);
table.append(tr1, tr2, tr3);
document.querySelector("#otherInfos").append(table, finalPrice, checkOut);
});
}
function paymentPage(total) {
window.open("./payment.html");
}
</script>
<script src="./script/common.js"></script>