lokeshloki143 commited on
Commit
0bbd3b5
·
verified ·
1 Parent(s): f120af0

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +417 -550
templates/cart.html CHANGED
@@ -6,534 +6,491 @@
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: 100%; /* Set the width to 70px */
100
- height: 100%; /* Set the height to 70px */
101
- object-fit: contain; /* 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' },
@@ -542,17 +499,14 @@
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
  }
@@ -560,63 +514,50 @@
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('/cart/checkout', {
621
  method: 'POST',
622
  headers: { 'Content-Type': 'application/json' },
@@ -625,133 +566,59 @@
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>
 
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
+ <!-- Google Fonts -->
12
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
13
  <style>
14
+ * {
15
+ box-sizing: border-box;
16
+ margin: 0;
17
+ padding: 0;
 
18
  }
19
+
20
+ body {
21
+ font-family: 'Inter', sans-serif;
22
+ background-color: #F9FAFB;
23
+ color: #1A3C34;
24
+ line-height: 1.6;
25
+ padding: 20px;
26
+ }
27
+
28
  .cart-container {
29
+ max-width: 800px;
30
+ margin: 40px auto;
31
+ padding: 20px;
32
  background-color: #FFFFFF;
33
+ border-radius: 12px;
34
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
35
+ }
36
+
37
+ .cart-header {
38
+ display: flex;
39
+ justify-content: space-between;
40
+ align-items: center;
41
+ margin-bottom: 20px;
42
+ }
43
+
44
+ .cart-header h4 {
45
+ font-size: 1.75rem;
46
+ font-weight: 600;
47
+ color: #FF6F00;
48
+ margin: 0;
49
+ }
50
+
51
+ .close-cart {
52
+ font-size: 1.5rem;
53
+ color: #1A3C34;
54
  text-decoration: none;
55
+ transition: color 0.2s;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
57
+
58
+ .close-cart:hover {
59
+ color: #FF6F00;
60
  }
61
+
62
+ .cart-item {
63
+ display: flex;
64
+ align-items: flex-start;
65
+ padding: 20px;
66
+ margin-bottom: 15px;
67
+ background-color: #FFFFFF;
68
+ border: 1px solid #E5E7EB;
69
+ border-radius: 8px;
70
+ transition: box-shadow 0.2s;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
72
+
73
+ .cart-item:hover {
74
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
75
  }
76
+
77
+ .image-wrapper {
78
+ width: 80px;
79
+ height: 80px;
80
+ flex-shrink: 0;
81
+ display: flex;
82
+ align-items: center;
83
+ justify-content: center;
84
+ }
85
+
86
+ .cart-item img {
87
+ width: 100%;
88
+ height: 100%;
89
+ object-fit: cover;
90
+ border-radius: 6px;
91
+ border: 1px solid #E5E7EB;
92
+ transition: transform 0.2s;
93
+ }
94
+
95
+ .cart-item img:hover {
96
+ transform: scale(1.05);
97
+ }
98
+
99
  .cart-item-details {
100
  flex: 1;
101
  margin-left: 15px;
102
  }
103
+
104
+ .cart-item-title {
105
+ font-size: 1.1rem;
106
+ font-weight: 600;
107
+ color: #1A3C34;
108
+ }
109
+
110
+ .cart-item-addons,
111
+ .cart-item-instructions {
112
+ font-size: 0.9rem;
113
+ color: #6B7280;
114
+ margin-top: 5px;
115
+ }
116
+
117
  .cart-item-quantity {
118
  display: flex;
119
  align-items: center;
120
+ margin-top: 10px;
121
  }
122
+
123
  .cart-item-quantity button {
124
+ width: 32px;
125
+ height: 32px;
126
+ border: 1px solid #E5E7EB;
127
+ background-color: #F9FAFB;
128
+ font-size: 1rem;
 
129
  cursor: pointer;
130
+ transition: background-color 0.2s;
131
  }
132
+
133
+ .cart-item-quantity button:hover {
134
+ background-color: #E5E7EB;
135
+ }
136
+
137
  .cart-item-quantity input {
138
+ width: 50px;
139
  text-align: center;
140
+ border: 1px solid #E5E7EB;
141
+ background-color: #F9FAFB;
142
+ font-size: 1rem;
143
+ margin: 0 8px;
144
+ border-radius: 4px;
145
+ }
146
+
147
+ .cart-item-actions {
148
+ display: flex;
149
+ flex-direction: column;
150
+ align-items: flex-end;
151
+ gap: 10px;
152
+ }
153
+
154
+ .remove-btn {
155
+ background: none;
156
  border: none;
157
+ cursor: pointer;
158
+ font-size: 1.2rem;
159
+ color: #DC2626;
160
+ transition: color 0.2s;
161
+ }
162
+
163
+ .remove-btn:hover {
164
+ color: #B91C1C;
165
+ }
166
+
167
+ .text-primary {
168
+ font-size: 1.1rem;
169
+ font-weight: 600;
170
+ color: #16A34A;
171
+ }
172
+
173
+ .cart-summary {
174
+ padding: 20px;
175
+ background-color: #FFFFFF;
176
+ border: 1px solid #E5E7EB;
177
+ border-radius: 8px;
178
+ margin-top: 20px;
179
+ }
180
+
181
+ .coupon-selection {
182
+ display: flex;
183
+ justify-content: space-between;
184
+ align-items: center;
185
+ margin-bottom: 15px;
186
+ }
187
+
188
+ .coupon-selection label {
189
+ font-weight: 600;
190
+ color: #1A3C34;
191
+ }
192
+
193
+ .coupon-selection a {
194
+ color: #FF6F00;
195
+ text-decoration: none;
196
+ font-weight: 500;
197
+ }
198
+
199
+ .coupon-selection a:hover {
200
+ text-decoration: underline;
201
+ }
202
+
203
+ #couponDropdown {
204
+ width: 100%;
205
+ padding: 8px;
206
+ border: 1px solid #E5E7EB;
207
+ border-radius: 4px;
208
+ margin-top: 10px;
209
+ display: none;
210
+ }
211
+
212
+ #couponDropdown.show {
213
+ display: block;
214
+ }
215
+
216
+ .bill-details {
217
+ display: grid;
218
+ grid-template-columns: 1fr auto;
219
+ gap: 10px;
220
+ margin-bottom: 15px;
221
+ }
222
+
223
+ .bill-details .label {
224
+ font-weight: 500;
225
+ color: #1A3C34;
226
+ }
227
+
228
+ .bill-details .amount {
229
+ text-align: right;
230
+ font-weight: 500;
231
+ color: #1A3C34;
232
+ }
233
+
234
+ .dotted-line {
235
+ border-bottom: 2px dotted #E5E7EB;
236
+ margin: 15px 0;
237
+ }
238
+
239
+ .total-bill {
240
+ display: grid;
241
+ grid-template-columns: 1fr auto;
242
+ font-weight: 600;
243
+ font-size: 1.2rem;
244
+ margin-bottom: 20px;
245
+ }
246
+
247
+ .total-bill .amount {
248
+ text-align: right;
249
+ color: #16A34A;
250
+ }
251
+
252
+ .checkout-button {
253
+ background-color: #FF6F00;
254
+ color: #FFFFFF;
255
+ padding: 12px;
256
+ border: none;
257
+ border-radius: 8px;
258
+ width: 100%;
259
+ font-size: 1.1rem;
260
+ font-weight: 500;
261
+ cursor: pointer;
262
+ transition: background-color 0.2s;
263
+ }
264
+
265
+ .checkout-button:hover {
266
+ background-color: #E65B00;
267
+ }
268
+
269
+ .suggestion-section {
270
+ margin-top: 20px;
271
+ padding: 20px;
272
+ background-color: #FFFFFF;
273
+ border: 1px solid #E5E7EB;
274
+ border-radius: 8px;
275
+ }
276
+
277
+ .suggestion-section h5 {
278
+ font-size: 1.25rem;
279
+ font-weight: 600;
280
+ color: #1A3C34;
281
+ margin-bottom: 15px;
282
+ }
283
+
284
+ .suggestion-items-container {
285
+ display: flex;
286
+ overflow-x: auto;
287
+ gap: 15px;
288
+ padding-bottom: 10px;
289
+ }
290
+
291
+ .suggestion-item {
292
+ flex-shrink: 0;
293
+ width: 180px;
294
+ padding: 15px;
295
+ background-color: #FFFFFF;
296
+ border: 1px solid #E5E7EB;
297
+ border-radius: 8px;
298
+ display: flex;
299
+ align-items: center;
300
+ gap: 10px;
301
+ transition: transform 0.2s;
302
+ }
303
+
304
+ .suggestion-item:hover {
305
+ transform: translateY(-2px);
306
+ }
307
+
308
+ .suggestion-item img {
309
+ width: 50px;
310
+ height: 50px;
311
+ object-fit: cover;
312
+ border-radius: 6px;
313
+ }
314
+
315
+ .suggestion-item div {
316
+ flex: 1;
317
+ }
318
+
319
+ .suggestion-item .name {
320
+ font-size: 1rem;
321
+ font-weight: 500;
322
+ color: #1A3C34;
323
+ }
324
+
325
+ .suggestion-item .price {
326
+ font-size: 0.9rem;
327
+ color: #16A34A;
328
+ }
329
+
330
+ .add-back-button {
331
+ position: absolute;
332
+ top: -10px;
333
+ right: -10px;
334
+ width: 28px;
335
+ height: 28px;
336
+ background-color: #FFFFFF;
337
+ border: 2px solid #16A34A;
338
+ color: #16A34A;
339
+ border-radius: 50%;
340
  font-size: 1rem;
341
+ cursor: pointer;
342
+ display: flex;
343
+ align-items: center;
344
+ justify-content: center;
345
+ transition: background-color 0.2s, color 0.2s;
346
+ }
347
+
348
+ .add-back-button:hover {
349
+ background-color: #16A34A;
350
+ color: #FFFFFF;
351
+ }
352
+
353
+ .suggestion-items-container::-webkit-scrollbar {
354
+ height: 6px;
355
+ }
356
+
357
+ .suggestion-items-container::-webkit-scrollbar-thumb {
358
+ background-color: #D1D5DB;
359
+ border-radius: 3px;
360
+ }
361
+
362
+ .suggestion-items-container::-webkit-scrollbar-track {
363
+ background-color: #F9FAFB;
364
+ }
365
+
366
+ @media (max-width: 576px) {
367
+ .cart-container {
368
+ padding: 15px;
369
+ }
370
+
371
+ .cart-item {
372
+ flex-direction: column;
373
+ align-items: stretch;
374
+ }
375
+
376
+ .cart-item-actions {
377
+ align-items: flex-start;
378
+ margin-top: 10px;
379
+ }
380
+
381
+ .suggestion-item {
382
+ width: 150px;
383
+ }
384
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
385
  </style>
386
  </head>
387
  <body>
388
  <div class="container">
389
  <div class="cart-container">
390
+ <div class="cart-header">
391
+ <h4>Your Cart</h4>
392
+ <a href="/menu" class="close-cart">×</a>
393
  </div>
394
 
 
 
395
  <!-- Cart Items -->
396
+ <div class="cart-items">
397
  {% for item in cart_items %}
398
  <div class="cart-item">
399
  <div class="image-wrapper">
400
  <img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
401
  </div>
402
  <div class="cart-item-details">
403
+ <div class="cart-item-title">{{ item.Name }}</div>
 
 
404
  <div class="cart-item-addons">
405
+ <small>Add-ons: {{ item.Add_Ons__c }}</small>
406
  </div>
407
  <div class="cart-item-instructions">
408
+ <small>Instructions: {{ item.Instructions__c or "None" }}</small>
409
  </div>
410
+ <div class="cart-item-quantity">
411
  <button onclick="updateQuantity('decrease', '{{ item.Name }}', '{{ customer_email }}')">-</button>
412
  <input type="text" value="{{ item.Quantity__c|int }}" readonly data-item-name="{{ item.Name }}">
413
  <button onclick="updateQuantity('increase', '{{ item.Name }}', '{{ customer_email }}')">+</button>
414
  </div>
415
  </div>
416
  <div class="cart-item-actions">
417
+ <button class="remove-btn" onclick="removeItemFromCart('{{ item.Name }}')">
 
 
 
418
  <i class="bi bi-trash"></i>
419
  </button>
420
+ <div class="text-primary">${{ item.Price__c }}</div>
 
 
 
421
  </div>
422
  </div>
423
  {% else %}
 
424
  <p>No items in your cart.</p>
425
  {% endfor %}
426
  </div>
427
 
428
  <!-- Suggestions Section -->
429
  {% if suggestions %}
430
+ <div class="suggestion-section">
431
+ <h5>Complete Your Meal</h5>
432
+ <div class="suggestion-items-container">
433
+ {% for suggestion in suggestions %}
434
+ <div class="suggestion-item">
435
+ <img src="{{ suggestion.Image1__c }}"
436
+
437
+ alt="{{ suggestion.Name }}" onerror="this.src='/static/placeholder.jpg';">
438
+ <div>
439
+ <div class="name">{{ suggestion.Name }}</div>
440
+ <div class="price">${{ suggestion.Price__c }}</div>
441
+ </div>
442
+ <button class="add-back-button" onclick="addToCartSuggestion('{{ suggestion.Name }}', '{{ suggestion.Price__c }}', '{{ suggestion.Image1__c }}', '{{ suggestion.Id }}')">+</button>
443
+ </div>
444
+ {% endfor %}
445
  </div>
 
446
  </div>
 
 
447
  {% endif %}
448
 
449
+ <!-- Cart Summary -->
450
  <div class="cart-summary">
451
+ {% if coupons %}
452
+ <div class="coupon-selection">
453
+ <label>Apply Coupon</label>
454
+ <a href="javascript:void(0);" id="applyCouponLink" onclick="toggleCouponDropdown()">+ Apply Coupon</a>
455
+ </div>
456
+ <select id="couponDropdown" onchange="calculateDiscount()">
457
+ <option value="">Select a coupon</option>
458
+ {% for coupon in coupons %}
459
+ <option value="{{ coupon }}">{{ coupon }}</option>
460
+ {% endfor %}
461
+ </select>
462
+ {% endif %}
 
 
 
 
 
463
 
464
  <div class="bill-details">
465
  <div class="label">Cart Total</div>
466
  <div class="amount">${{ subtotal }}</div>
 
 
467
  <div class="label">Discount</div>
468
  <div class="amount" id="discountText">-${{ discount }}</div>
 
 
 
 
469
  </div>
 
470
  <div class="dotted-line"></div>
 
471
  <div class="total-bill">
472
+ <div class="label">To Pay</div>
473
+ <div class="amount" id="totalBillText">${{ subtotal }}</div>
474
  </div>
475
  <button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
476
  </div>
477
  </div>
478
  </div>
479
 
480
+ <!-- JavaScript (Unchanged) -->
481
  <script>
 
482
  function updateQuantity(action, itemName, customerEmail) {
483
  let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
484
  let quantity = parseInt(quantityInput.value);
 
485
  if (action === 'increase') {
486
  quantity++;
487
  } else if (action === 'decrease' && quantity > 1) {
488
  quantity--;
489
  }
 
490
  if (isNaN(quantity) || quantity < 1) {
491
  alert("Invalid quantity!");
492
  return;
493
  }
 
494
  fetch('/cart/update_quantity', {
495
  method: 'POST',
496
  headers: { 'Content-Type': 'application/json' },
 
499
  .then(response => response.json())
500
  .then(data => {
501
  if (data.success) {
 
502
  quantityInput.value = quantity;
503
+ let itemElement = quantityInput.closest(".cart-item");
504
  if (itemElement) {
505
  let basePriceElement = itemElement.querySelector(".base-price");
506
  let addonsPriceElement = itemElement.querySelector(".addons-price");
 
507
  if (basePriceElement) {
508
+ basePriceElement.innerText = data.new_item_price.toFixed(2);
509
  }
 
510
  if (addonsPriceElement && data.addons_price !== undefined) {
511
  addonsPriceElement.innerText = data.addons_price.toFixed(2);
512
  }
 
514
  console.error(`Parent cart item element not found for item: ${itemName}`);
515
  }
516
  location.reload();
 
 
517
  } else {
518
  alert("Error updating quantity: " + data.error);
519
  }
520
  })
521
  .catch(err => console.error("Error:", err));
522
  }
523
+
524
  function toggleCouponDropdown() {
525
  let couponDropdown = document.getElementById('couponDropdown');
 
 
526
  if (couponDropdown.style.display === "none" || couponDropdown.style.display === "") {
527
  couponDropdown.style.display = "block";
528
  } else {
529
  couponDropdown.style.display = "none";
530
  }
531
  }
532
+
533
  function calculateDiscount() {
534
+ let couponDropdown = document.getElementById('couponDropdown');
535
+ let selectedCoupon = couponDropdown.value.trim();
536
+ let subtotal = parseFloat("{{ subtotal }}");
 
537
  if (selectedCoupon && selectedCoupon.toLowerCase() !== "none") {
 
538
  let discount = subtotal * 0.10;
539
  let total = subtotal - discount;
 
540
  document.getElementById("discountText").innerText = `$${discount.toFixed(2)}`;
541
  document.getElementById("totalBillText").innerText = `$${total.toFixed(2)}`;
542
  } else {
 
543
  document.getElementById("discountText").innerText = `$0.00`;
544
  document.getElementById("totalBillText").innerText = `$${subtotal.toFixed(2)}`;
545
  }
546
  }
547
+
548
  function proceedToOrder() {
549
  let couponDropdown = document.getElementById('couponDropdown');
 
 
550
  let selectedCoupon = "";
 
 
551
  if (couponDropdown) {
 
552
  if (couponDropdown.value != null) {
553
+ selectedCoupon = couponDropdown.value.trim();
554
  } else {
555
+ selectedCoupon = "";
556
  }
557
  }
 
558
  if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
559
+ selectedCoupon = null;
560
  }
 
561
  fetch('/cart/checkout', {
562
  method: 'POST',
563
  headers: { 'Content-Type': 'application/json' },
 
566
  .then(response => response.json())
567
  .then(data => {
568
  if (data.success) {
569
+ alert(data.message);
570
+ window.location.href = '/order';
571
  } else {
572
+ alert(data.error || data.message);
573
  }
574
  })
575
  .catch(err => console.error('Error during checkout:', err));
576
  }
577
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
  function removeItemFromCart(itemName) {
579
  fetch(`/cart/remove/${encodeURIComponent(itemName)}`, {
580
  method: 'POST',
581
+ headers: { 'Content-Type': 'application/json' }
 
 
582
  })
583
  .then(response => response.json())
584
  .then(data => {
585
  if (data.success) {
586
  alert(data.message);
587
+ location.reload();
588
  } else {
589
  alert(data.message);
590
  }
591
  })
592
  .catch(err => console.error('Error removing item:', err));
593
  }
594
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
595
  function addToCartSuggestion(itemName, itemPrice, itemImage, itemId) {
596
+ const customerEmail = "{{ customer_email }}";
 
597
  const data = {
598
  item_name: itemName,
599
  item_price: itemPrice,
600
  item_image: itemImage,
601
  item_id: itemId,
602
+ addons: [],
603
+ instructions: "",
604
  customer_email: customerEmail
605
  };
 
606
  fetch('/cart/add_suggestion_to_cart', {
607
  method: 'POST',
608
+ headers: { 'Content-Type': 'application/json' },
 
 
609
  body: JSON.stringify(data)
610
  })
611
  .then(response => response.json())
612
  .then(data => {
613
  if (data.success) {
614
  alert('Item added to cart!');
615
+ location.reload();
616
  } else {
617
  alert('Error adding item to cart: ' + data.error);
618
  }
619
  })
620
  .catch(err => console.error('Error adding item:', err));
621
  }
 
 
622
  </script>
 
623
  </body>
624
+ </html>