lokeshloki143 commited on
Commit
66c327a
·
verified ·
1 Parent(s): 5b2f47a

Update templates/cart.html

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