Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +17 -31
templates/cart.html
CHANGED
|
@@ -386,42 +386,28 @@
|
|
| 386 |
}
|
| 387 |
|
| 388 |
function calculateDiscount() {
|
| 389 |
-
let couponDropdown = document.getElementById('couponDropdown');
|
| 390 |
-
let selectedCoupon = couponDropdown.value.trim();
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
| 398 |
-
|
| 399 |
-
|
| 400 |
-
|
| 401 |
-
|
| 402 |
-
})
|
| 403 |
-
})
|
| 404 |
-
.then(response => response.json())
|
| 405 |
-
.then(data => {
|
| 406 |
-
// Update the UI with the response (success or error)
|
| 407 |
-
if (data.success) {
|
| 408 |
-
document.getElementById("discountText").innerText = `$${data.discount.toFixed(2)}`;
|
| 409 |
-
document.getElementById("totalBillText").innerText = `$${data.totalBill.toFixed(2)}`;
|
| 410 |
-
} else {
|
| 411 |
-
alert(data.message);
|
| 412 |
-
}
|
| 413 |
-
})
|
| 414 |
-
.catch(error => {
|
| 415 |
-
console.error('Error:', error);
|
| 416 |
-
alert('There was an error applying the coupon.');
|
| 417 |
-
});
|
| 418 |
} else {
|
| 419 |
-
//
|
| 420 |
-
|
|
|
|
| 421 |
}
|
| 422 |
}
|
| 423 |
|
| 424 |
|
|
|
|
| 425 |
function proceedToOrder() {
|
| 426 |
let couponCheckbox = document.getElementById('couponCheckbox');
|
| 427 |
let couponDropdown = document.getElementById('couponDropdown');
|
|
|
|
| 386 |
}
|
| 387 |
|
| 388 |
function calculateDiscount() {
|
| 389 |
+
let couponDropdown = document.getElementById('couponDropdown'); // Get coupon dropdown
|
| 390 |
+
let selectedCoupon = couponDropdown.value.trim(); // Get the selected coupon value
|
| 391 |
+
let subtotal = parseFloat("{{ subtotal }}"); // Get the subtotal (from the backend)
|
| 392 |
+
|
| 393 |
+
// If a valid coupon is selected
|
| 394 |
+
if (selectedCoupon && selectedCoupon.toLowerCase() !== "none") {
|
| 395 |
+
// Apply 10% discount
|
| 396 |
+
let discount = subtotal * 0.10;
|
| 397 |
+
let total = subtotal - discount;
|
| 398 |
+
|
| 399 |
+
// Update UI with discount and total bill
|
| 400 |
+
document.getElementById("discountText").innerText = `$${discount.toFixed(2)}`;
|
| 401 |
+
document.getElementById("totalBillText").innerText = `$${total.toFixed(2)}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 402 |
} else {
|
| 403 |
+
// If no coupon is selected or "None" is selected, reset the discount
|
| 404 |
+
document.getElementById("discountText").innerText = `$0.00`;
|
| 405 |
+
document.getElementById("totalBillText").innerText = `$${subtotal.toFixed(2)}`;
|
| 406 |
}
|
| 407 |
}
|
| 408 |
|
| 409 |
|
| 410 |
+
|
| 411 |
function proceedToOrder() {
|
| 412 |
let couponCheckbox = document.getElementById('couponCheckbox');
|
| 413 |
let couponDropdown = document.getElementById('couponDropdown');
|