Swathi6 commited on
Commit
8818cc9
·
verified ·
1 Parent(s): 6178d86

Create templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +757 -0
templates/cart.html ADDED
@@ -0,0 +1,757 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Cart</title>
7
+ <!-- Bootstrap CSS -->
8
+ <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
9
+ <style>
10
+
11
+ body {
12
+ font-family: Arial, sans-serif;
13
+ background-color: #fdf4e3; /* Updated background color */
14
+ color: #333;
15
+ }
16
+ .cart-container {
17
+ max-width: 768px;
18
+ margin: 20px auto;
19
+ padding: 15px;
20
+ background-color: #FFFFFF;
21
+ border-radius: 10px;
22
+
23
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
24
+ }
25
+ .cart-container2 {
26
+ background-color:#FFFFFF;
27
+ }
28
+ /* Green Back Button styling */
29
+ .back-button {
30
+ position: absolute;
31
+ top: 15px;
32
+ left: 15px;
33
+ display: inline-block;
34
+ background-color: green; /* Green color */
35
+ color: white;
36
+ padding: 10px 20px;
37
+ text-decoration: none;
38
+ font-weight: bold;
39
+ border-radius: 4px;
40
+ z-index: 10; /* Ensure it stays above other content */
41
+ }
42
+ .back-button:hover {
43
+ background-color: darkgreen; /* Darker green color on hover */
44
+ }
45
+ .cart-item {
46
+ display: flex;
47
+ align-items: flex-start;
48
+ justify-content: space-between;
49
+ border: 1px solid transparent; /* Set the border to transparent */
50
+ padding: 30px 15px 15px;
51
+ background-color: #fff;/* Padding for the content */
52
+ box-sizing: border-box;
53
+ min-height: 100px;
54
+ position: relative; /* Make the cart item a reference for the absolute positioning of the remove icon */
55
+ border: 1px solid #fdf4e3; /* light Orange border around each item */
56
+ border-radius: 8px; /* Rounded corners for items */
57
+ }
58
+ .remove-btn {
59
+ border: none; /* Remove the border around the button */
60
+ background-color: transparent; /* Transparent background */
61
+ cursor: pointer; /* Change cursor to pointer */
62
+ font-size: 1.2rem; /* Slightly decrease the size of the trash icon */
63
+ margin-bottom: 10px; /* Add space below the delete icon */
64
+ transition: color 0.3s ease; /* Smooth transition for icon color */
65
+ position: relative; /* Make it relative for movement */
66
+ top: -35px; /* Move the button 10px upwards */
67
+ left: 50px; /* Move the button 30px to the right */
68
+ }
69
+ .remove-btn i {
70
+ color: red; /* Make the trash icon red */
71
+ }
72
+ /* Hover effect */
73
+ .remove-btn:hover {
74
+ color: black; /* Change the icon color to black on hover */
75
+ background-color: transparent; /* Keep background transparent on hover */
76
+ }
77
+ /* Prevent background color on focus or click */
78
+ .remove-btn:focus {
79
+ outline: none; /* Remove the outline */
80
+ background-color: transparent; /* Keep background transparent after clicking */
81
+ }
82
+ /* Green Color for Prices */
83
+ .text-primary {
84
+ color: #2e7d32; /* Green color for the prices */
85
+ text-align: right; /* Center-align the price */
86
+ font-weight: bold; /* Make the price text bold */
87
+ white-space: nowrap; /* Prevent price text from wrapping */
88
+ }
89
+ /* For the image container */
90
+ .image-wrapper {
91
+ width: 80px; /* Width of the image container */
92
+ height: 80px !important; /* Set the height of the container to match the image */
93
+ display: flex; /* Flex container for the image */
94
+ align-items: center; /* Center image vertically */
95
+ justify-content: center; /* Center image horizontally */
96
+ }
97
+ /* For the image */
98
+ .cart-item img {
99
+ width: 70px; /* Set the width to 70px */
100
+ height: 70px; /* Set the height to 70px */
101
+ object-fit: cover; /* Ensure the image covers the container without stretching */
102
+ border-radius: 5px; /* Optional: rounded corners */
103
+ border: 1px solid #ffcc80; /* Light orange border around images */
104
+ margin: 0; /* Ensure no extra space around the image */
105
+ }
106
+
107
+ .cart-item img:hover {
108
+ transform: scale(1.05);
109
+ }
110
+ .cart-item-title {
111
+ font-size: 1.1rem;
112
+ font-weight: bold; /* Make the title text bold */
113
+ }
114
+
115
+ .checkout-button {
116
+ background-color: #ff5722; /* Full Orange color */
117
+ color: #ffffff; /* White text */
118
+ padding: 12px;
119
+ border-radius: 8px;
120
+ border: none;
121
+ width: 100%;
122
+ font-size: 1.2rem;
123
+ cursor: pointer;
124
+ transition: background-color 0.3s, color 0.3s;
125
+ }
126
+ .checkout-button:hover {
127
+ background-color: #ff5722; /* Full Orange color on hover */
128
+ color: #ffffff; /* White text on hover */
129
+ }
130
+ .add-back-button {
131
+ padding: 6px 20px;
132
+ font-size: 0.9rem;
133
+ border-radius: 20px;
134
+ border: 1px solid #fff;
135
+ background-color: #fff;
136
+ color: #0FAA39;
137
+ cursor: pointer;
138
+ transition: background-color 0.3s, color 0.3s;
139
+ }
140
+ .add-back-button:hover {
141
+ background-color: #fff;
142
+ color: #0FAA39;
143
+ }
144
+
145
+ .cart-item-details {
146
+ flex: 1;
147
+ margin-left: 15px;
148
+ }
149
+
150
+ .cart-item-quantity {
151
+ display: flex;
152
+ align-items: center;
153
+ margin-top: 5px;
154
+ }
155
+ .cart-item-quantity button {
156
+ width: 24px;
157
+ height: 24px;
158
+ border: none;
159
+ background-color: #f0f0f0;
160
+ font-size: 0.8rem;
161
+ font-weight: bold;
162
+ cursor: pointer;
163
+ }
164
+ .cart-item-quantity input {
165
+ width: 40px;
166
+ text-align: center;
167
+ border: none;
168
+ background-color: #f8f9fa;
169
+ font-size: 1rem;
170
+ margin: 0 5px;
171
+ }
172
+ /* Make the parent container position relative */
173
+ .cart-summary {
174
+ position: relative; /* Make sure dropdown is positioned relative to this container */
175
+ text-align: left;
176
+ margin-top: 15px;
177
+ padding: 20px;
178
+ background-color: #fff;
179
+ border-radius: 12px;
180
+ border: 2px solid #fdf4e3; /* light Orange border around the cart summary */
181
+ box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
182
+ }
183
+ .cart-item-instructions {
184
+ word-wrap: break-word; /* Ensure that long instructions text wraps to the next line */
185
+ white-space: normal; /* Allow text to wrap and prevent overflow */
186
+ overflow: hidden; /* Hide any overflow text */
187
+ max-width: 100%; /* Ensure instructions text stays within the container's width */
188
+ word-break: break-word; /* Break the word when necessary */
189
+
190
+ }
191
+ /* Coupon Section styling */
192
+ .coupon-selection {
193
+ display: flex; /* Use flexbox to align items */
194
+ justify-content: space-between; /* Space between the label and the link */
195
+ align-items: center;
196
+ font-size: 1rem;
197
+ margin-bottom: 20px; /* Add space below Apply Coupon section */
198
+ position: relative; /* Ensure dropdown is within this container */
199
+ }
200
+ /* Ensure the Apply Coupon label and link are aligned correctly */
201
+ .coupon-selection label {
202
+ font-weight: bold;
203
+ color: black;
204
+ }
205
+ .coupon-selection a {
206
+ color: #007bff; /* Blue for the link */
207
+ font-size: 1rem;
208
+ text-decoration: none;
209
+ text-align: right;
210
+ }
211
+ /* Coupon Dropdown styling */
212
+ #couponDropdown {
213
+ width: 30%; /* Set dropdown to 30% of the width */
214
+ display: none; /* Hidden by default */
215
+ background-color: #fff;
216
+ box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2); /* Add shadow */
217
+ z-index: 10; /* Ensure it's above other content */
218
+ margin-top: 10px; /* Add space from the link */
219
+ margin-left: auto; /* Push it to the right side */
220
+ margin-right: 0; /* Ensure it doesn't overflow outside */
221
+ }
222
+ /* Show the dropdown when it's active */
223
+ #couponDropdown.show {
224
+ display: block;
225
+ }
226
+ /* Ensure Apply Coupon section aligns correctly */
227
+ .coupon-selection {
228
+ display: flex;
229
+ justify-content: space-between;
230
+ align-items: center;
231
+ font-size: 1rem;
232
+ margin-bottom: 20px; /* Add space below Apply Coupon section */
233
+ }
234
+ /* Apply Coupon link and label styles */
235
+ .coupon-selection label {
236
+ font-weight: bold;
237
+ color: black;
238
+ }
239
+ .coupon-selection a {
240
+ color: #007bff; /* Blue for the link */
241
+ font-size: 1rem;
242
+ text-decoration: none;
243
+ text-align: right;
244
+ }
245
+ /* Bill details grid structure */
246
+ .bill-details {
247
+ display: grid;
248
+ grid-template-columns: 1fr 1fr; /* Two-column layout */
249
+ grid-gap: 10px;
250
+ margin-bottom: 10px;
251
+ }
252
+ /* Adjust label and amount for bill details */
253
+ .bill-details .label {
254
+ font-weight: 600;
255
+ font-size: 1rem;
256
+ }
257
+ .bill-details .amount {
258
+ text-align: right;
259
+ font-weight: 600;
260
+ font-size: 1rem;
261
+ }
262
+ /* Divider line between bill sections */
263
+ .dotted-line {
264
+ border-bottom: 2px dotted #ccc;
265
+ margin: 15px 0;
266
+ }
267
+ /* Total bill grid layout */
268
+ .total-bill {
269
+ display: grid;
270
+ grid-template-columns: 1fr 1fr;
271
+ font-weight: 600;
272
+ font-size: 1.2rem;
273
+ margin-top: 10px;
274
+ margin-bottom: 10px; /* Add 10px space between To Pay and Submit Button */
275
+ }
276
+ .total-bill .label {
277
+ font-size: 1.1rem;
278
+ }
279
+ .total-bill .amount {
280
+ text-align: right;
281
+ font-size: 1.1rem;
282
+ color: #2e7d32; /* Green for Total Bill Price */
283
+ }
284
+ /* Margin to add space for dropdown when visible */
285
+ .cart-summary.has-dropdown {
286
+ margin-bottom: 80px; /* Create space below the content when dropdown is visible */
287
+ }
288
+ .checkout-button {
289
+ background-color: #ff5722;
290
+ color: #ffffff;
291
+ padding: 12px;
292
+ border-radius: 8px;
293
+ border: none;
294
+ height: 44px;
295
+ width: 100%;
296
+ font-size: 1.2rem;
297
+ cursor: pointer;
298
+ transition: background-color 0.3s, color 0.3s;
299
+ display: flex;
300
+ justify-content: center;
301
+ align-items: center;
302
+ text-align: center;
303
+ }
304
+ .suggestion-section {
305
+ margin-top: 25px;
306
+ padding: 15px;
307
+ background-color: #fff;
308
+ border-radius: 10px;
309
+ border: 2px solid #fdf4e3; /* light Orange border around the complete meal box */
310
+ }
311
+ .suggestion-items-container {
312
+ display: flex;
313
+ overflow-x: auto; /* Horizontal scrolling */
314
+ gap: 10px; /* Space between items */
315
+ padding-bottom: 10px;
316
+ padding-top: 10px;
317
+ }
318
+ /* Styling for the suggestion item card */
319
+ .suggestion-item {
320
+ display: flex; /* Align items horizontally */
321
+ align-items: center; /* Center image and text vertically */
322
+ justify-content: flex-start; /* Align items to the start (left side) */
323
+ flex-shrink: 0;
324
+ width: 160px; /* Set fixed width for each suggestion item */
325
+ padding: 10px;
326
+ border-radius: 8px; /* Rounded corners */
327
+ background-color: #fff;
328
+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
329
+ transition: transform 0.3s ease;
330
+ margin-right: 10px; /* Ensure there's space between the cards */
331
+ position: relative; /* For positioning the + icon */
332
+ text-align: left; /* Align text to the left */
333
+ overflow: visible; /* Allow the button to overflow outside */
334
+ border: 2px solid #fdf4e3; /* light Orange border around the suggestion items */
335
+ }
336
+ .suggestion-item:hover {
337
+ transform: scale(1.05); /* Slight zoom effect on hover */
338
+ }
339
+ .suggestion-item img {
340
+ width: 50px; /* Set a fixed width for the image */
341
+ height: 50px; /* Set a fixed height for the image */
342
+ object-fit: cover; /* Ensure image fits correctly without distortion */
343
+ border-radius: 5px; /* Rounded corners for the image */
344
+ margin-right: 12px; /* Space between the image and text */
345
+ }
346
+ .suggestion-item div {
347
+ flex-grow: 1; /* Allow the text section to expand and fill available space */
348
+ text-align: left; /* Align text to the left */
349
+ }
350
+ /* Styling for the + symbol button (with green border, white background, and black text) */
351
+ .add-back-button {
352
+ position: absolute;
353
+ top: -5px;
354
+ right: -10px;
355
+ font-size: 1rem; /* Smaller font size */
356
+ padding: 0; /* Remove padding */
357
+ width: 30px; /* Set fixed width */
358
+ height: 30px; /* Set fixed height */
359
+ background-color: #fff;
360
+ color: #0FAA39;
361
+ border: 2px solid #0FAA39;
362
+ border-radius: 0; /* Square shape */
363
+ cursor: pointer;
364
+ transition: background-color 0.3s, color 0.3s, border-color 0.3s;
365
+ z-index: 2; /* Increased z-index to ensure it stays above the borders */
366
+ }
367
+ .add-back-button:hover {
368
+ background-color: #fff; /* Green background on hover */
369
+ color: #0FAA39; /* White color for the + symbol when hovered */
370
+ border-color: #0FAA39; /* Green border on hover */
371
+ z-index: 3; /* Ensure button stays on top when hovered */
372
+ }
373
+ /* Ensure the scroll container works fine */
374
+ .suggestion-items-container::-webkit-scrollbar {
375
+ height: 8px; /* Height of the scrollbar */
376
+ }
377
+ .suggestion-items-container::-webkit-scrollbar-thumb {
378
+ background-color: #fff; /* Green color for scrollbar thumb */
379
+ border-radius: 4px;
380
+ }
381
+ .suggestion-items-container::-webkit-scrollbar-track {
382
+ background-color: #f1f1f1;
383
+ }
384
+
385
+ .cart-item-actions {
386
+ display: flex; /* Use flexbox to align items horizontally */
387
+ align-items: flex-start; /* Align the price at the top of the cart item (like the item name) */
388
+ margin-left: auto; /* This will push the price to the right side of the cart item */
389
+ }
390
+ h4.mb-4.fw-bold {
391
+ text-align: center; /* Centers the title */
392
+ color: #FF5722; /* Orange color for the title */
393
+ .cart-container h4 {
394
+ text-align: center; /* This will center the title horizontally */
395
+ color: #FF5722; /* Orange color */
396
+ font-weight: bold; /* Make it bold */
397
+ }
398
+
399
+ </style>
400
+ </head>
401
+ <body>
402
+ <div class="container">
403
+ <div class="cart-container">
404
+ <div style="text-align: right;">
405
+ <a href="/menu" style="text-decoration: none; font-size: 1.5rem; color: #007bff;">&times;</a>
406
+ </div>
407
+
408
+ <h4 class="mb-4 fw-bold">Your Cart</h4>
409
+
410
+ <!-- Cart Items -->
411
+ <div class="cart-container2">
412
+ {% for item in cart_items %}
413
+ <div class="cart-item">
414
+ <div class="image-wrapper">
415
+ <img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
416
+ </div>
417
+ <div class="cart-item-details">
418
+ <div class="cart-item-title">
419
+ {{ item.Name }}
420
+ </div>
421
+ <div class="cart-item-addons">
422
+ <small class="text-muted">Add-ons: {{ item.Add_Ons__c }}</small>
423
+ </div>
424
+ <div class="cart-item-instructions">
425
+ <small class="text-muted">Instructions: {{ item.Instructions__c or "None" }}</small>
426
+ </div>
427
+ <div class="cart-item-quantity mt-2">
428
+ <button onclick="updateQuantity('decrease', '{{ item.Name }}', '{{ customer_email }}')">-</button>
429
+ <input type="text" value="{{ item.Quantity__c|int }}" readonly data-item-name="{{ item.Name }}">
430
+ <button onclick="updateQuantity('increase', '{{ item.Name }}', '{{ customer_email }}')">+</button>
431
+ </div>
432
+ </div>
433
+ <div class="cart-item-actions">
434
+ <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
435
+
436
+ <!-- Delete Button with Trash Icon and onclick handler -->
437
+ <button type="button" class="btn btn-light text-dark remove-btn" onclick="removeItemFromCart('{{ item.Name }}')">
438
+ <i class="bi bi-trash"></i>
439
+ </button>
440
+
441
+ <div class="text-primary" style="color: #000 !important;">
442
+ $<span class="base-price">{{ item.Price__c }}</span>
443
+ </div>
444
+ </div>
445
+ </div>
446
+ {% else %}
447
+ <!-- Code to handle the case when cart_items is empty -->
448
+ <p>No items in your cart.</p>
449
+ {% endfor %}
450
+ </div>
451
+
452
+ <!-- Suggestions Section -->
453
+ {% if suggestions %}
454
+ <div class="suggestion-section">
455
+ <h5>Complete Your Meal</h5>
456
+ <div class="suggestion-items-container">
457
+ {% for suggestion in suggestions %}
458
+ <div class="suggestion-item">
459
+ <img src="{{ suggestion.Image1__c }}" alt="{{ suggestion.Name }}" onerror="this.src='/static/placeholder.jpg';">
460
+ <div>
461
+ <div>{{ suggestion.Name }}</div>
462
+ <div class="text-muted">${{ suggestion.Price__c }}</div>
463
+ </div>
464
+ <!-- Replace add button with a cart icon -->
465
+ <button class="add-back-button" onclick="addToCartSuggestion('{{ suggestion.Name }}', '{{ suggestion.Price__c }}', '{{ suggestion.Image1__c }}', '{{ suggestion.Id }}')">+</button>
466
+
467
+
468
+ </div>
469
+ {% endfor %}
470
+ </div>
471
+ </div>
472
+
473
+ {% endif %}
474
+
475
+ <!-- Subtotal -->
476
+ <div class="cart-summary">
477
+ <!-- Coupon Section -->
478
+ {% if coupons %}
479
+ <div class="coupon-selection d-flex justify-content-between align-items-center">
480
+ <label class="text-dark font-weight-bold mb-0">Apply Coupon</label>
481
+ <a href="javascript:void(0);" id="applyCouponLink" onclick="toggleCouponDropdown()" class="text-primary">+ Apply Coupon</a>
482
+ </div>
483
+
484
+ <!-- Coupon Dropdown, positioned below Apply Coupon -->
485
+ <select id="couponDropdown" class="form-select mt-2" style="display:none;" onchange="calculateDiscount()">
486
+ <option value="">Select a coupon</option>
487
+ {% for coupon in coupons %}
488
+ <option value="{{ coupon }}">{{ coupon }}</option>
489
+ {% endfor %}
490
+ </select>
491
+ {% endif %}
492
+
493
+
494
+
495
+ <div class="bill-details">
496
+ <div class="label">Cart Total</div>
497
+ <div class="amount">${{ subtotal }}</div>
498
+
499
+
500
+ <div class="label">Discount</div>
501
+ <div class="amount" id="discountText">-${{ discount }}</div>
502
+
503
+
504
+
505
+
506
+ </div>
507
+
508
+ <div class="dotted-line"></div>
509
+
510
+ <div class="total-bill">
511
+ <div class="label">To Pay</div>
512
+ <div class="amount" id="totalBillText">${{ subtotal }}</div>
513
+ </div>
514
+ <button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
515
+ </div>
516
+ </div>
517
+ </div>
518
+
519
+
520
+ <script>
521
+ // Example function to handle the increase/decrease button clicks
522
+ function updateQuantity(action, itemName, customerEmail) {
523
+ let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
524
+ let quantity = parseInt(quantityInput.value);
525
+ // Update quantity based on action
526
+ if (action === 'increase') {
527
+ quantity++;
528
+ } else if (action === 'decrease' && quantity > 1) {
529
+ quantity--;
530
+ }
531
+ // Validate quantity
532
+ if (isNaN(quantity) || quantity < 1) {
533
+ alert("Invalid quantity!");
534
+ return;
535
+ }
536
+ // Send updated quantity to the server
537
+ fetch('/cart/update_quantity', {
538
+ method: 'POST',
539
+ headers: { 'Content-Type': 'application/json' },
540
+ body: JSON.stringify({ email: customerEmail, item_name: itemName, quantity: quantity })
541
+ })
542
+ .then(response => response.json())
543
+ .then(data => {
544
+ if (data.success) {
545
+ // Update the item price and quantity in the UI
546
+ quantityInput.value = quantity;
547
+ let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
548
+ if (itemElement) {
549
+ let basePriceElement = itemElement.querySelector(".base-price");
550
+ let addonsPriceElement = itemElement.querySelector(".addons-price");
551
+ // Update the base price
552
+ if (basePriceElement) {
553
+ basePriceElement.innerText = data.new_item_price.toFixed(2); // Assuming backend sends this
554
+ }
555
+ // Update add-ons price if needed (optional)
556
+ if (addonsPriceElement && data.addons_price !== undefined) {
557
+ addonsPriceElement.innerText = data.addons_price.toFixed(2);
558
+ }
559
+ } else {
560
+ console.error(`Parent cart item element not found for item: ${itemName}`);
561
+ }
562
+ location.reload();
563
+ // Recalculate subtotal dynamically
564
+
565
+ } else {
566
+ alert("Error updating quantity: " + data.error);
567
+ }
568
+ })
569
+ .catch(err => console.error("Error:", err));
570
+ }
571
+ function toggleCouponDropdown() {
572
+ let couponDropdown = document.getElementById('couponDropdown');
573
+
574
+ // Toggle the visibility of the coupon dropdown
575
+ if (couponDropdown.style.display === "none" || couponDropdown.style.display === "") {
576
+ couponDropdown.style.display = "block";
577
+ } else {
578
+ couponDropdown.style.display = "none";
579
+ }
580
+ }
581
+ function calculateDiscount() {
582
+ let couponDropdown = document.getElementById('couponDropdown'); // Get coupon dropdown
583
+ let selectedCoupon = couponDropdown.value.trim(); // Get the selected coupon value
584
+ let subtotal = parseFloat("{{ subtotal }}"); // Get the subtotal (from the backend)
585
+ // If a valid coupon is selected
586
+ if (selectedCoupon && selectedCoupon.toLowerCase() !== "none") {
587
+ // Apply 10% discount
588
+ let discount = subtotal * 0.10;
589
+ let total = subtotal - discount;
590
+ // Update UI with discount and total bill
591
+ document.getElementById("discountText").innerText = `$${discount.toFixed(2)}`;
592
+ document.getElementById("totalBillText").innerText = `$${total.toFixed(2)}`;
593
+ } else {
594
+ // If no coupon is selected or "None" is selected, reset the discount
595
+ document.getElementById("discountText").innerText = `$0.00`;
596
+ document.getElementById("totalBillText").innerText = `$${subtotal.toFixed(2)}`;
597
+ }
598
+ }
599
+
600
+ function proceedToOrder() {
601
+ let couponDropdown = document.getElementById('couponDropdown');
602
+
603
+ // Initialize selectedCoupon to an empty string by default
604
+ let selectedCoupon = "";
605
+
606
+ // Only proceed if couponDropdown exists
607
+ if (couponDropdown) {
608
+ // If the value is not null or undefined, strip the value
609
+ if (couponDropdown.value != null) {
610
+ selectedCoupon = couponDropdown.value.trim(); // safely call .trim() if value is not null
611
+ } else {
612
+ selectedCoupon = ""; // Assign empty string if value is null
613
+ }
614
+ }
615
+ // If no coupon is selected or the value is empty, treat it as no coupon
616
+ if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
617
+ selectedCoupon = null; // Treat it as no coupon selected
618
+ }
619
+ // Send the selected coupon to the backend for processing
620
+ fetch('/checkout', {
621
+ method: 'POST',
622
+ headers: { 'Content-Type': 'application/json' },
623
+ body: JSON.stringify({ selectedCoupon: selectedCoupon })
624
+ })
625
+ .then(response => response.json())
626
+ .then(data => {
627
+ if (data.success) {
628
+ alert(data.message); // Success message
629
+ window.location.href = '/order'; // Redirect to order page
630
+ } else {
631
+ alert(data.error || data.message); // Handle error message
632
+ }
633
+ })
634
+ .catch(err => console.error('Error during checkout:', err));
635
+ }
636
+ function calculateSubtotal() {
637
+ let subtotal = 0;
638
+ document.querySelectorAll('.cart-item').forEach(item => {
639
+ const quantity = parseInt(item.querySelector('input').value);
640
+ const basePrice = parseFloat(item.querySelector('.base-price').innerText.replace('$', '')); // Base Price
641
+ const addonsPrice = parseFloat(item.querySelector('.addons-price').innerText.replace('$', '')) || 0; // Add-ons Price
642
+ subtotal += (basePrice * quantity) + addonsPrice; // Include add-ons price in subtotal
643
+ });
644
+ // Update the subtotal in the HTML
645
+ document.querySelector('.cart-summary p').innerText = `Subtotal: $${subtotal.toFixed(2)}`;
646
+ return subtotal;
647
+ }
648
+ function addSuggestion(itemId) {
649
+ fetch(`/cart/add_suggestion/${itemId}`, {
650
+ method: 'POST',
651
+ headers: { 'Content-Type': 'application/json' },
652
+ body: JSON.stringify({})
653
+ })
654
+ .then(response => response.json())
655
+ .then(data => {
656
+ if (data.success) {
657
+ alert('Item added to cart!');
658
+ location.reload();
659
+ } else {
660
+ alert(data.error);
661
+ }
662
+ })
663
+ .catch(err => console.error('Error adding suggestion:', err));
664
+ }
665
+ function removeItemFromCart(itemName) {
666
+ fetch(`/cart/remove/${encodeURIComponent(itemName)}`, {
667
+ method: 'POST',
668
+ headers: {
669
+ 'Content-Type': 'application/json'
670
+ }
671
+ })
672
+ .then(response => response.json())
673
+ .then(data => {
674
+ if (data.success) {
675
+ alert(data.message);
676
+ location.reload(); // Reload the page to update the cart
677
+ } else {
678
+ alert(data.message);
679
+ }
680
+ })
681
+ .catch(err => console.error('Error removing item:', err));
682
+ }
683
+ function addToCart(itemName, customerEmail) {
684
+ fetch(`/cart/add_item`, {
685
+ method: "POST",
686
+ headers: { "Content-Type": "application/json" },
687
+ body: JSON.stringify({
688
+ email: customerEmail,
689
+ item_name: itemName.trim(), //Ensure the item name is trimmed
690
+ quantity: 0 // DEFAULT QUANTITY PASSED HERE
691
+ })
692
+ })
693
+ .then(response => response.json())
694
+ .then(data => {
695
+ if (data.success) {
696
+ alert("Item added/updated successfully.");
697
+ location.reload(); // Reload the page to update the cart
698
+ } else {
699
+ alert(data.error || "Failed to add item to cart.");
700
+ }
701
+ })
702
+ .catch(err => console.error("Error adding item to cart:", err));
703
+ }
704
+ function addSuggestion(itemId) {
705
+ fetch(`/cart/add_suggestion/${itemId}`, {
706
+ method: 'POST',
707
+ headers: { 'Content-Type': 'application/json' },
708
+ body: JSON.stringify({})
709
+ })
710
+ .then(response => response.json())
711
+ .then(data => {
712
+ if (data.success) {
713
+ alert('Item added to cart!');
714
+ location.reload();
715
+ } else {
716
+ alert(data.error);
717
+ }
718
+ })
719
+ .catch(err => console.error('Error adding suggestion:', err));
720
+ }
721
+ function addToCartSuggestion(itemName, itemPrice, itemImage, itemId) {
722
+ const customerEmail = "{{ customer_email }}"; // Get customer email from session
723
+ // Create the data object to send to the ser ver
724
+ const data = {
725
+ item_name: itemName,
726
+ item_price: itemPrice,
727
+ item_image: itemImage,
728
+ item_id: itemId,
729
+ addons: [], // Default to empty, you can adjust if needed
730
+ instructions: "", // Default to empty, you can adjust if needed
731
+ customer_email: customerEmail
732
+ };
733
+ // Send the data to the backend via a POST request
734
+ fetch('/cart/add_suggestion_to_cart', {
735
+ method: 'POST',
736
+ headers: {
737
+ 'Content-Type': 'application/json'
738
+ },
739
+ body: JSON.stringify(data)
740
+ })
741
+ .then(response => response.json())
742
+ .then(data => {
743
+ if (data.success) {
744
+ alert('Item added to cart!');
745
+ location.reload(); // Reload to update the cart view
746
+ } else {
747
+ alert('Error adding item to cart: ' + data.error);
748
+ }
749
+ })
750
+ .catch(err => console.error('Error adding item:', err));
751
+ }
752
+
753
+
754
+ </script>
755
+
756
+ </body>
757
+ </html>