nagasurendra commited on
Commit
ce87dce
·
verified ·
1 Parent(s): 759b0ab

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +36 -36
templates/cart.html CHANGED
@@ -571,43 +571,43 @@
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
 
 
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