nagasurendra commited on
Commit
28162e0
·
verified ·
1 Parent(s): d21f06d

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +36 -28
templates/cart.html CHANGED
@@ -570,37 +570,45 @@
570
 
571
 
572
 
573
- function proceedToOrder() {
574
- let couponDropdown = document.getElementById('couponDropdown');
575
 
576
- // Check if the coupon dropdown exists and is visible
577
- let selectedCoupon = ""; // Default to an empty string if no coupon dropdown exists
578
- if (couponDropdown) {
579
- selectedCoupon = couponDropdown.value ? couponDropdown.value.trim() : ""; // Safely handle if value is null or undefined
580
- }
581
 
582
- // Proceed without coupon if none is selected (or if dropdown is missing)
583
- if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
584
- selectedCoupon = null; // Treat as no coupon selected
585
- }
586
-
587
- // Send the selected coupon to the backend for processing
588
- fetch('/checkout', {
589
- method: 'POST',
590
- headers: { 'Content-Type': 'application/json' },
591
- body: JSON.stringify({ selectedCoupon: selectedCoupon })
592
- })
593
- .then(response => response.json())
594
- .then(data => {
595
- if (data.success) {
596
- alert(data.message); // Success message
597
- window.location.href = '/order'; // Redirect to order page
598
- } else {
599
- alert(data.error || data.message); // Handle error message
600
- }
601
- })
602
- .catch(err => console.error('Error during checkout:', err));
 
 
 
 
 
 
 
603
  }
 
 
 
 
604
 
605
 
606
  function calculateSubtotal() {
 
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
595
+ fetch('/checkout', {
596
+ method: 'POST',
597
+ headers: { 'Content-Type': 'application/json' },
598
+ body: JSON.stringify({ selectedCoupon: selectedCoupon })
599
+ })
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() {