-
Notifications
You must be signed in to change notification settings - Fork 0
/
cartpage.html
572 lines (516 loc) · 21.3 KB
/
cartpage.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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<!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">
<title>cartpage</title>
<link rel="stylesheet" href="./css/navbar.css">
<link rel="stylesheet" href="./css/footer.css">
<script src="https://kit.fontawesome.com/0d69f46662.js" crossorigin="anonymous"></script>
<style>
#cart{
background-color: #e0d5c5;
padding-top: 50px;
padding-bottom: 50px;
}
#parent {
width: 70%;
margin: auto;
padding-bottom: 100px;
background-color:white;
}
#checkbox {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
padding: 12px;
border-radius: 10px;
margin: 30px 0;
}
#cartNav{
display: flex;
flex-direction: row;
justify-content: space-between;
}
#cartNav > button:first-child {
width: 5%;
/* margin: 30px; */
margin: 16px 5px 25px 15px;
color: white;
font-weight: bold;
background-color: rgb(189, 24, 24);
text-decoration-line: none;
border-color: white;
}
#cartNav > button:last-child {
width: 65px;
margin: 18px 12px 20px 13px;
color: white;
font-weight: bold;
background-color: rgb(189, 24, 24);
text-decoration-line: none;
border-color: white;
}
#checkbox>p {
color: white;
margin: 0;
}
#checkbox>a>button {
/* background-color: red; */
color: black;
border: none;
border-radius: 8px;
padding: 5px 20px;
}
#parent>div>h1{
text-align: center;
}
#parent>div>h4{
text-align: center;
}
#parent>div>button{
display: block;
margin: 0 auto;
width:98%;
border-radius: 15px;
padding: 5px;
justify-content: center;
background-color:rgb(189, 24, 24);
border-color: rgb(134, 133, 133);
}
#cartDiv{
display: flex;
flex-direction: column;
margin: 20px 10px 5px 10px;
box-shadow: rgba(50, 50, 93, 0.25) 0px 13px 27px -5px, rgba(0, 0, 0, 0.3) 0px 8px 16px -8px;
}
#cartDiv > img{
width:30%;
}
.product-container {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0px 10px 0 10px;
margin: 5px;
box-shadow: rgba(0, 0, 0, 0.05) 0px 6px 24px 0px, rgba(0, 0, 0, 0.08) 0px 0px 0px 1px;
}
.product-container > div:first-child{
display: flex;
flex-direction: column;
margin-right:2px;
}
.product-container > img{
width:30%;
}
.product-container > div:last-child {
margin-left: auto;
display: flex;
flex-direction: column;
text-align: center;
}
.product-container > div:last-child > button:first-child {
width: 10%;
padding-left: 15px;
padding-right: 15px;
margin: auto;
text-align:center;
background-color:rgb(189, 24, 24);
color:white;
font-weight: bold;
cursor: pointer;
}
.product-container > div:last-child > button:last-child {
width: 10%;
padding-left: 15px;
padding-right: 15px;
margin: auto;
text-align:center;
background-color:black;
color:white;
font-weight: bold;
cursor: pointer;
}
#checkout {
width:98%;
display: flex;
margin:auto;
flex-direction: column;
box-shadow: rgba(0, 0, 0, 0.05) 0px 6px 24px 0px, rgba(0, 0, 0, 0.08) 0px 0px 0px 1px;
}
#checkout > div:first-child{
display: flex;
flex-direction: row;
justify-content: space-between;
}
#checkout > div:first-child > p{
margin-left: 10px;
margin-right: 10px;
}
#checkout > div:last-child{
text-align: center;
}
#checkout > div:last-child > a > button{
/* font-weight: bold; */
width: 100%;
background-color: black;
color: rgb(216, 207, 189);
padding: 5px;
font-size: larger;
width: 100%;
margin-bottom: 10px;
cursor: pointer;
}
#giftCheck{
margin: 5px 0 20px 12px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="navbar-container">
<header class="page-header">
<div class="header-container">
<div class="Full-header">
<div class="logo-container">
<div class="logo-container-box">
<a class="logo" href="index.html">
<img src="https://www.bialetti.com/media/logo/default/5-layers_3x.png" alt="Bialetti">
</a>
</div>
</div>
<div class="menu-container">
<div class="Header-menu">
<a class="menu-name" href="#">MOKA EXPRESS</a>
</div>
<div class="Header-menu">
<a class="menu-name" href="#">BIALETTI COFFEE ROASTING</a>
</div>
<div class="Header-menu dropdown">
<a href="./product.html">
<button class="dropbtn">PRODUCTS
<i class="fa-solid fa-angle-down"></i>
</button>
</a>
<div class="dropdown-content">
<div class="row">
<div class="column">
<h3 class="column-h3">COFFEE</h3>
<a href="#">Grounds</a>
<a href="#">Coffee beans</a>
</div>
<div class="column">
<div class="vl"></div>
<h3 class="column-h3">COFFEE MAKERS</h3>
<a href="#">Aluminium coffee makers</a>
<a href="#">Stainless steal coffee makers</a>
<a href="#">Special coffee makers</a>
</div>
<div class="column">
<div class="vl"></div>
<h3 class="column-h3">ACCESSORIES</h3>
<a href="#">Small cups and mugs</a>
<a href="#">Coffee accessories</a>
<a href="#">Spare Parts</a>
</div>
<div class="column">
<div class="vl"></div>
<img class="column-img" src="https://www.bialetti.com/media/wysiwyg/moka-express-menu.jpg" alt="Coffee">
</div>
</div>
</div>
</div>
<div class="Header-menu dropdown">
<button class="dropbtn">NEWS
<i class="fa-solid fa-angle-down" id="fa-down"></i>
</button>
<div class="dropdown-content-2">
<div class="column-2">
<a href="#">Small cups and mugs</a>
<a href="#">Coffee accessories</a>
</div>
</div>
</div>
<div class="Header-menu">
<a class="menu-name" href="#">INSPIRATION</a>
</div>
<div class="Header-menu">
<a class="menu-name" href="#">OUR HISTORY</a>
</div>
</div>
<div class="icon-container">
<button id="magniglass" >
<a href="#">
<i class="fa-solid fa-magnifying-glass"></i>
</a>
</button>
<button onclick="document.getElementById('login-form').style.display='block'">
<a href="#">
<i class="fa-solid fa-user"></i>
</a>
</button>
<button>
<a href="#">
<i class="fa-solid fa-cart-plus"></i>
</a>
</button>
<button id = "open" >
<a href="#">
<i class="fa-solid fa-bars"></i>
</a>
</button>
<form id="search-bar" >
<input type="text" id="search" placeholder="Search entire store here...">
</form>
</div>
</div>
</div>
</header>
<div id='login-form'class='login-page'>
<div class="form-box">
<div class='button-box'>
<div id='btn'></div>
<button type='button'onclick='login()'class='toggle-btn'>Log In</button>
<button type='button'onclick='register()'class='toggle-btn'>Register</button>
</div>
<form id='login' class='input-group-login'>
<input type='text'class='input-field' id='login-email' placeholder='Email Id' required >
<input type='password'class='input-field' id='login-pass' placeholder='Enter Password' required>
<span class='input-field-2' id="password-error" style="display:none;color:red;">Email and/or password incorrect.</span>
<input type='checkbox'class='check-box'><span>Remember Password</span>
<button type='submit'class='submit-btn'>Log in</button>
</form>
<form id='register' class='input-group-register'>
<input type='text' id="firstname" class='input-field'placeholder='First Name' required>
<input type='text' id="lastname" class='input-field'placeholder='Last Name ' required>
<input type='email'id="regisemail" class='input-field'placeholder='Email Id' required>
<input type='password' id="resipass" class='input-field'placeholder='Enter Password' required>
<input type='password' id="resirepass" class='input-field'placeholder='Confirm Password' required>
<input type='checkbox'class='check-box' required><span>I agree to the terms and conditions</span>
<span id="email-exists" class='input-field-2' style="display:none;"></span>
<button type='submit'class='submit-btn'>Register</button>
</form>
</div>
</div>
</div>
<div class="w3-sidebar w3-bar-block w3-collapse w3-card w3-animate-left" id="mySidebar">
<button id="closebtn" class="w3-bar-item w3-button w3-large w3-hide-large" >
<i class="fa-solid fa-xmark"></i>
</button>
<a id="sidebar-1a" href="#" class="w3-bar-item w3-button">THE GROUP <i class="fa-solid fa-chevron-down"></i></a>
<a href="#" class="w3-bar-item w3-button">INVESTOR RELATION </a>
<a href="#" class="w3-bar-item w3-button">SUSTAINABILITY <i class="fa-solid fa-chevron-down"></i></a>
<a href="#" class="w3-bar-item w3-button">CAREERS</a>
<a href="#" class="w3-bar-item w3-button">CONTACT US</a>
<div class="follow-logo">
<p>Follow US:</p>
<div><i class="fa fa-facebook" aria-hidden="true"></i></div>
<div><i class="fa fa-instagram" aria-hidden="true"></i></div>
</div>
</div>
</div>
<div id="cart">
<div id="parent">
<div>
<div id="cartNav">
<button><</button>
<h1>MY CART<span id="countitems"></span></h1>
<button id="clearCart">Clear cart </button>
</div>
<h4 id="freeShippingText"></h4>
<button id="just_for_design"></button>
<div id="cartDiv">
</div>
<input type="checkbox" id="giftCheck" value="gift" onclick="giftBoxCheck()">
<label for="checkBox"> This order is a gift</label><br>
<div id="checkout">
<div><p>Subtotal : </p>
<p id="showtotal">0</p>
</div>
<div><a href="paymentPage.html"><button id="checkoutBtn">CHECKOUT</button></a></div>
</div>
</div>
</div>
</div>
<footer>
<div>
<div id="contact_container">
<div>
<div class="contact">
<img src="https://www.bialetti.com/media/wysiwyg/logo-footer_4x.png" alt="">
<p>The essence of <br>
Italian coffee culture.</p>
</div>
<p>
<span id="address">
Registered Office
</span>
<br>
25030 Coccaglio BS
<br>
Via Fogliano, 1
<br>
Italia
</p>
<button id="contact-btn">
<i class="fa-solid fa-pen"></i>
CONTACT US
</button>
</div>
<div class="legal">
<h4><a href="">Legal</a> </h4>
<ul>
<li><a href="">Cookies</a></li>
<li><a href="">Privacy Policy</a></li>
<li><a href="">Terms and conditions</a></li>
<li><a href="">B2B</a></li>
</ul>
</div>
</div>
<hr>
<div class="footer-bottom">
<div>
<div class="tags">
<a href="">About Us</a>
<a href="">Our history</a>
<a href="">Work with us</a>
</div>
<div class="bottom-para">
<p>
2021 © Bialetti Industrie S.p.A. / Cap. Soc. i.v. Euro 1.041.628,00 / Cod.Fisc., P.IVA e numero d’iscrizione al Registro delle Imprese di Brescia 03032320248
</p>
</div>
</div>
<div class="social-icons">
<a class="icons" href="https://www.facebook.com/Bialetti/" target="_blank"><i class="fa-brands fa-facebook-f"></i></a>
<a class="icons" href="https://www.instagram.com/bialetti/" target="_blank"><i class="fa-brands fa-instagram"></i></a>
</div>
</div>
</div>
</footer
<script src="./js/navbar.js"></script>
</body>
</html>
<script>
const cartDiv = document.querySelector("#cartDiv");
let id = localStorage.getItem("cartId")
getProductData(id);
// console.log(id)
async function getProductData(id){
try {
const res = await fetch(`https://bialettiserver.onrender.com/products?id=${id}`);
const data = await res.json();
// console.log(data);
displayProductData(data);
} catch (err) {
console.log("Error: fetching in product data");
}
}
const displayProductData = (data) => {
var count=0;
var sum=0;
data.forEach(product => {
const productDiv = document.createElement('div')
productDiv.classList.add('product-container');
const image = document.createElement('img');
image.src = product.img1;
const detailDiv = document.createElement('div')
const name = document.createElement('h2');
name.textContent = product.product_name;
detailDiv.appendChild(name);
const price = document.createElement('p');
price.textContent = `Price: $${product.price}`;
detailDiv.appendChild(price);
const quantityDiv = document.createElement('div')
var increase=document.createElement("button");
increase.textContent="+";
increase.onclick=function(){
increaseval(quantity);
};
function increaseval(value){
var val = parseInt(value.textContent);
var pr=val+1;
var priceVal=pr*product.price
price.textContent="Price: $"+Number(priceVal).toFixed(2);
quantity.textContent = pr
updateSubtotal();
}
quantityDiv.appendChild(increase)
var quantity = document.createElement('p')
quantity.innerHTML = '1'
quantityDiv.appendChild(quantity)
var decrease=document.createElement("button");
decrease.textContent="-";
decrease.onclick=function(){
decreaseval(quantity);
};
function decreaseval(value){
var val = parseInt(value.textContent);
if(val==1){
return ;
}else{
var pr=val-1;
var priceVal=pr*product.price
price.textContent="Price: $"+Number(priceVal).toFixed(2);
quantity.textContent = pr
}
updateSubtotal();
}
quantityDiv.appendChild(decrease)
productDiv.appendChild(image)
// productDiv.appendChild(imgDiv)
productDiv.appendChild(detailDiv)
productDiv.appendChild(quantityDiv)
cartDiv.appendChild(productDiv);
count++;
sum += product.price;
});
var countitems = document.getElementById('countitems');
countitems.textContent = "("+count+")";
var showtotal = document.getElementById("showtotal");
showtotal.textContent = "$" + sum;
// var clearC = document.getElementById("clearCart").addEventListener("click", clearWholeCart);
document.getElementById("clearCart").onclick = clearWholeCart;
function clearWholeCart() {
cartDiv.innerHTML = "";
updateSubtotal();
countitems.innerHTML = "";
}
}
function giftBoxCheck() {
var checkBox = document.getElementById("giftCheck");
var text = document.getElementById("freeShippingText");
if (checkBox.checked == true){
text.textContent = 'YOUR ORDER IS QUALIFIES FOR FREE SHIPPING!';
}
else{
text.textContent = '';
}
}
function updateSubtotal() {
var sum = 0;
var prices = document.querySelectorAll('.product-container p');
prices.forEach(price => {
var priceText = price.textContent;
var priceVal = parseFloat(priceText.substring(priceText.indexOf('$') + 1));
sum += priceVal;
});
var showTotalElement = document.querySelector("#showtotal");
showTotalElement.textContent = "$ "+sum.toFixed(2);
// Store the subtotal value in localStorage
var setSubtotal = localStorage.setItem("subtotal", sum.toFixed(2));
console.log(setSubtotal);
}
// var total = document.getElementById("subtotal").textContent;
// var subtotal = parseFloat(total.substring(total.indexOf('$') + 1));
// localStorage.setItem("subtotal", subtotal )
// console.log("subtotal value save");
document.getElementById("checkoutBtn").addEventListener("click", redirectPayment);
function redirectPayment() {
var setSubtotal = localStorage.setItem("subtotal", sum.toFixed(2));
console.log(setSubtotal);
}
// document.getElementById("checkoutBtn").addEventListener("click", redirectPayment);
</script>