nagasurendra commited on
Commit
cb2be1c
·
verified ·
1 Parent(s): af39efe

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. templates/cart.html +8 -11
templates/cart.html CHANGED
@@ -573,18 +573,14 @@
573
  let couponDropdown = document.getElementById('couponDropdown');
574
 
575
  // Check if the coupon dropdown exists and is visible
576
- if (!couponDropdown) {
577
- console.log("Coupon dropdown does not exist.");
578
- alert("No coupons available.");
579
- return;
580
  }
581
 
582
- let selectedCoupon = couponDropdown.value.trim(); // Get selected coupon from the dropdown
583
-
584
- // If no coupon is selected, alert the user
585
  if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
586
- alert("Please select a valid coupon before proceeding.");
587
- return;
588
  }
589
 
590
  // Send the selected coupon to the backend for processing
@@ -596,15 +592,16 @@
596
  .then(response => response.json())
597
  .then(data => {
598
  if (data.success) {
599
- alert(data.message);
600
  window.location.href = '/order'; // Redirect to order page
601
  } else {
602
- alert(data.error || data.message);
603
  }
604
  })
605
  .catch(err => console.error('Error during checkout:', err));
606
  }
607
 
 
608
  function calculateSubtotal() {
609
  let subtotal = 0;
610
  document.querySelectorAll('.cart-item').forEach(item => {
 
573
  let couponDropdown = document.getElementById('couponDropdown');
574
 
575
  // Check if the coupon dropdown exists and is visible
576
+ let selectedCoupon = ""; // Default to an empty string if no coupon dropdown exists
577
+ if (couponDropdown) {
578
+ selectedCoupon = couponDropdown.value.trim(); // Get selected coupon from the dropdown
 
579
  }
580
 
581
+ // Proceed without coupon if none is selected (or if dropdown is missing)
 
 
582
  if (selectedCoupon === "" || selectedCoupon === "None" || selectedCoupon === "Null") {
583
+ selectedCoupon = null; // Treat as no coupon selected
 
584
  }
585
 
586
  // Send the selected coupon to the backend for processing
 
592
  .then(response => response.json())
593
  .then(data => {
594
  if (data.success) {
595
+ alert(data.message); // Success message
596
  window.location.href = '/order'; // Redirect to order page
597
  } else {
598
+ alert(data.error || data.message); // Handle error message
599
  }
600
  })
601
  .catch(err => console.error('Error during checkout:', err));
602
  }
603
 
604
+
605
  function calculateSubtotal() {
606
  let subtotal = 0;
607
  document.querySelectorAll('.cart-item').forEach(item => {