-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckout.html
393 lines (367 loc) · 24.7 KB
/
checkout.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>CPE's Special Burger Checkout</title>
<link rel="stylesheet" type="text/css" href="style/checkout.css" media="screen" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/datepicker.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,300;1,400;1,500;1,600;1,700;1,800&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/1571a8b9bd.js" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/datepicker.min.js"></script>
</head>
<body>
<header id="main-header" class="container">
<div class="logo">
<img src="assets/images/Logo.png" width="200"/>
</div>
<div class="side-menu">
<h3 class="menu"><a href="/index.html" class="dark"><i class="fa-solid fa-arrow-left"></i> Add more items</a></h3>
</div>
</header>
<main>
<section id="checkout_body">
<hr class="hr--clear" />
<div class="container flex space-between checkout-body">
<div class="personal-details pr-2">
<h4 class="margin-bottom-25 login-notif pointer" onclick="open_login()">Login to your account or register.</h4>
<div id="account-modal">
<div class="modal-content padding-bottom-1rem">
<span class="close" onclick="close_modal()">×</span>
<h2>Login</h2>
<h5>Login to your account.</h5>
<small class="red secondary margin-bottom-25" id="login_error" style="display: none;"></small>
<input type="text" class="input-details width-90p" id="username" placeholder="Username"/>
<input type="password" class="input-details width-90p no-margin-bottom" id="password" placeholder="Password" />
<small class="primary">New user? <a href="#" class="dark bold">Register here.</a></small>
<br /><br />
<button class="secondary-button pointer no-margin-bottom full-width" onclick="login()">Login</button>
</div>
</div>
<h3>Personal Details</h3>
<hr class="details-border" />
<br />
<input type="text" class="input-details order-information" placeholder="Your first name" id="fname" required onkeyup="validate(this)">
<small class="error"></small>
<input type="text" class="input-details order-information" placeholder="Your last name" id="lname" required onkeyup="validate(this)">
<small class="error"></small>
<br />
<h3>Delivery Details</h3>
<hr class="details-border" />
<br />
<input type="text" class="input-details order-information" placeholder="Your street address" id="saddress" required onkeyup="validate(this)">
<small class="error"></small>
<input type="text" class="input-details order-information" placeholder="Your barangay" id="baddress" required onkeyup="validate(this)">
<small class="error"></small>
<input type="text" class="input-details order-information" placeholder="Your city" id="caddress" required onkeyup="validate(this)">
<small class="error"></small>
<input type="text" class="input-details order-information" placeholder="Your province" id="paddress" required onkeyup="validate(this)">
<small class="error"></small>
<input type="number" class="input-details order-information" placeholder="Your zip code" id="zaddress" required onkeyup="validate(this)">
<small class="error"></small>
<br />
<h3>Delivery Fee</h3>
<hr class="details-border" />
<br />
<div class="delivery-container flex align-center">
<div class="delivery-option">
<input class="delivery-information" type="radio" id="standard" name="delivery_type" value="50" onclick="recalculate_total(this.value)">
<label for="standard" class="secondary"><i class="fa-solid fa-truck"></i> Standard - ₱50.00</label><br>
</div>
<div class="delivery-option">
<input class="delivery-information" type="radio" id="express" name="delivery_type" value="180" onclick="recalculate_total(this.value)">
<label for="express" class="secondary"><i class="fa-solid fa-truck-fast"></i> Express - ₱180.00</label><br>
</div>
</div>
<small class="radio-error"></small>
<br />
<br />
<h3>Payment</h3>
<hr class="details-border" />
<br />
<div class="payments-container flex align-center space-between">
<div class="payment-option" onclick="select_payment('card')">
<h4 class="no-margin-bottom">Credit / Debit Card</h4>
<p class="secondary">Pay using VISA or Mastercard.</p>
</div>
<div class="payment-option" onclick="select_payment('ewallet')">
<h4 class="no-margin-bottom">E-Wallet</h4>
<p class="secondary">Pay using GCash, Maya, or Coins.ph.</p>
</div>
<div class="payment-option active" onclick="select_payment('cod')">
<h4 class="no-margin-bottom">Cash on Delivery</h4>
<p class="secondary">Pay using cash once your order arrives.</p>
</div>
</div>
<div id="payment-modal">
<div class="modal-content">
<span class="close" onclick="close_modal()">×</span>
<h3 id="payment_type"></h3>
<h5 id="payment_description"></h5>
<br />
<div id="payment_fields"></div>
<br />
<button class="tertiary-button pointer width-90p" onclick="close_modal()">Cancel</button>
<button class="secondary-button pointer no-margin-bottom width-90p proceed-payment" onclick="proceed_payment()">Select Payment Method</button>
</div>
</div>
<br />
<br />
<div class="checkout-buttons">
<button class="tertiary-button pointer"><a href="/index.html" class="dark">Continue Shopping</a></button>
<button class="secondary-button pointer" onclick="place_order()">Place Order</button>
</div>
</div>
<div class="order-details pr-2">
<h3>Order Details</h3>
<div id="cart_items"></div>
<div class="shipping">
<h3 class="flex space-between"><span class="shipping-title">Shipping:</span><span id="shipping_cost"></span></h3>
</div>
<div class="grand-total">
<h3 class="flex space-between"><span class="total-title">Total:</span><span id="grand_total"></span></h3>
</div>
<script>
var html = "";
var grand_total = 0;
var price = 0;
var quantity = 0;
var sub_total = 0;
// if (getCookie('shopping-cart')) {
// var cart = (typeof getCookie('shopping-cart') == 'string') ? JSON.parse(getCookie('shopping-cart')) : getCookie('shopping-cart');
// cart.forEach(function(item) {
// var cart_item = (typeof item == 'string') ? JSON.parse(item) : item;
// price = parseFloat(cart_item.price);
// quantity = parseInt(cart_item.qty);
// sub_total = price * quantity;
// html += `<div class='cart-item-container' id="cart-item-`+ cart_item.id +`">
// <div class='item-image'><img width='75' src=` + cart_item.image + ` /></div>
// <div class='item-details'>
// <h3 class='cart-item-name'>` + cart_item.name + `</h3>
// <p class='cart-details'>₱` + price.toFixed(2) + ` x ` + quantity + `</p>
// </div>
// <div class='item-price'>
// <h3 class='no-margin'>₱` + sub_total.toFixed(2) + `</h3>
// </div>
// </div>`;
// grand_total += sub_total;
// });
// document.getElementById('cart_items').innerHTML = html;
// document.getElementById("grand_total").innerHTML = "₱" + parseFloat(grand_total).toFixed(2);
// setCookie("grand_total", parseFloat(grand_total).toFixed(2));
// }
if (getCookie('shopping-cart')) {
var cart = (typeof getCookie('shopping-cart') == 'string') ? JSON.parse(getCookie('shopping-cart')) : getCookie('shopping-cart');
cart.forEach(function(item) {
var cart_item = (typeof item == 'string') ? JSON.parse(item) : item;
for (var key in cart_item) {
price = parseFloat(cart_item[key].price);
quantity = parseInt(cart_item[key].quantity);
sub_total = cart_item[key].final_price;
html += `<div class='cart-item-container' id="cart-item-`+ cart_item[key].id +`">
<div class='item-image'><img width='75' src=` + cart_item[key].image + ` /></div>
<div class='item-details'>
<h3 class='cart-item-name'>` + cart_item[key].name + `</h3>
<p class='cart-details'>₱` + price.toFixed(2) + ` x ` + quantity + `</p>`+ render_additional(cart_item[key]) +`
</div>
<div class='item-price'>
<h3 class='no-margin'>₱` + sub_total.toFixed(2) + `</h3>
<a class='red secondary small' href='#' onclick='remove_item("`+ cart_item[key].id +`")'>Remove</a>
</div>
</div>`;
grand_total += sub_total;
}
});
document.getElementById('cart_items').innerHTML = html;
document.getElementById("grand_total").innerHTML = "₱" + parseFloat(grand_total).toFixed(2);
setCookie("grand_total", parseFloat(grand_total).toFixed(2));
}
function render_additional(additional_items) {
var html = '', html1 = '<br /><p class="bold primary">Additional items</p>';
for (var key in additional_items) {
if (additional_items[key].additional_name != undefined) {
html += `<div class="additional-items-container width-60p flex space-between">
<p class='cart-details'>` + additional_items[key].proper_name + `</h3>
<p class='cart-details'>₱` + parseFloat(additional_items[key].additional_price).toFixed(2) + ` x ` + additional_items[key].additional_qty + `</p>
</div>`;
} else {
html = '';
}
}
html = html == '' ? html : html1 + html;
return html;
}
function login() {
var user = document.getElementById("username").value;
var pass = document.getElementById("password").value;
if (user == "admin" && pass == "admin") {
close_modal();
} else {
document.getElementById("login_error").innerHTML = "Wrong Username/Password. Please try again.";
document.getElementById("login_error").style.display = "block";
}
}
function proceed_payment() {
var all_inputs = document.querySelectorAll("#payment-modal input"), valid = true;
Array.from(all_inputs).forEach((inpt) => {
if (inpt.value == "") {
inpt.classList.add("input-error");
inpt.nextElementSibling.style.display = "block";
inpt.nextElementSibling.innerHTML = "Required field.";
valid = false;
} else {
inpt.classList.remove("input-error");
inpt.nextElementSibling.style.display = "none";
inpt.nextElementSibling.innerHTML = " ";
}
});
if (valid) {
close_modal();
}
}
function setCookie(cname, cvalue) {
const d = new Date();
var exdays = 30;
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function recalculate_total(shipping_fee) {
var grand_total = getCookie("grand_total");
var new_total = parseFloat(grand_total) + parseInt(shipping_fee);
document.getElementById("grand_total").innerHTML = "₱" + parseFloat(new_total).toFixed(2);
document.getElementById("shipping_cost").innerHTML = "₱" + parseFloat(shipping_fee).toFixed(2);
document.querySelector('.delivery-container').classList.remove("input-error");
document.querySelector('.delivery-container').nextElementSibling.style.display = "none";
document.querySelector('.delivery-container').nextElementSibling.innerHTML = "";
document.querySelector('.shipping').style.display = "block";
setCookie("shipping_cost", parseFloat(shipping_fee).toFixed(2));
}
function close_modal() {
document.getElementById("payment-modal").style.display = "none";
document.getElementById("account-modal").style.display = "none";
}
function select_payment(type) {
var payment_type = '', payment_description = '', payment_fields = [];
switch(type) {
case 'card':
payment_type = 'Credit / Debit Card';
payment_description = "Pay using VISA or Mastercard.";
payment_fields = ["Name on card", "Expiry Date", "Credit Card Number", "CVC"];
break;
case 'ewallet':
payment_type = 'E-wallet';
payment_description = 'Pay using GCash, Maya, or Coins.ph.';
payment_fields = ['Mobile Number'];
break;
}
document.querySelector(".proceed-payment").setAttribute("data-type", type);
document.getElementById("payment_type").innerHTML = payment_type;
document.getElementById("payment_description").innerHTML = payment_description;
var html = '';
if (type != "cod") {
document.getElementById("payment-modal").style.display = "block";
for (var key in payment_fields) {
switch(payment_fields[key]) {
case "Credit Card Number":
case "CVC":
case "Mobile Number":
html += '<input type="number" class="input-details quarter" placeholder="'+ payment_fields[key] +'" onkeyup="validate(this)" required><small class="error"></small>';
break;
case "Expiry Date":
html += '<input type="date" class="input-details quarter" placeholder="'+ payment_fields[key] +'" onchange="validate(this)" required><small class="error"></small>';
break;
default:
html += '<input type="text" class="input-details quarter" placeholder="'+ payment_fields[key] +'" onkeyup="validate(this)" required><small class="error"></small>';
break;
}
}
document.getElementById("payment_fields").innerHTML = html;
}
setCookie("payment_type", type);
}
function place_order() {
if (validate("all")) {
var fields = document.getElementsByClassName("order-information");
Array.from(fields).forEach((field) => {
setCookie(field.getAttribute("id"), field.value);
});
location.href = "/thankyou.html";
}
}
function validate(fields) {
var valid = true;
if (fields == "all") {
var elements = document.getElementsByClassName("order-information");
Array.from(elements).forEach((element) => {
if (element.value == "") {
element.classList.add("input-error");
element.nextElementSibling.style.display = "block";
element.nextElementSibling.innerHTML = "Required field.";
valid = false;
} else {
element.classList.remove("input-error");
element.nextElementSibling.style.display = "none";
element.nextElementSibling.innerHTML = " ";
}
});
if (document.querySelector('input[name="delivery_type"]:checked') == null) {
document.querySelector('.delivery-container').classList.add("input-error");
document.querySelector('.delivery-container').nextElementSibling.style.display = "block";
document.querySelector('.delivery-container').nextElementSibling.innerHTML = "Required field.";
valid = false;
} else {
document.querySelector('.delivery-container').classList.remove("input-error");
document.querySelector('.delivery-container').nextElementSibling.style.display = "none";
document.querySelector('.delivery-container').nextElementSibling.innerHTML = "";
}
return valid;
} else {
if (fields.value == "") {
fields.classList.add("input-error");
fields.nextElementSibling.style.display = "block";
fields.nextElementSibling.innerHTML = "Required field.";
} else {
fields.classList.remove("input-error");
fields.nextElementSibling.style.display = "none";
fields.nextElementSibling.innerHTML = "";
}
}
}
function open_login() {
document.getElementById("account-modal").style.display = "block";
}
</script>
</div>
</div>
<hr class="hr--clear" />
</section>
</main>
<footer>
<div class="container flex align-center space-between">
<div class="copyright padding-top-5"><p class="lx-small light no-margin primary">© 2023. All Rights Reserved.</p></div>
<div class="footer-menu">
<ul class="footer-list no-margin">
<li><a href="/" class="light">Home</a></li>
<li><a href="/index.html/#best-sellers" class="light">Menu</a></li>
</ul>
</div>
</div>
</footer>
</body>