Spaces:
Runtime error
Runtime error
Update templates/cart.html
Browse files- templates/cart.html +182 -156
templates/cart.html
CHANGED
|
@@ -10,23 +10,39 @@
|
|
| 10 |
|
| 11 |
body {
|
| 12 |
font-family: Arial, sans-serif;
|
| 13 |
-
background-color:
|
| 14 |
color: #333;
|
| 15 |
}
|
| 16 |
.cart-container {
|
| 17 |
max-width: 768px;
|
| 18 |
margin: 20px auto;
|
| 19 |
padding: 15px;
|
| 20 |
-
background-color: #
|
| 21 |
border-radius: 10px;
|
|
|
|
| 22 |
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
| 23 |
}
|
| 24 |
.cart-container2 {
|
| 25 |
-
background-color
|
| 26 |
}
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
display: flex;
|
| 31 |
align-items: flex-start;
|
| 32 |
justify-content: space-between;
|
|
@@ -36,19 +52,23 @@
|
|
| 36 |
box-sizing: border-box;
|
| 37 |
min-height: 100px;
|
| 38 |
position: relative; /* Make the cart item a reference for the absolute positioning of the remove icon */
|
|
|
|
|
|
|
| 39 |
}
|
| 40 |
-
|
| 41 |
.remove-btn {
|
| 42 |
border: none; /* Remove the border around the button */
|
| 43 |
background-color: transparent; /* Transparent background */
|
| 44 |
cursor: pointer; /* Change cursor to pointer */
|
| 45 |
-
font-size: 1.
|
| 46 |
margin-bottom: 10px; /* Add space below the delete icon */
|
| 47 |
transition: color 0.3s ease; /* Smooth transition for icon color */
|
| 48 |
position: relative; /* Make it relative for movement */
|
| 49 |
-
top: -
|
| 50 |
left: 50px; /* Move the button 30px to the right */
|
| 51 |
}
|
|
|
|
|
|
|
|
|
|
| 52 |
/* Hover effect */
|
| 53 |
.remove-btn:hover {
|
| 54 |
color: black; /* Change the icon color to black on hover */
|
|
@@ -59,53 +79,53 @@
|
|
| 59 |
outline: none; /* Remove the outline */
|
| 60 |
background-color: transparent; /* Keep background transparent after clicking */
|
| 61 |
}
|
|
|
|
| 62 |
.text-primary {
|
| 63 |
-
color: #
|
| 64 |
text-align: right; /* Center-align the price */
|
|
|
|
| 65 |
white-space: nowrap; /* Prevent price text from wrapping */
|
| 66 |
}
|
| 67 |
-
/*
|
| 68 |
.image-wrapper {
|
| 69 |
width: 80px; /* Width of the image container */
|
| 70 |
-
height:
|
| 71 |
-
display: flex;
|
| 72 |
-
align-items:
|
| 73 |
-
justify-content: center;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
}
|
| 75 |
-
|
| 76 |
-
/* Responsive for mobile devices */
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
.cart-item img {
|
| 80 |
-
width: 100%; /* Fill the image container */
|
| 81 |
-
height: auto !important; /* Maintain aspect ratio */
|
| 82 |
-
object-fit: contain;
|
| 83 |
-
border-radius: 8px; /* Optional: rounded corners */
|
| 84 |
-
transition: transform 0.3s;/* Ensure the full image is visible */
|
| 85 |
-
|
| 86 |
-
}
|
| 87 |
.cart-item img:hover {
|
| 88 |
transform: scale(1.05);
|
| 89 |
}
|
| 90 |
.cart-item-title {
|
| 91 |
font-size: 1.1rem;
|
| 92 |
-
font-weight:
|
| 93 |
}
|
| 94 |
|
| 95 |
.checkout-button {
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
}
|
| 110 |
.add-back-button {
|
| 111 |
padding: 6px 20px;
|
|
@@ -157,7 +177,16 @@
|
|
| 157 |
padding: 20px;
|
| 158 |
background-color: #fff;
|
| 159 |
border-radius: 12px;
|
|
|
|
| 160 |
box-shadow: 0 6px 15px rgba(0, 0, 0, 0.1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
}
|
| 162 |
/* Coupon Section styling */
|
| 163 |
.coupon-selection {
|
|
@@ -250,15 +279,15 @@
|
|
| 250 |
.total-bill .amount {
|
| 251 |
text-align: right;
|
| 252 |
font-size: 1.1rem;
|
| 253 |
-
color: #
|
| 254 |
}
|
| 255 |
/* Margin to add space for dropdown when visible */
|
| 256 |
.cart-summary.has-dropdown {
|
| 257 |
margin-bottom: 80px; /* Create space below the content when dropdown is visible */
|
| 258 |
}
|
| 259 |
.checkout-button {
|
| 260 |
-
background-color:
|
| 261 |
-
color:
|
| 262 |
padding: 12px;
|
| 263 |
border-radius: 8px;
|
| 264 |
border: none;
|
|
@@ -277,6 +306,7 @@
|
|
| 277 |
padding: 15px;
|
| 278 |
background-color: #fff;
|
| 279 |
border-radius: 10px;
|
|
|
|
| 280 |
}
|
| 281 |
.suggestion-items-container {
|
| 282 |
display: flex;
|
|
@@ -301,6 +331,7 @@
|
|
| 301 |
position: relative; /* For positioning the + icon */
|
| 302 |
text-align: left; /* Align text to the left */
|
| 303 |
overflow: visible; /* Allow the button to overflow outside */
|
|
|
|
| 304 |
}
|
| 305 |
.suggestion-item:hover {
|
| 306 |
transform: scale(1.05); /* Slight zoom effect on hover */
|
|
@@ -356,7 +387,15 @@
|
|
| 356 |
align-items: flex-start; /* Align the price at the top of the cart item (like the item name) */
|
| 357 |
margin-left: auto; /* This will push the price to the right side of the cart item */
|
| 358 |
}
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
</style>
|
| 361 |
</head>
|
| 362 |
<body>
|
|
@@ -480,54 +519,55 @@
|
|
| 480 |
|
| 481 |
<script>
|
| 482 |
// Example function to handle the increase/decrease button clicks
|
| 483 |
-
|
| 484 |
-
|
| 485 |
-
|
| 486 |
-
|
| 487 |
-
|
| 488 |
-
|
| 489 |
-
|
| 490 |
-
|
| 491 |
-
|
| 492 |
-
|
| 493 |
-
|
| 494 |
-
|
| 495 |
-
|
| 496 |
-
alert("Invalid quantity!");
|
| 497 |
-
return;
|
| 498 |
-
}
|
| 499 |
-
|
| 500 |
-
// Send updated quantity to the server
|
| 501 |
-
fetch('/cart/update_quantity', { // Correct URL (prefixed by '/cart')
|
| 502 |
-
method: 'POST',
|
| 503 |
-
headers: { 'Content-Type': 'application/json' },
|
| 504 |
-
body: JSON.stringify({ email: customerEmail, item_name: itemName, quantity: quantity })
|
| 505 |
-
})
|
| 506 |
-
.then(response => response.json())
|
| 507 |
-
.then(data => {
|
| 508 |
-
if (data.success) {
|
| 509 |
-
quantityInput.value = quantity;
|
| 510 |
-
let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
|
| 511 |
-
if (itemElement) {
|
| 512 |
-
let basePriceElement = itemElement.querySelector(".base-price");
|
| 513 |
-
let addonsPriceElement = itemElement.querySelector(".addons-price");
|
| 514 |
-
// Update the base price
|
| 515 |
-
if (basePriceElement) {
|
| 516 |
-
basePriceElement.innerText = data.new_item_price.toFixed(2);
|
| 517 |
-
}
|
| 518 |
-
// Update add-ons price if needed (optional)
|
| 519 |
-
if (addonsPriceElement && data.addons_price !== undefined) {
|
| 520 |
-
addonsPriceElement.innerText = data.addons_price.toFixed(2);
|
| 521 |
-
}
|
| 522 |
}
|
| 523 |
-
|
| 524 |
-
|
| 525 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 526 |
}
|
| 527 |
-
})
|
| 528 |
-
.catch(err => console.error("Error:", err));
|
| 529 |
-
}
|
| 530 |
-
|
| 531 |
function toggleCouponDropdown() {
|
| 532 |
let couponDropdown = document.getElementById('couponDropdown');
|
| 533 |
|
|
@@ -538,19 +578,15 @@
|
|
| 538 |
couponDropdown.style.display = "none";
|
| 539 |
}
|
| 540 |
}
|
| 541 |
-
|
| 542 |
-
|
| 543 |
function calculateDiscount() {
|
| 544 |
let couponDropdown = document.getElementById('couponDropdown'); // Get coupon dropdown
|
| 545 |
let selectedCoupon = couponDropdown.value.trim(); // Get the selected coupon value
|
| 546 |
let subtotal = parseFloat("{{ subtotal }}"); // Get the subtotal (from the backend)
|
| 547 |
-
|
| 548 |
// If a valid coupon is selected
|
| 549 |
if (selectedCoupon && selectedCoupon.toLowerCase() !== "none") {
|
| 550 |
// Apply 10% discount
|
| 551 |
let discount = subtotal * 0.10;
|
| 552 |
let total = subtotal - discount;
|
| 553 |
-
|
| 554 |
// Update UI with discount and total bill
|
| 555 |
document.getElementById("discountText").innerText = `$${discount.toFixed(2)}`;
|
| 556 |
document.getElementById("totalBillText").innerText = `$${total.toFixed(2)}`;
|
|
@@ -560,51 +596,43 @@
|
|
| 560 |
document.getElementById("totalBillText").innerText = `$${subtotal.toFixed(2)}`;
|
| 561 |
}
|
| 562 |
}
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
|
| 566 |
|
| 567 |
function proceedToOrder() {
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
|
| 573 |
-
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
|
|
|
| 601 |
}
|
| 602 |
-
})
|
| 603 |
-
.catch(err => console.error('Error during checkout:', err));
|
| 604 |
-
}
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
function calculateSubtotal() {
|
| 609 |
let subtotal = 0;
|
| 610 |
document.querySelectorAll('.cart-item').forEach(item => {
|
|
@@ -613,7 +641,6 @@
|
|
| 613 |
const addonsPrice = parseFloat(item.querySelector('.addons-price').innerText.replace('$', '')) || 0; // Add-ons Price
|
| 614 |
subtotal += (basePrice * quantity) + addonsPrice; // Include add-ons price in subtotal
|
| 615 |
});
|
| 616 |
-
|
| 617 |
// Update the subtotal in the HTML
|
| 618 |
document.querySelector('.cart-summary p').innerText = `Subtotal: $${subtotal.toFixed(2)}`;
|
| 619 |
return subtotal;
|
|
@@ -636,22 +663,23 @@
|
|
| 636 |
.catch(err => console.error('Error adding suggestion:', err));
|
| 637 |
}
|
| 638 |
function removeItemFromCart(itemName) {
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
| 646 |
-
|
| 647 |
-
|
| 648 |
-
|
| 649 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 650 |
}
|
| 651 |
-
})
|
| 652 |
-
.catch(err => console.error('Error removing item:', err));
|
| 653 |
-
}
|
| 654 |
-
|
| 655 |
function addToCart(itemName, customerEmail) {
|
| 656 |
fetch(`/cart/add_item`, {
|
| 657 |
method: "POST",
|
|
@@ -721,11 +749,9 @@
|
|
| 721 |
})
|
| 722 |
.catch(err => console.error('Error adding item:', err));
|
| 723 |
}
|
| 724 |
-
|
| 725 |
-
|
| 726 |
|
| 727 |
|
| 728 |
</script>
|
| 729 |
|
| 730 |
</body>
|
| 731 |
-
</html>
|
|
|
|
| 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;
|
|
|
|
| 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 */
|
|
|
|
| 79 |
outline: none; /* Remove the outline */
|
| 80 |
background-color: transparent; /* Keep background transparent after clicking */
|
| 81 |
}
|
| 82 |
+
/* Green Color for Prices */
|
| 83 |
.text-primary {
|
| 84 |
+
color: #2e7d32; /* Green color for the prices */
|
| 85 |
text-align: right; /* Center-align the price */
|
| 86 |
+
font-weight: bold; /* Make the price text bold */
|
| 87 |
white-space: nowrap; /* Prevent price text from wrapping */
|
| 88 |
}
|
| 89 |
+
/* For the image container */
|
| 90 |
.image-wrapper {
|
| 91 |
width: 80px; /* Width of the image container */
|
| 92 |
+
height: 80px !important; /* Set the height of the container to match the image */
|
| 93 |
+
display: flex; /* Flex container for the image */
|
| 94 |
+
align-items: center; /* Center image vertically */
|
| 95 |
+
justify-content: center; /* Center image horizontally */
|
| 96 |
+
}
|
| 97 |
+
/* For the image */
|
| 98 |
+
.cart-item img {
|
| 99 |
+
width: 70px; /* Set the width to 70px */
|
| 100 |
+
height: 70px; /* Set the height to 70px */
|
| 101 |
+
object-fit: cover; /* Ensure the image covers the container without stretching */
|
| 102 |
+
border-radius: 5px; /* Optional: rounded corners */
|
| 103 |
+
border: 1px solid #ffcc80; /* Light orange border around images */
|
| 104 |
+
margin: 0; /* Ensure no extra space around the image */
|
| 105 |
}
|
| 106 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
.cart-item img:hover {
|
| 108 |
transform: scale(1.05);
|
| 109 |
}
|
| 110 |
.cart-item-title {
|
| 111 |
font-size: 1.1rem;
|
| 112 |
+
font-weight: bold; /* Make the title text bold */
|
| 113 |
}
|
| 114 |
|
| 115 |
.checkout-button {
|
| 116 |
+
background-color: #ff5722; /* Full Orange color */
|
| 117 |
+
color: #ffffff; /* White text */
|
| 118 |
+
padding: 12px;
|
| 119 |
+
border-radius: 8px;
|
| 120 |
+
border: none;
|
| 121 |
+
width: 100%;
|
| 122 |
+
font-size: 1.2rem;
|
| 123 |
+
cursor: pointer;
|
| 124 |
+
transition: background-color 0.3s, color 0.3s;
|
| 125 |
+
}
|
| 126 |
+
.checkout-button:hover {
|
| 127 |
+
background-color: #ff5722; /* Full Orange color on hover */
|
| 128 |
+
color: #ffffff; /* White text on hover */
|
| 129 |
}
|
| 130 |
.add-back-button {
|
| 131 |
padding: 6px 20px;
|
|
|
|
| 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 {
|
|
|
|
| 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;
|
|
|
|
| 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;
|
|
|
|
| 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 */
|
|
|
|
| 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>
|
|
|
|
| 519 |
|
| 520 |
<script>
|
| 521 |
// Example function to handle the increase/decrease button clicks
|
| 522 |
+
function updateQuantity(action, itemName, customerEmail) {
|
| 523 |
+
let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
|
| 524 |
+
let quantity = parseInt(quantityInput.value);
|
| 525 |
+
// Update quantity based on action
|
| 526 |
+
if (action === 'increase') {
|
| 527 |
+
quantity++;
|
| 528 |
+
} else if (action === 'decrease' && quantity > 1) {
|
| 529 |
+
quantity--;
|
| 530 |
+
}
|
| 531 |
+
// Validate quantity
|
| 532 |
+
if (isNaN(quantity) || quantity < 1) {
|
| 533 |
+
alert("Invalid quantity!");
|
| 534 |
+
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
}
|
| 536 |
+
// Send updated quantity to the server
|
| 537 |
+
fetch('/cart/update_quantity', {
|
| 538 |
+
method: 'POST',
|
| 539 |
+
headers: { 'Content-Type': 'application/json' },
|
| 540 |
+
body: JSON.stringify({ email: customerEmail, item_name: itemName, quantity: quantity })
|
| 541 |
+
})
|
| 542 |
+
.then(response => response.json())
|
| 543 |
+
.then(data => {
|
| 544 |
+
if (data.success) {
|
| 545 |
+
// Update the item price and quantity in the UI
|
| 546 |
+
quantityInput.value = quantity;
|
| 547 |
+
let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
|
| 548 |
+
if (itemElement) {
|
| 549 |
+
let basePriceElement = itemElement.querySelector(".base-price");
|
| 550 |
+
let addonsPriceElement = itemElement.querySelector(".addons-price");
|
| 551 |
+
// Update the base price
|
| 552 |
+
if (basePriceElement) {
|
| 553 |
+
basePriceElement.innerText = data.new_item_price.toFixed(2); // Assuming backend sends this
|
| 554 |
+
}
|
| 555 |
+
// Update add-ons price if needed (optional)
|
| 556 |
+
if (addonsPriceElement && data.addons_price !== undefined) {
|
| 557 |
+
addonsPriceElement.innerText = data.addons_price.toFixed(2);
|
| 558 |
+
}
|
| 559 |
+
} else {
|
| 560 |
+
console.error(`Parent cart item element not found for item: ${itemName}`);
|
| 561 |
+
}
|
| 562 |
+
location.reload();
|
| 563 |
+
// Recalculate subtotal dynamically
|
| 564 |
+
|
| 565 |
+
} else {
|
| 566 |
+
alert("Error updating quantity: " + data.error);
|
| 567 |
+
}
|
| 568 |
+
})
|
| 569 |
+
.catch(err => console.error("Error:", err));
|
| 570 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
function toggleCouponDropdown() {
|
| 572 |
let couponDropdown = document.getElementById('couponDropdown');
|
| 573 |
|
|
|
|
| 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)}`;
|
|
|
|
| 596 |
document.getElementById("totalBillText").innerText = `$${subtotal.toFixed(2)}`;
|
| 597 |
}
|
| 598 |
}
|
|
|
|
|
|
|
|
|
|
| 599 |
|
| 600 |
function proceedToOrder() {
|
| 601 |
+
let couponDropdown = document.getElementById('couponDropdown');
|
| 602 |
+
|
| 603 |
+
// Initialize selectedCoupon to an empty string by default
|
| 604 |
+
let selectedCoupon = "";
|
| 605 |
+
|
| 606 |
+
// Only proceed if couponDropdown exists
|
| 607 |
+
if (couponDropdown) {
|
| 608 |
+
// If the value is not null or undefined, strip the value
|
| 609 |
+
if (couponDropdown.value != null) {
|
| 610 |
+
selectedCoupon = couponDropdown.value.trim(); // safely call .trim() if value is not null
|
| 611 |
+
} else {
|
| 612 |
+
selectedCoupon = ""; // Assign empty string if value is null
|
| 613 |
+
}
|
| 614 |
+
}
|
| 615 |
+
// If no coupon is selected or the value is empty, treat it as no coupon
|
| 616 |
+
if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
|
| 617 |
+
selectedCoupon = null; // Treat it as no coupon selected
|
| 618 |
+
}
|
| 619 |
+
// Send the selected coupon to the backend for processing
|
| 620 |
+
fetch('/checkout', {
|
| 621 |
+
method: 'POST',
|
| 622 |
+
headers: { 'Content-Type': 'application/json' },
|
| 623 |
+
body: JSON.stringify({ selectedCoupon: selectedCoupon })
|
| 624 |
+
})
|
| 625 |
+
.then(response => response.json())
|
| 626 |
+
.then(data => {
|
| 627 |
+
if (data.success) {
|
| 628 |
+
alert(data.message); // Success message
|
| 629 |
+
window.location.href = '/order'; // Redirect to order page
|
| 630 |
+
} else {
|
| 631 |
+
alert(data.error || data.message); // Handle error message
|
| 632 |
+
}
|
| 633 |
+
})
|
| 634 |
+
.catch(err => console.error('Error during checkout:', err));
|
| 635 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 636 |
function calculateSubtotal() {
|
| 637 |
let subtotal = 0;
|
| 638 |
document.querySelectorAll('.cart-item').forEach(item => {
|
|
|
|
| 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;
|
|
|
|
| 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",
|
|
|
|
| 749 |
})
|
| 750 |
.catch(err => console.error('Error adding item:', err));
|
| 751 |
}
|
|
|
|
|
|
|
| 752 |
|
| 753 |
|
| 754 |
</script>
|
| 755 |
|
| 756 |
</body>
|
| 757 |
+
</html>
|