Spaces:
Sleeping
Sleeping
File size: 13,859 Bytes
dad761f 22c7e1a dad761f 22c7e1a dad761f 22c7e1a dad761f 22c7e1a dd8d73b 22c7e1a ecc63f2 2d9a321 22c7e1a 35bcc12 22c7e1a 85c4a46 876a124 d79d6f9 85c4a46 22c7e1a dad761f 22c7e1a 82813d8 a138d7e 7a42b14 82813d8 ddb0e12 22c7e1a 423a4e7 b36d1ac 85c4a46 b36d1ac 22c7e1a 423a4e7 22c7e1a 85c4a46 a0d5227 85c4a46 a0d5227 85c4a46 423a4e7 85c4a46 423a4e7 85c4a46 5b607ed 070ae9d 85c4a46 1fb91bb 423a4e7 85c4a46 423a4e7 ddb0e12 423a4e7 ddb0e12 85c4a46 22c7e1a 85c4a46 22c7e1a 85c4a46 22c7e1a 85c4a46 22c7e1a 7a42b14 22c7e1a 7a42b14 22c7e1a a86b838 22c7e1a dad761f 22c7e1a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 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 298 299 300 301 302 303 304 305 306 307 308 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 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cart</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f9fa;
}
.cart-container {
max-width: 768px;
margin: 20px auto;
padding: 15px;
background-color: #fff;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.cart-item {
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #dee2e6;
padding: 10px 0;
}
.cart-item img {
width: 70px;
height: 70px;
object-fit: cover;
border-radius: 5px;
}
.cart-item-details {
flex: 1;
margin-left: 15px;
}
.cart-item-title {
font-size: 1rem;
font-weight: bold;
}
.cart-item-quantity {
display: flex;
align-items: center;
margin-top: 5px;
}
.cart-item-quantity button {
width: 30px;
height: 30px;
border: none;
background-color: #f0f0f0;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
}
.cart-item-quantity input {
width: 40px;
text-align: center;
border: none;
background-color: #f8f9fa;
font-size: 1rem;
margin: 0 5px;
}
.cart-summary {
text-align: right;
margin-top: 15px;
}
.checkout-button {
background-color: #007bff;
color: #fff;
padding: 10px;
border-radius: 5px;
border: none;
width: 100%;
font-size: 1.2rem;
cursor: pointer;
margin-top: 10px;
}
.suggestion-section {
margin-top: 20px;
padding: 15px;
background-color: #f8f9fa;
border-radius: 10px;
}
.suggestion-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px 0;
}
.suggestion-item img {
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 5px;
}
.add-back-button {
padding: 5px 15px;
font-size: 0.9rem;
border-radius: 20px;
border: 1px solid #007bff;
color: #007bff;
background-color: #fff;
cursor: pointer;
}
.add-back-button:hover {
background-color: #007bff;
color: #fff;
}
</style>
</head>
<body>
<div class="container">
<div class="cart-container">
<div style="text-align: right;">
<a href="/menu" style="text-decoration: none; font-size: 1.5rem; color: #007bff;">×</a>
</div>
<h4 class="mb-4">Your Cart</h4>
<!-- Cart Items -->
{% for item in cart_items %}
<div class="cart-item">
<img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
<div class="cart-item-details">
<div class="cart-item-title">{{ item.Name }}</div>
<div class="cart-item-addons">
<small class="text-muted">Add-ons: {{ item.Add_Ons__c }}</small>
</div>
<div class="cart-item-instructions">
<small class="text-muted">Instructions: {{ item.Instructions__c or "None" }}</small>
</div>
<div class="cart-item-quantity mt-2">
<!-- Decrease button -->
<button onclick="updateQuantity('decrease', '{{ item.Name }}', '{{ customer_email }}')">-</button>
<!-- Quantity input field -->
<input type="text" value="{{ item.Quantity__c }}" readonly data-item-name="{{ item.Name }}">
<!-- Increase button -->
<button onclick="updateQuantity('increase', '{{ item.Name }}', '{{ customer_email }}')">+</button>
</div>
</div>
<div class="cart-item-actions">
<div class="text-primary">
$<span class="base-price">{{ item.Price__c }}</span>
</div>
<button class="btn btn-danger btn-sm" onclick="removeItemFromCart('{{ item.Name }}')">Remove</button>
</div>
</div>
{% else %}
<p class="text-center">Your cart is empty.</p>
{% endfor %}
<!-- Subtotal -->
<div class="cart-summary">
<p class="fw-bold">Subtotal: ${{ subtotal }}</p>
{% if reward_points >= 500 %}
<div class="reward-points-checkbox">
<label>
<input type="checkbox" id="rewardCheckbox" value="500" onchange="calculateDiscount()">
Apply Reward Points ({{ reward_points }} points available)
</label>
</div>
{% endif %}
<p class="fw-bold" id="discountText">Discount: $0</p>
<p class="fw-bold" id="totalBillText">Total Bill: ${{ subtotal }}</p>
<button class="checkout-button" onclick="proceedToOrder()">Proceed to Order</button>
</div>
</div>
<!-- Suggestions Section -->
<div class="suggestion-section">
{% for suggestion in suggestions %}
<div class="suggestion-item">
<img src="{{ suggestion.Image1__c }}" alt="{{ suggestion.Name }}" onerror="this.src='/static/placeholder.jpg';">
<div>
<div>{{ suggestion.Name }}</div>
<div class="text-muted">${{ suggestion.Price__c }}</div>
</div>
<button class="add-back-button" onclick="addSuggestion('{{ suggestion.Id }}')">Add</button>
</div>
{% endfor %}
</div>
</div>
<script>
// Example function to handle the increase/decrease button clicks
function updateQuantity(action, itemName, customerEmail) {
let quantityInput = document.querySelector(`input[data-item-name="${itemName}"]`);
let quantity = parseInt(quantityInput.value);
// Update quantity based on action
if (action === 'increase') {
quantity++;
} else if (action === 'decrease' && quantity > 1) {
quantity--;
}
// Validate quantity
if (isNaN(quantity) || quantity < 1) {
alert("Invalid quantity!");
return;
}
// Send updated quantity to the server
fetch('/cart/update_quantity', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email: customerEmail, item_name: itemName, quantity: quantity })
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Update the item price and quantity in the UI
quantityInput.value = quantity;
let itemElement = quantityInput.closest(".cart-item"); // Locate the parent cart item
if (itemElement) {
let basePriceElement = itemElement.querySelector(".base-price");
let addonsPriceElement = itemElement.querySelector(".addons-price");
// Update the base price
if (basePriceElement) {
basePriceElement.innerText = data.new_item_price.toFixed(2); // Assuming backend sends this
}
// Update add-ons price if needed (optional)
if (addonsPriceElement && data.addons_price !== undefined) {
addonsPriceElement.innerText = data.addons_price.toFixed(2);
}
} else {
console.error(`Parent cart item element not found for item: ${itemName}`);
}
location.reload();
// Recalculate subtotal dynamically
} else {
alert("Error updating quantity: " + data.error);
}
})
.catch(err => console.error("Error:", err));
}
function calculateDiscount() {
const subtotal = parseFloat("{{ subtotal }}");
const discountElement = document.getElementById('discountText');
const totalElement = document.getElementById('totalBillText');
const checkbox = document.getElementById('rewardCheckbox');
let discount = 0;
if (checkbox.checked) {
discount = subtotal * 0.10; // 10% discount if the checkbox is selected
}
// Update the discount and total bill text
discountElement.innerText = `Discount: $${discount.toFixed(2)}`;
totalElement.innerText = `Total Bill: $${(subtotal - discount).toFixed(2)}`;
}
function calculateSubtotal() {
let subtotal = 0;
document.querySelectorAll('.cart-item').forEach(item => {
const quantity = parseInt(item.querySelector('input').value);
const basePrice = parseFloat(item.querySelector('.base-price').innerText.replace('$', '')); // Base Price
const addonsPrice = parseFloat(item.querySelector('.addons-price').innerText.replace('$', '')) || 0; // Add-ons Price
subtotal += (basePrice * quantity) + addonsPrice; // Include add-ons price in subtotal
});
// Update the subtotal in the HTML
document.querySelector('.cart-summary p').innerText = `Subtotal: $${subtotal.toFixed(2)}`;
return subtotal;
}
function proceedToOrder() {
const useRewardPoints = document.getElementById('rewardCheckbox').checked;
fetch('/checkout', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ useRewardPoints: useRewardPoints })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert(data.message);
window.location.href = '/order'; // Redirect to menu or order confirmation page
} else {
alert(data.error || data.message);
}
})
.catch(err => console.error('Error during checkout:', err));
}
function addSuggestion(itemId) {
fetch(`/cart/add_suggestion/${itemId}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({})
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert('Item added to cart!');
location.reload();
} else {
alert(data.error);
}
})
.catch(err => console.error('Error adding suggestion:', err));
}
function removeItemFromCart(itemName) {
fetch(`/cart/remove/${encodeURIComponent(itemName)}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert(data.message);
location.reload(); // Reload the page to update the cart
} else {
alert(data.message);
}
})
.catch(err => console.error('Error removing item:', err));
}
function addToCart(itemName, customerEmail) {
fetch(`/cart/add_item`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
email: customerEmail,
item_name: itemName.trim(), //Ensure the item name is trimmed
quantity: 0 // DEFAULT QUANTITY PASSED HERE
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert("Item added/updated successfully.");
location.reload(); // Reload the page to update the cart
} else {
alert(data.error || "Failed to add item to cart.");
}
})
.catch(err => console.error("Error adding item to cart:", err));
}
</script>
</body>
</html> |