Update templates/cart.html
Browse files- templates/cart.html +436 -641
templates/cart.html
CHANGED
@@ -7,487 +7,406 @@
|
|
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:
|
14 |
-
|
15 |
-
}
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
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 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
.
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
}
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
}
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
.
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
.total-bill {
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
}
|
305 |
-
.total-bill .label {
|
306 |
-
|
307 |
-
}
|
308 |
-
.total-bill .amount {
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
}
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
.
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
}
|
347 |
-
|
348 |
-
.
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
.
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
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 |
-
|
433 |
-
|
434 |
-
<
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
<div class="container">
|
444 |
<div class="cart-container">
|
445 |
-
<div style="text-align: right;">
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
<
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
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 |
-
|
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">
|
@@ -500,79 +419,55 @@
|
|
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 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
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 |
-
|
551 |
-
|
552 |
</div>
|
553 |
<button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
|
554 |
</div>
|
555 |
</div>
|
556 |
</div>
|
557 |
-
|
558 |
-
|
559 |
<script>
|
560 |
-
//
|
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,217 +476,117 @@
|
|
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");
|
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);
|
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');
|
622 |
-
let selectedCoupon = couponDropdown.value.trim();
|
623 |
-
let subtotal = parseFloat("{{ subtotal }}");
|
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 |
-
|
643 |
-
|
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 })
|
663 |
})
|
664 |
-
.then(response =>
|
665 |
-
|
666 |
-
|
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(
|
697 |
-
location.
|
698 |
} else {
|
699 |
-
alert(data.error);
|
700 |
}
|
701 |
})
|
702 |
-
.catch(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();
|
716 |
} else {
|
717 |
alert(data.message);
|
718 |
}
|
719 |
})
|
720 |
.catch(err => console.error('Error removing item:', err));
|
721 |
}
|
722 |
-
|
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 }}";
|
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: [],
|
769 |
-
instructions: "",
|
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();
|
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 |
-
|
|
|
7 |
<!-- Bootstrap CSS -->
|
8 |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
|
9 |
<style>
|
|
|
10 |
body {
|
11 |
font-family: Arial, sans-serif;
|
12 |
+
background-color: #fdf4e3;
|
13 |
+
color: #333;
|
14 |
+
}
|
15 |
+
.top-bar {
|
16 |
+
background-color: #FF6F3C;
|
17 |
+
width: 100%;
|
18 |
+
padding: 10px 15px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
display: flex;
|
20 |
+
align-items: center;
|
21 |
+
box-sizing: border-box;
|
22 |
+
}
|
23 |
+
.back-link {
|
24 |
+
display: flex;
|
25 |
+
align-items: center;
|
26 |
+
text-decoration: none;
|
27 |
+
}
|
28 |
+
.back-arrow {
|
29 |
+
font-size: 1.8rem;
|
30 |
+
color: #000;
|
31 |
+
font-weight: bold;
|
32 |
+
}
|
33 |
+
.back-label {
|
34 |
+
margin-left: 10px;
|
35 |
+
color: white;
|
36 |
+
font-weight: bold;
|
37 |
+
font-size: 1rem;
|
38 |
+
}
|
39 |
+
h1 {
|
40 |
+
color: #1C1C1C;
|
41 |
+
font-size: 1.2rem;
|
42 |
+
margin: 30px 0 15px;
|
43 |
+
text-align: center;
|
44 |
+
}
|
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 |
+
.cart-container {
|
53 |
+
max-width: 768px;
|
54 |
+
margin: 20px auto;
|
55 |
+
padding: 15px;
|
56 |
+
background-color: #FFFFFF;
|
57 |
+
border-radius: 10px;
|
58 |
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
59 |
+
}
|
60 |
+
.cart-container2 {
|
61 |
+
background-color: #FFFFFF;
|
62 |
+
display: flex;
|
63 |
+
flex-direction: column;
|
64 |
+
padding: 10px;
|
65 |
+
}
|
66 |
+
.cart-item {
|
67 |
+
display: flex;
|
68 |
+
align-items: flex-start;
|
69 |
+
justify-content: space-between;
|
70 |
+
border: 1px solid #fdf4e3;
|
71 |
+
padding: 30px 15px 15px;
|
72 |
+
background-color: #fff;
|
73 |
+
box-sizing: border-box;
|
74 |
+
min-height: 100px;
|
75 |
+
position: relative;
|
76 |
+
border-radius: 8px;
|
77 |
+
}
|
78 |
+
.remove-btn {
|
79 |
+
border: none;
|
80 |
+
background-color: transparent;
|
81 |
+
cursor: pointer;
|
82 |
+
font-size: 1.2rem;
|
83 |
+
margin-bottom: 10px;
|
84 |
+
transition: color 0.3s ease;
|
85 |
+
position: relative;
|
86 |
+
top: -35px;
|
87 |
+
left: 50px;
|
88 |
+
}
|
89 |
+
.remove-btn i {
|
90 |
+
color: red;
|
91 |
+
}
|
92 |
+
.remove-btn:hover {
|
93 |
+
color: black;
|
94 |
+
background-color: transparent;
|
95 |
+
}
|
96 |
+
.remove-btn:focus {
|
97 |
+
outline: none;
|
98 |
+
background-color: transparent;
|
99 |
+
}
|
100 |
+
.text-primary {
|
101 |
+
color: #2e7d32;
|
102 |
+
text-align: right;
|
103 |
+
font-weight: bold;
|
104 |
+
white-space: nowrap;
|
105 |
+
}
|
106 |
+
.image-wrapper {
|
107 |
+
width: 80px;
|
108 |
+
height: 80px !important;
|
109 |
+
display: flex;
|
110 |
+
align-items: center;
|
111 |
+
justify-content: center;
|
112 |
+
}
|
113 |
+
.cart-item img {
|
114 |
+
width: 70px;
|
115 |
+
height: 70px;
|
116 |
+
object-fit: cover;
|
117 |
+
border-radius: 5px;
|
118 |
+
border: 1px solid #ffcc80;
|
119 |
+
margin: 0;
|
120 |
+
}
|
121 |
+
.cart-item img:hover {
|
122 |
+
transform: scale(1.05);
|
123 |
+
}
|
124 |
+
.cart-item-title {
|
125 |
+
font-size: 1.1rem;
|
126 |
+
font-weight: bold;
|
127 |
+
}
|
128 |
+
.checkout-button {
|
129 |
+
background-color: #FF6F3C; /* Updated to vibrant orange */
|
130 |
+
color: #ffffff;
|
131 |
+
padding: 12px;
|
132 |
+
border-radius: 8px;
|
133 |
+
border: none;
|
134 |
+
width: 100%;
|
135 |
+
font-size: 1rem;
|
136 |
+
cursor: pointer;
|
137 |
+
transition: background-color 0.3s, color 0.3s;
|
138 |
+
}
|
139 |
+
.checkout-button:hover {
|
140 |
+
background-color: #E55A2A; /* Slightly darker orange on hover */
|
141 |
+
color: #ffffff;
|
142 |
+
}
|
143 |
+
.add-back-button {
|
144 |
+
padding: 6px 20px;
|
145 |
+
font-size: 0.9rem;
|
146 |
+
border-radius: 20px;
|
147 |
+
border: 1px solid #fff;
|
148 |
+
background-color: #fff;
|
149 |
+
color: #0FAA39;
|
150 |
+
cursor: pointer;
|
151 |
+
transition: background-color 0.3s, color 0.3s;
|
152 |
+
}
|
153 |
+
.add-back-button:hover {
|
154 |
+
background-color: #fff;
|
155 |
+
color: #0FAA39;
|
156 |
+
}
|
157 |
+
.cart-item-details {
|
158 |
+
flex: 1;
|
159 |
+
margin-left: 15px;
|
160 |
+
}
|
161 |
+
.cart-item-quantity {
|
162 |
+
display: flex;
|
163 |
+
align-items: center;
|
164 |
+
margin-top: 5px;
|
165 |
+
}
|
166 |
+
.cart-item-quantity button {
|
167 |
+
width: 24px;
|
168 |
+
height: 24px;
|
169 |
+
border: none;
|
170 |
+
background-color: #f0f0f0;
|
171 |
+
font-size: 0.8rem;
|
172 |
+
font-weight: bold;
|
173 |
+
cursor: pointer;
|
174 |
+
}
|
175 |
+
.cart-item-quantity input {
|
176 |
+
width: 40px;
|
177 |
+
text-align: center;
|
178 |
+
border: none;
|
179 |
+
background-color: #f8f9fa;
|
180 |
+
font-size: 1rem;
|
181 |
+
margin: 0 5px;
|
182 |
+
}
|
183 |
+
.cart-summary {
|
184 |
+
position: relative;
|
185 |
+
text-align: left;
|
186 |
+
margin-top: 15px;
|
187 |
+
padding: 20px;
|
188 |
+
background-color: #fff;
|
189 |
+
border-radius: 12px;
|
190 |
+
border: 2px solid #fdf4e3;
|
191 |
+
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
|
192 |
+
}
|
193 |
+
.cart-item-instructions {
|
194 |
+
word-wrap: break-word;
|
195 |
+
white-space: normal;
|
196 |
+
overflow: hidden;
|
197 |
+
max-width: 100%;
|
198 |
+
word-break: break-word;
|
199 |
+
}
|
200 |
+
.coupon-selection {
|
201 |
+
display: flex;
|
202 |
+
justify-content: space-between;
|
203 |
+
align-items: center;
|
204 |
+
font-size: 1rem;
|
205 |
+
margin-bottom: 20px;
|
206 |
+
position: relative;
|
207 |
+
}
|
208 |
+
.coupon-selection label {
|
209 |
+
font-weight: bold;
|
210 |
+
color: black;
|
211 |
+
}
|
212 |
+
.coupon-selection a {
|
213 |
+
color: #007bff;
|
214 |
+
font-size: 1rem;
|
215 |
+
text-decoration: none;
|
216 |
+
text-align: right;
|
217 |
+
}
|
218 |
+
#couponDropdown {
|
219 |
+
width: 30%;
|
220 |
+
display: none;
|
221 |
+
background-color: #fff;
|
222 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
|
223 |
+
z-index: 10;
|
224 |
+
margin-top: 10px;
|
225 |
+
margin-left: auto;
|
226 |
+
margin-right: 0;
|
227 |
+
}
|
228 |
+
#couponDropdown.show {
|
229 |
+
display: block;
|
230 |
+
}
|
231 |
+
.bill-details {
|
232 |
+
display: grid;
|
233 |
+
grid-template-columns: 1fr 1fr;
|
234 |
+
grid-gap: 10px;
|
235 |
+
margin-bottom: 10px;
|
236 |
+
}
|
237 |
+
.bill-details .label {
|
238 |
+
font-weight: 600;
|
239 |
+
font-size: 1rem;
|
240 |
+
}
|
241 |
+
.bill-details .amount {
|
242 |
+
text-align: right;
|
243 |
+
font-weight: 600;
|
244 |
+
font-size: 1rem;
|
245 |
+
}
|
246 |
+
.dotted-line {
|
247 |
+
border-bottom: 2px dotted #ccc;
|
248 |
+
margin: 15px 0;
|
249 |
+
}
|
250 |
+
.total-bill {
|
251 |
+
display: grid;
|
252 |
+
grid-template-columns: 1fr 1fr;
|
253 |
+
font-weight: 600;
|
254 |
+
font-size: 1.2rem;
|
255 |
+
margin-top: 10px;
|
256 |
+
margin-bottom: 10px;
|
257 |
+
}
|
258 |
+
.total-bill .label {
|
259 |
+
font-size: 1.1rem;
|
260 |
+
}
|
261 |
+
.total-bill .amount {
|
262 |
+
text-align: right;
|
263 |
+
font-size: 1.1rem;
|
264 |
+
color: #2e7d32;
|
265 |
+
}
|
266 |
+
.cart-summary.has-dropdown {
|
267 |
+
margin-bottom: 80px;
|
268 |
+
}
|
269 |
+
.suggestion-section {
|
270 |
+
margin-top: 25px;
|
271 |
+
padding: 15px;
|
272 |
+
background-color: #fff;
|
273 |
+
border-radius: 10px;
|
274 |
+
border: 2px solid #fdf4e3;
|
275 |
+
}
|
276 |
+
.suggestion-items-container {
|
277 |
+
display: flex;
|
278 |
+
overflow-x: auto;
|
279 |
+
gap: 10px;
|
280 |
+
padding-bottom: 10px;
|
281 |
+
padding-top: 10px;
|
282 |
+
}
|
283 |
+
.suggestion-item {
|
284 |
+
display: flex;
|
285 |
+
align-items: center;
|
286 |
+
justify-content: flex-start;
|
287 |
+
flex-shrink: 0;
|
288 |
+
width: 160px;
|
289 |
+
padding: 10px;
|
290 |
+
border-radius: 8px;
|
291 |
+
background-color: #fff;
|
292 |
+
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
293 |
+
transition: transform 0.3s ease;
|
294 |
+
margin-right: 10px;
|
295 |
+
position: relative;
|
296 |
+
text-align: left;
|
297 |
+
overflow: visible;
|
298 |
+
border: 2px solid #fdf4e3;
|
299 |
+
}
|
300 |
+
.suggestion-item:hover {
|
301 |
+
transform: scale(1.05);
|
302 |
+
}
|
303 |
+
.suggestion-item img {
|
304 |
+
width: 50px;
|
305 |
+
height: 50px;
|
306 |
+
object-fit: cover;
|
307 |
+
border-radius: 5px;
|
308 |
+
margin-right: 12px;
|
309 |
+
}
|
310 |
+
.suggestion-item div {
|
311 |
+
flex-grow: 1;
|
312 |
+
text-align: left;
|
313 |
+
}
|
314 |
+
.add-back-button {
|
315 |
+
position: absolute;
|
316 |
+
top: -5px;
|
317 |
+
right: -10px;
|
318 |
+
font-size: 1rem;
|
319 |
+
padding: 0;
|
320 |
+
width: 30px;
|
321 |
+
height: 30px;
|
322 |
+
background-color: #fff;
|
323 |
+
color: #0FAA39;
|
324 |
+
border: 2px solid #0FAA39;
|
325 |
+
border-radius: 0;
|
326 |
+
cursor: pointer;
|
327 |
+
transition: background-color 0.3s, color 0.3s, border-color 0.3s;
|
328 |
+
z-index: 2;
|
329 |
+
}
|
330 |
+
.add-back-button:hover {
|
331 |
+
background-color: #fff;
|
332 |
+
color: #0FAA39;
|
333 |
+
border-color: #0FAA39;
|
334 |
+
z-index: 3;
|
335 |
+
}
|
336 |
+
.suggestion-items-container::-webkit-scrollbar {
|
337 |
+
height: 8px;
|
338 |
+
}
|
339 |
+
.suggestion-items-container::-webkit-scrollb
|
340 |
+
ar-thumb {
|
341 |
+
background-color: #fff;
|
342 |
+
border-radius: 4px;
|
343 |
+
}
|
344 |
+
.suggestion-items-container::-webkit-scrollbar-track {
|
345 |
+
background-color: #f1f1f1;
|
346 |
+
}
|
347 |
+
.cart-item-actions {
|
348 |
+
display: flex;
|
349 |
+
align-items: flex-start;
|
350 |
+
margin-left: auto;
|
351 |
+
}
|
352 |
+
h4.mb-4.fw-bold {
|
353 |
+
text-align: center;
|
354 |
+
color: #FF5722;
|
355 |
+
}
|
356 |
+
.cart-container h4 {
|
357 |
+
text-align: center;
|
358 |
+
color: #FF5722;
|
359 |
+
font-weight: bold;
|
360 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
</style>
|
362 |
</head>
|
363 |
+
<body>
|
364 |
+
<!-- Top Orange Label Bar -->
|
365 |
+
<div class="top-bar">
|
366 |
+
<a href="/menu" class="back-link">
|
367 |
+
<span class="back-arrow">⟨</span>
|
368 |
+
<span class="back-label">Back to Menu</span>
|
369 |
+
</a>
|
370 |
+
</div>
|
371 |
+
<!-- Order History Title (centered and dark black) -->
|
372 |
+
<div class="order-heading">Your Cart</umt>
|
|
|
373 |
<div class="container">
|
374 |
<div class="cart-container">
|
375 |
+
<div style="text-align: right;"></div>
|
376 |
+
<div class="cart-container2">
|
377 |
+
{% for item in cart_items %}
|
378 |
+
<div class="cart-item">
|
379 |
+
<div class="image-wrapper">
|
380 |
+
<img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
|
381 |
+
</div>
|
382 |
+
<div class="cart-item-details">
|
383 |
+
<div class="cart-item-title">{{ item.Name }}</div>
|
384 |
+
<div class="cart-item-addons">
|
385 |
+
<small class="text-muted">Add-ons: {{ item.Add_Ons__c }}</small>
|
386 |
+
</div>
|
387 |
+
<div class="cart-item-instructions">
|
388 |
+
<small class="text-muted">Instructions: {{ item.Instructions__c or "None" }}</small>
|
389 |
+
</div>
|
390 |
+
<div class="cart-item-quantity mt-2">
|
391 |
+
<button onclick="updateQuantity('decrease', '{{ item.Name }}', '{{ customer_email }}')">-</button>
|
392 |
+
<input type="text" value="{{ item.Quantity__c|int }}" readonly data-item-name="{{ item.Name }}">
|
393 |
+
<button onclick="updateQuantity('increase', '{{ item.Name }}', '{{ customer_email }}')">+</button>
|
394 |
+
</div>
|
395 |
+
</div>
|
396 |
+
<div class="cart-item-actions">
|
397 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
|
398 |
+
<button type="button" class="btn btn-light text-dark remove-btn" onclick="removeItemFromCart('{{ item.Name }}')">
|
399 |
+
<i class="bi bi-trash"></i>
|
400 |
+
</button>
|
401 |
+
<div class="text-primary" style="color: #000 !important;">
|
402 |
+
$<span class="base-price">{{ item.Price__c }}</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
403 |
</div>
|
404 |
</div>
|
405 |
+
</div>
|
406 |
{% else %}
|
407 |
+
<p>No items in your cart.</p>
|
|
|
408 |
{% endfor %}
|
409 |
</div>
|
|
|
|
|
410 |
<!-- Suggestions Section -->
|
411 |
{% if suggestions %}
|
412 |
<div class="suggestion-section">
|
|
|
419 |
<div>{{ suggestion.Name }}</div>
|
420 |
<div class="text-muted">${{ suggestion.Price__c }}</div>
|
421 |
</div>
|
|
|
422 |
<button class="add-back-button" onclick="addToCartSuggestion('{{ suggestion.Name }}', '{{ suggestion.Price__c }}', '{{ suggestion.Image1__c }}', '{{ suggestion.Id }}')">+</button>
|
|
|
|
|
423 |
</div>
|
424 |
{% endfor %}
|
425 |
</div>
|
426 |
</div>
|
|
|
427 |
{% endif %}
|
|
|
428 |
<!-- Subtotal -->
|
429 |
<div class="cart-summary">
|
430 |
+
{% if coupons %}
|
431 |
+
<div class="coupon-selection d-flex justify-content-between align-items-center">
|
432 |
+
<label class="text-dark font-weight-bold mb-0">Apply Coupon</label>
|
433 |
+
<a href="javascript:void(0);" id="applyCouponLink" onclick="toggleCouponDropdown()" class="text-primary">+ Apply Coupon</a>
|
434 |
+
</div>
|
435 |
+
<select id="couponDropdown" class="form-select mt-2" style="display:none;" onchange="calculateDiscount()">
|
436 |
+
<option value="">Select a coupon</option>
|
437 |
+
{% for coupon in coupons %}
|
438 |
+
<option value="{{ coupon }}">{{ coupon }}</option>
|
439 |
+
{% endfor %}
|
440 |
+
</select>
|
441 |
+
{% endif %}
|
|
|
|
|
|
|
|
|
|
|
|
|
442 |
<div class="bill-details">
|
443 |
<div class="label">Cart Total</div>
|
444 |
<div class="amount">${{ subtotal }}</div>
|
|
|
|
|
445 |
<div class="label">Discount</div>
|
446 |
<div class="amount" id="discountText">-${{ discount }}</div>
|
|
|
|
|
|
|
|
|
447 |
</div>
|
|
|
448 |
<div class="dotted-line"></div>
|
|
|
449 |
<div class="total-bill">
|
450 |
+
<div class="label">To Pay</div>
|
451 |
+
<div class="amount" id="totalBillText">${{ subtotal }}</div>
|
452 |
</div>
|
453 |
<button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
|
454 |
</div>
|
455 |
</div>
|
456 |
</div>
|
|
|
|
|
457 |
<script>
|
458 |
+
// Update quantity
|
459 |
function updateQuantity(action, itemName, customerEmail) {
|
460 |
let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
|
461 |
let quantity = parseInt(quantityInput.value);
|
|
|
462 |
if (action === 'increase') {
|
463 |
quantity++;
|
464 |
} else if (action === 'decrease' && quantity > 1) {
|
465 |
quantity--;
|
466 |
}
|
|
|
467 |
if (isNaN(quantity) || quantity < 1) {
|
468 |
alert("Invalid quantity!");
|
469 |
return;
|
470 |
}
|
|
|
471 |
fetch('/cart/update_quantity', {
|
472 |
method: 'POST',
|
473 |
headers: { 'Content-Type': 'application/json' },
|
|
|
476 |
.then(response => response.json())
|
477 |
.then(data => {
|
478 |
if (data.success) {
|
|
|
479 |
quantityInput.value = quantity;
|
480 |
+
let itemElement = quantityInput.closest(".cart-item");
|
481 |
if (itemElement) {
|
482 |
let basePriceElement = itemElement.querySelector(".base-price");
|
|
|
|
|
483 |
if (basePriceElement) {
|
484 |
+
basePriceElement.innerText = data.new_item_price.toFixed(2);
|
|
|
|
|
|
|
|
|
485 |
}
|
|
|
|
|
486 |
}
|
487 |
location.reload();
|
|
|
|
|
488 |
} else {
|
489 |
alert("Error updating quantity: " + data.error);
|
490 |
}
|
491 |
})
|
492 |
.catch(err => console.error("Error:", err));
|
493 |
}
|
494 |
+
// Toggle coupon dropdown
|
495 |
function toggleCouponDropdown() {
|
496 |
let couponDropdown = document.getElementById('couponDropdown');
|
497 |
+
couponDropdown.style.display = couponDropdown.style.display === "none" || couponDropdown.style.display === "" ? "block" : "none";
|
|
|
|
|
|
|
|
|
|
|
|
|
498 |
}
|
499 |
+
// Calculate discount
|
500 |
function calculateDiscount() {
|
501 |
+
let couponDropdown = document.getElementById('couponDropdown');
|
502 |
+
let selectedCoupon = couponDropdown.value.trim();
|
503 |
+
let subtotal = parseFloat("{{ subtotal }}");
|
|
|
504 |
if (selectedCoupon && selectedCoupon.toLowerCase() !== "none") {
|
|
|
505 |
let discount = subtotal * 0.10;
|
506 |
let total = subtotal - discount;
|
|
|
507 |
document.getElementById("discountText").innerText = `$${discount.toFixed(2)}`;
|
508 |
document.getElementById("totalBillText").innerText = `$${total.toFixed(2)}`;
|
509 |
} else {
|
|
|
510 |
document.getElementById("discountText").innerText = `$0.00`;
|
511 |
document.getElementById("totalBillText").innerText = `$${subtotal.toFixed(2)}`;
|
512 |
}
|
513 |
}
|
514 |
+
// Proceed to Order
|
515 |
function proceedToOrder() {
|
516 |
let couponDropdown = document.getElementById('couponDropdown');
|
517 |
+
let selectedCoupon = couponDropdown && couponDropdown.value ? couponDropdown.value.trim() : null;
|
518 |
+
if (selectedCoupon === "" || selectedCoupon.toLowerCase() === "none") {
|
519 |
+
selectedCoupon = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
520 |
}
|
|
|
521 |
fetch('/checkout', {
|
522 |
method: 'POST',
|
523 |
headers: { 'Content-Type': 'application/json' },
|
524 |
body: JSON.stringify({ selectedCoupon: selectedCoupon })
|
525 |
})
|
526 |
+
.then(response => {
|
527 |
+
if (!response.ok) {
|
528 |
+
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
|
|
|
|
|
|
|
529 |
}
|
530 |
+
return response.json();
|
531 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
532 |
.then(data => {
|
533 |
if (data.success) {
|
534 |
+
alert(data.message || "Order processed successfully!");
|
535 |
+
window.location.href = '/order';
|
536 |
} else {
|
537 |
+
alert(data.error || "Failed to process order. Please try again.");
|
538 |
}
|
539 |
})
|
540 |
+
.catch(err => {
|
541 |
+
console.error('Error during checkout:', err);
|
542 |
+
alert("An error occurred while processing your order. Please try again.");
|
543 |
+
});
|
544 |
}
|
545 |
+
// Remove item from cart
|
546 |
function removeItemFromCart(itemName) {
|
547 |
fetch(`/cart/remove/${encodeURIComponent(itemName)}`, {
|
548 |
method: 'POST',
|
549 |
+
headers: { 'Content-Type': 'application/json' }
|
|
|
|
|
550 |
})
|
551 |
.then(response => response.json())
|
552 |
.then(data => {
|
553 |
if (data.success) {
|
554 |
alert(data.message);
|
555 |
+
location.reload();
|
556 |
} else {
|
557 |
alert(data.message);
|
558 |
}
|
559 |
})
|
560 |
.catch(err => console.error('Error removing item:', err));
|
561 |
}
|
562 |
+
// Add suggestion to cart
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
563 |
function addToCartSuggestion(itemName, itemPrice, itemImage, itemId) {
|
564 |
+
const customerEmail = "{{ customer_email }}";
|
|
|
565 |
const data = {
|
566 |
item_name: itemName,
|
567 |
item_price: itemPrice,
|
568 |
item_image: itemImage,
|
569 |
item_id: itemId,
|
570 |
+
addons: [],
|
571 |
+
instructions: "",
|
572 |
customer_email: customerEmail
|
573 |
};
|
|
|
574 |
fetch('/cart/add_suggestion_to_cart', {
|
575 |
method: 'POST',
|
576 |
+
headers: { 'Content-Type': 'application/json' },
|
|
|
|
|
577 |
body: JSON.stringify(data)
|
578 |
})
|
579 |
.then(response => response.json())
|
580 |
.then(data => {
|
581 |
if (data.success) {
|
582 |
alert('Item added to cart!');
|
583 |
+
location.reload();
|
584 |
} else {
|
585 |
alert('Error adding item to cart: ' + data.error);
|
586 |
}
|
587 |
})
|
588 |
.catch(err => console.error('Error adding item:', err));
|
589 |
}
|
|
|
|
|
590 |
</script>
|
|
|
591 |
</body>
|
592 |
+
</html>
|
|