-
Notifications
You must be signed in to change notification settings - Fork 4
/
checkout.html
433 lines (355 loc) · 14.4 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
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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="max-age=604800" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Ensures optimal rendering on mobile devices. -->
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> <!-- Optimal Internet Explorer compatibility -->
<title>CheckOut</title>
<link href="images/icons/burger-icon2.jpg" rel="shortcut icon" type="image/x-icon">
<!-- jQuery -->
<script src="js/jquery-2.0.0.min.js" type="text/javascript"></script>
<!-- Bootstrap4 files-->
<script src="js/bootstrap.bundle.min.js" type="text/javascript"></script>
<link href="css/bootstrap-custom.css" rel="stylesheet" type="text/css" />
<!-- Font awesome 5 -->
<link href="fonts/fontawesome/css/fontawesome-all.min.css" type="text/css" rel="stylesheet">
<!-- custom style -->
<link href="css/uikit.css" rel="stylesheet" type="text/css" />
<link href="css/responsive.css" rel="stylesheet" media="only screen and (max-width: 1200px)" />
<!-- custom javascript -->
<script src="js/script.js" type="text/javascript"></script>
<script src="js/bootstrap-input-spinner.js"></script>
<script type="text/javascript">
var cart, totalPrice, login_user
// jquery ready start
$(document).ready(function () {
cart = JSON.parse(sessionStorage.getItem("cart"))
login_user = sessionStorage.getItem("login_user")
var cart_num = 0
if (!login_user)
window.location.replace("/login.html")
if (!cart || cart.length == 0) {
$('#exampleModal').modal()
}
else {
renderCart()
cart_num = cart.length
// load input plugin
$("input[type='number']").inputSpinner();
}
$("#cartCounter").text(cart_num)
});
function renderCart() {
$("#productTable").empty()
cart.forEach((val, index) => {
$("#productTable").append(`<tr>
<td>
<figure class="media">
<div class="img-wrap"><img src="` + val.img + `" class="img-thumbnail img-sm"></div>
<figcaption class="media-body">
<h6 class="title text-truncate">` + val.Name + ` </h6>
<dl class="dlist-inline small">
<dt>Meat: </dt>
<dd>` + val.meat + `</dd>
</dl>
</figcaption>
</figure>
</td>
<td>
<input id="quantity` + index + `" class="form-control-sm" onchange="updateCartQuantity(` + index + `)" type="number" value="` + val.quantity + `" min="1" max="100" step="1"/>
</td>
<td>
<div class="price-wrap">
<var id="price` + index + `" class="price">RM ` + (val.Price * val.quantity).toFixed(2) + `</var>
<small class="text-muted">(RM ` + val.Price.toFixed(2) + ` each)</small>
</div>
</td>
<td class="text-right">
<a href="" onclick="removeProduct(` + index + `)" class="btn btn-outline-danger"> × Remove</a>
</td>
</tr>`)
});
updateTotalPrice()
}
function updateCartQuantity(i) {
var quantity = parseInt($("#quantity" + i).val())
// update cart into session
cart[i].quantity = quantity
sessionStorage.setItem("cart", JSON.stringify(cart))
// update cart into members information, local storage
var members_informations = JSON.parse(localStorage.getItem("members_informations"))
members_informations[login_user].cart = JSON.stringify(cart)
localStorage.setItem("members_informations", JSON.stringify(members_informations))
// Update Price
$("#price" + i).text("RM " + (cart[i].Price * cart[i].quantity).toFixed(2))
updateTotalPrice()
}
function updateTotalPrice() {
totalPrice = 0
for (var i = 0; i < cart.length; i++) {
totalPrice += cart[i].Price * cart[i].quantity
}
$("#totalPrice").text("RM " + totalPrice.toFixed(2))
}
function removeProduct(i) {
cart.splice(i, 1)
// update cart into session storage
sessionStorage.setItem("cart", JSON.stringify(cart))
// update cart into members information, local storage
var members_informations = JSON.parse(localStorage.getItem("members_informations"))
members_informations[login_user].cart = JSON.stringify(cart)
localStorage.setItem("members_informations", JSON.stringify(members_informations))
renderCart()
}
</script>
</head>
<body>
<header class="section-header">
<nav class="navbar navbar-top navbar-expand-lg navbar-dark bg-secondary">
<div class="container">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav"
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="home.html">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item dropdown" id="need-login">
<a class="nav-link dropdown-toggle" href="#" data-toggle="dropdown"> My account </a>
<ul class="dropdown-menu">
<li> <a class="dropdown-item" href="view_order.html"> My Orders </a></li>
<li> <a class="dropdown-item" href="checkout.html"> My Shopping Cart </a></li>
<li> <a class="dropdown-item" href="#" onclick="logOut()"> Log out </a></li>
</ul>
</li>
<li class="nav-item">
<a class="nav-link" href="about_us.html">About Us <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact_us.html">Contact Us<span
class="sr-only">(current)</span></a>
</li>
</ul>
</div>
</div> <!-- container // -->
</nav>
<section class="header-main shadow-sm">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-3 col-sm-4">
<a href="home.html" class="brand-wrap">
<img class="logo" src="images/icons/burger-icon2.jpg">
<h2 class="logo-text">IT Burger</h2>
</a> <!-- brand-wrap.// -->
</div>
<div class="col-lg-9 col-sm-8">
<div class="widgets-wrap float-right">
<a href="/checkout.html" class="widget-header mr-3">
<div class="icontext">
<div class="icon-wrap"><i class="icon-sm round border fa fa-shopping-cart"></i>
</div>
<div class="text-wrap">
<span id="cartCounter" class="small badge badge-danger"></span>
<div>Cart</div>
</div>
</div>
</a>
</div>
</div>
</div> <!-- container.// -->
</section> <!-- header-main .// -->
</header> <!-- section-header.// -->
<!-- ========================= SECTION CONTENT ========================= -->
<section class="section-content bg padding-y border-top">
<div class="container">
<div class="row">
<main class="col-sm-12 col-md-9">
<div class="card">
<table class="table table-hover shopping-cart-wrap">
<thead class="text-muted">
<tr>
<th scope="col">Product</th>
<th scope="col" width="200">Quantity</th>
<th scope="col" width="120">Price</th>
<th scope="col" class="text-right" width="200">Action</th>
</tr>
</thead>
<tbody id="productTable">
</tbody>
</table>
</div> <!-- card.// -->
</main> <!-- col.// -->
<aside class="col-sm-3">
<dl class="dlist-align h4">
<dt>Total:</dt>
<dd class="text-right"><strong id="totalPrice"></strong></dd>
</dl>
<hr>
<script
src="https://www.paypal.com/sdk/js?client-id=AR7G9dkEWf5capUpnNV37tSJjwDg89TLiv3RHu73uW3BWE51ac8OYgVrzPhGStFJPulyF01SAiJ0RYe4"> // Required. Replace SB_CLIENT_ID with your sandbox client ID.
</script>
<div id="paypal-button-container"></div>
<script>
paypal.Buttons({
createOrder: function (data, actions) {
// This function sets up the details of the transaction, including the amount and line item details.
return actions.order.create({
purchase_units: [{
amount: {
value: (totalPrice / 4).toFixed(2),
currency: "MYR"
}
}]
});
},
onApprove: function (data, actions) {
// This function captures the funds from the transaction.
return actions.order.capture().then(function (details) {
var order_history = JSON.parse(sessionStorage.getItem("order_history"))
var cart = JSON.parse(sessionStorage.getItem("cart"))
var od = {}
// Date Time
var today = new Date();
var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
var dateTime = date + ' ' + time;
if (!order_history) order_history = []
// generate order history
od.item = cart
od.checkoutDate = dateTime
od.totalPrice = totalPrice.toFixed(2)
order_history.push(od)
// update order history into session storage
sessionStorage.setItem("cart", "[]")
sessionStorage.setItem("order_history", JSON.stringify(order_history))
// update order history into members information, local storage
var members_informations = JSON.parse(localStorage.getItem("members_informations"))
members_informations[login_user].order_history = JSON.stringify(order_history)
members_informations[login_user].cart = "[]"
localStorage.setItem("members_informations", JSON.stringify(members_informations))
// This function shows a transaction success message to your buyer. TODO
alert('Transaction completed by ' + details.payer.name.given_name)
window.location.replace("/view_order.html")
});
}
}).render('#paypal-button-container');
//This function displays Smart Payment Buttons on your web page.
</script>
<p><strong>Note: Based on the weather table below, if it is currently raining heavily, the delivery
service will be delay a bit.</strong></p>
<iframe
src="https://www.meteoblue.com/en/weather/widget/daily/kampar_malaysia_1735274?geoloc=fixed&days=7&tempunit=CELSIUS&windunit=KILOMETER_PER_HOUR&precipunit=MILLIMETER&coloured=coloured&pictoicon=0&pictoicon=1&maxtemperature=0&maxtemperature=1&mintemperature=0&mintemperature=1&windspeed=0&windgust=0&winddirection=0&uv=0&uv=1&humidity=0&humidity=1&precipitation=0&precipitationprobability=0&precipitationprobability=1&spot=0&pressure=0&layout=light"
frameborder="0" scrolling="NO" allowtransparency="true"
sandbox="allow-same-origin allow-scripts allow-popups allow-popups-to-escape-sandbox"
style="width: 378px; height: 301px"></iframe>
<div>
<!-- DO NOT REMOVE THIS LINK --><a
href="https://www.meteoblue.com/en/weather/week/kampar_malaysia_1735274?utm_source=weather_widget&utm_medium=linkus&utm_content=daily&utm_campaign=Weather%2BWidget"
target="_blank"></a></div>
</aside> <!-- col.// -->
</div>
</div> <!-- container .// -->
</section>
<!-- ========================= SECTION CONTENT END// ========================= -->
<!-- ========================= SECTION ========================= -->
<section class="section-name bg-white padding-y">
<div class="container">
</div><!-- container // -->
</section>
<!-- ========================= SECTION END// ========================= -->
<!-- ========================= SECTION ========================= -->
<section class="section-name bg padding-y">
<div class="container">
</div><!-- container // -->
</section>
<!-- ========================= SECTION END// ========================= -->
<!-- ========================= MODAL ========================= -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header bg-info">
<h5 class="modal-title text-white" id="exampleModalLabel">Empty</h5>
<button type="button" class="close text-white" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Your cart is Empty!
</div>
<div class="modal-footer">
<a href="home.html"><button type="button" class="btn btn-info">Back to Home</button></a>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- ========================= MODAL .END// ========================= -->
<div class="video">
<iframe width="250" height="125" src="https://www.youtube.com/embed/zoQ8C0r6Djw" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<a id="back2Top" title="Back to top" href="#">➤</a>
<script>
/*Scroll to top when arrow up clicked BEGIN*/
$(window).scroll(function() {
var height = $(window).scrollTop();
if (height > 100) {
$('#back2Top').fadeIn();
} else {
$('#back2Top').fadeOut();
}
});
$(document).ready(function() {
$("#back2Top").click(function(event) {
event.preventDefault();
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
});
/*Scroll to top when arrow up clicked END*/
</script>
<!-- ========================= FOOTER ========================= -->
<footer class="section-footer bg-secondary">
<div class="container">
<section class="footer-bottom row border-top-white">
<div class="col-sm-6">
<p class="text-white-50"> IT Burger</p>
</div>
<div class="col-sm-6 text-right">
<p class="text-sm-right text-white-50">
Copyright © 2018 <br>
<a href="http://bootstrap-ecommerce.com" class="text-white-50">Bootstrap-ecommerce UI kit</a>
</p>
</div>
</section> <!-- //footer-top -->
</div><!-- //container -->
</footer>
<!-- ========================= FOOTER END // ========================= -->
<script>
document.getElementById("pay").onclick = display;
function display() {
alert("Payment Success!");
}
</script>
<!--Start of Tawk.to Script-->
<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/5f59c9eaf0e7167d000f00d4/default';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->
</body>
</html>