-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheckout.html
294 lines (263 loc) · 10.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
<!doctype html>
<html lang="en">
<head>
<title>Checkout - Starshop</title>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- bootstrap -->
<link rel="stylesheet" href="css/bootstrap-dark.css">
<link href="css/custom.css" rel="stylesheet">
<!-- icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.min.css">
<link rel="icon" href="assets/icons/cart.png">
<!-- handlebars -->
<script src="js/handlebars.min-v4.7.8.js"></script>
<script src="js/vanilla.js"></script>
<script src="js/checkout.js"></script>
<script>
function init() {
render({}, '[type="text/x-handlebars-navbar"]')
render({}, '[type="text/x-handlebars-footer"]')
// $on($('#bestellen'), 'click', toLocal)
const checkoutForm = document.querySelector('.needs-validation')
checkoutForm.addEventListener('submit', event => {
var clear = true;
// no validation check if no stars in cart
if (sessionStorage.getItem("cart") === null) {
event.preventDefault()
event.stopPropagation()
clear = false;
// validation check
} else if (!checkoutForm.checkValidity()) {
event.preventDefault()
event.stopPropagation()
clear = false;
}
// add data to local storage
checkoutForm.classList.add('was-validated')
if (clear) {
toLocal()
clearCart()
}
}, false)
// render cart information
if (!(sessionStorage.getItem('cart') === null)) {
const cartIDs = JSON.parse(sessionStorage.getItem("cart"))
const cart = []
cartIDs.forEach(element => {
const data = getElement(element, localStorage.getItem("data"))
if (!(data === null)) {
cart.push(data)
}
});
var total = 0
cart.forEach(element => {
total += element["Price"]
});
render({ "total": total }, '[type="text/x-handlebars-template-2"]')
if (cart.length > 0) {
render(cart, '[type="text/x-handlebars-template"]')
}
}
}
</script>
</head>
<body onload="init()">
<script id="template" type="text/x-handlebars-navbar">
{{> navbar }}
</script>
<div></div>
<section class="bg-black">
<div class="container ">
<div class="row">
<!-- MARK: cart overview
-->
<div class="col-md-4 order-md-2 mb-4">
<h4 class="d-flex justify-content-between align-items-center my-3">
<span class="text">Your cart</span>
</h4>
<script id="template" type="text/x-handlebars-template">
{{#each this}}
<li class="list-group-item d-flex justify-content-between lh-condensed">
<img src="assets/stars/{{Color}}.png" class="card-img-top cart-image-checkout border-bottom border-dark img-fluidF">
<div class="align-items-start">
<h6 class="my-0 text-start">{{ProperName}}</h6>
<small class="text-muted">
{{#if (lt Price 100000)}}
<strong>Sale</strong>
{{/if}}
Distance: {{Distance}}
</small>
</div>
<span class="text-muted">€ {{formatCurrency Price}}</span>
</li>
{{/each}}
</script>
<ul class="list-group mb-3">
</ul>
<script id="template" type="text/x-handlebars-template-2">
<li class="list-group-item d-flex justify-content-between">
<span>
Total
</span>
<strong>
€ {{formatCurrency total}}
</strong>
</li>
</script>
<ul class="list-group mb-3">
</ul>
</div>
<!-- MARK: billing Form
-->
<div class="col-md-8 order-md-1">
<h4 class="my-3">Checkout</h4>
<form class="needs-validation" novalidate action="confirmation.html">
<div class="row">
<div class="col-md-6 mb-3">
<label for="first">First name</label>
<input type="name" class="form-control" id="first" placeholder="Ursa" required>
<div class="invalid-feedback"> Valid first name is required.</div>
</div>
<div class="col-md-6 mb-3">
<label for="last">Last name</label>
<input type="name" class="form-control" id="last" placeholder="Major" required>
<div class="invalid-feedback">Valid last name is required.</div>
</div>
</div>
<div class="mb-3">
<label for="email">Email</label>
<input type="email" class="form-control" id="email" placeholder="[email protected]" required>
<div class="invalid-feedback">Please enter a valid email address for shipping updates.</div>
</div>
<div class="mb-3">
<label for="address">Address</label>
<input type="text" class="form-control" id="address" placeholder="1234 Main St" required>
<div class="invalid-feedback">Please enter your shipping address.</div>
</div>
<div class="mb-3">
<label for="address2">Address 2 <span class="text-muted">(Optional)</span></label>
<input type="text" class="form-control" id="address2" placeholder="">
</div>
<div class="row">
<div class="col-md-5 mb-3">
<label for="country" class="form-label">Country</label>
<input class="form-control" list="datalistOptions" id="country" placeholder="Type to search..." required>
<datalist id="datalistOptions">
<option value="USA">
<option value="Germany">
<option value="Canada">
<option value="United Kingdom">
<option value="France">
</datalist>
<div class="invalid-feedback"> Please select a valid country.</div>
</div>
<div class="col-md-4 mb-3">
<label for="city" class="form-label">City</label>
<input class="form-control" list="datalistOptionscity" id="city" placeholder="Type to search..." required>
<datalist id="datalistOptionscity">
<option value="Berlin">
<option value="New York">
<option value="Seattle">
<option value="Paris">
<option value="London">
</datalist>
</div>
<div class="col-md-3 mb-3">
<label for="zip">Zip</label>
<input type="number" class="form-control" id="zip" placeholder="12345" required>
<div class="invalid-feedback">Zip code required.</div>
</div>
</div>
<hr class="mb-4">
<h4 class="mb-3">Payment</h4>
<div class="form-check">
<input class="form-check-input" type="radio" value="card" id="ccRadio" required>
<label class="form-check-label" for="ccRadio">
Credit card
</label>
</div>
<div class="form-check py-3">
<input class="form-check-input" type="radio" value="paypal" id="paypalRadio" required>
<label class="form-check-label" for="paypalRadio">
Paypal
</label>
</div>
<div id="paypal-content" style="display: none;">
<div class="row">
<div class="display-6"><i class="bi bi-paypal"></i> Paypal</div>
</div>
<div class="text-light">login after confirmation</div>
</div>
<div id="card-content" style="display: none;">
<div id="ccForm">
<div class="row">
<div class="col-md-6 mb-3">
<label for="card-name">Name on card</label>
<input type="text" class="form-control" id="card-name" placeholder="" required>
<small class="text-muted">Full name as displayed on card</small>
<div class="invalid-feedback">Name on card is required</div>
</div>
<div class="col-md-6 mb-3">
<label for="card-number">Credit card number</label>
<input type="number" class="form-control" id="card-number" placeholder="" required>
<div class="invalid-feedback">Credit card number is required</div>
</div>
</div>
<div class="row">
<div class="col-md-3 mb-3">
<label for="expiration">Expiration</label>
<input type="month" class="form-control" id="expiration" required>
<div class="invalid-feedback">
Expiration date required
</div>
</div>
<div class="col-md-3 mb-3">
<label for="cvv">CVV</label>
<input type="number" class="form-control" id="cvv" placeholder="" required>
<div class="invalid-feedback">
Security code required
</div>
</div>
</div>
</div>
</div>
<hr class="mb-4">
<button class="btn mb-3 btn-dark text-muted btn-lg btn-block" id="bestellen" type="submit">Continue to
checkout</button>
</form>
</div>
</div>
</div>
<script>
document.querySelectorAll('.form-check-input').forEach(input => {
input.addEventListener('change', function (even) {
event.preventDefault()
if (this.checked) {
document.querySelectorAll('#paypal-content, #card-content').forEach(content => {
content.style.display = 'none'
});
if (this.value === 'paypal') {
document.getElementById('paypal-content').style.display = 'block'
document.getElementById('ccRadio').checked = false;
setCardPlaceholder()
} else if (this.value === 'card') {
document.getElementById('card-content').style.display = 'block'
document.getElementById('paypalRadio').checked = false;
resetCardPlaceholder()
}
}
});
});
</script>
</section>
<!-- MARK: footer-->
<script id="template" type="text/x-handlebars-footer">
{{> footer }}
</script>
<div></div>
<!-- Bootstrap JavaScript Libraries -->
<script src="js/bootstrap.js"></script>
</body>
</html>