Update templates/cart.html (#4)
Browse files- Update templates/cart.html (fa60002298fabb911e96e05dcd98ea6859cb03fb)
Co-authored-by: Surendra <[email protected]>
- templates/cart.html +20 -7
templates/cart.html
CHANGED
|
@@ -569,14 +569,26 @@
|
|
| 569 |
|
| 570 |
|
| 571 |
|
|
|
|
| 572 |
function proceedToOrder() {
|
| 573 |
let couponDropdown = document.getElementById('couponDropdown');
|
| 574 |
-
let selectedCoupon = couponDropdown.value.trim(); // Get selected coupon from the dropdown
|
| 575 |
|
| 576 |
-
//
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 580 |
}
|
| 581 |
|
| 582 |
// Send the selected coupon to the backend for processing
|
|
@@ -588,16 +600,17 @@
|
|
| 588 |
.then(response => response.json())
|
| 589 |
.then(data => {
|
| 590 |
if (data.success) {
|
| 591 |
-
alert(data.message);
|
| 592 |
window.location.href = '/order'; // Redirect to order page
|
| 593 |
} else {
|
| 594 |
-
alert(data.error || data.message);
|
| 595 |
}
|
| 596 |
})
|
| 597 |
.catch(err => console.error('Error during checkout:', err));
|
| 598 |
}
|
| 599 |
|
| 600 |
|
|
|
|
| 601 |
function calculateSubtotal() {
|
| 602 |
let subtotal = 0;
|
| 603 |
document.querySelectorAll('.cart-item').forEach(item => {
|
|
|
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
+
|
| 573 |
function proceedToOrder() {
|
| 574 |
let couponDropdown = document.getElementById('couponDropdown');
|
|
|
|
| 575 |
|
| 576 |
+
// Initialize selectedCoupon to an empty string by default
|
| 577 |
+
let selectedCoupon = "";
|
| 578 |
+
|
| 579 |
+
// Only proceed if couponDropdown exists
|
| 580 |
+
if (couponDropdown) {
|
| 581 |
+
// If the value is not null or undefined, strip the value
|
| 582 |
+
if (couponDropdown.value != null) {
|
| 583 |
+
selectedCoupon = couponDropdown.value.trim(); // safely call .trim() if value is not null
|
| 584 |
+
} else {
|
| 585 |
+
selectedCoupon = ""; // Assign empty string if value is null
|
| 586 |
+
}
|
| 587 |
+
}
|
| 588 |
+
|
| 589 |
+
// If no coupon is selected or the value is empty, treat it as no coupon
|
| 590 |
+
if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
|
| 591 |
+
selectedCoupon = null; // Treat it as no coupon selected
|
| 592 |
}
|
| 593 |
|
| 594 |
// Send the selected coupon to the backend for processing
|
|
|
|
| 600 |
.then(response => response.json())
|
| 601 |
.then(data => {
|
| 602 |
if (data.success) {
|
| 603 |
+
alert(data.message); // Success message
|
| 604 |
window.location.href = '/order'; // Redirect to order page
|
| 605 |
} else {
|
| 606 |
+
alert(data.error || data.message); // Handle error message
|
| 607 |
}
|
| 608 |
})
|
| 609 |
.catch(err => console.error('Error during checkout:', err));
|
| 610 |
}
|
| 611 |
|
| 612 |
|
| 613 |
+
|
| 614 |
function calculateSubtotal() {
|
| 615 |
let subtotal = 0;
|
| 616 |
document.querySelectorAll('.cart-item').forEach(item => {
|