nagasurendra commited on
Commit
9ce6625
·
verified ·
1 Parent(s): 767415b

Update templates/cart.html

Browse files
Files changed (1) hide show
  1. 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
- // Send the selected coupon to the backend for processing
393
- if (selectedCoupon) {
394
- // Perform AJAX request to send the selected coupon to the backend
395
- fetch('/checkout', {
396
- method: 'POST',
397
- headers: {
398
- 'Content-Type': 'application/json',
399
- },
400
- body: JSON.stringify({
401
- selectedCoupon: selectedCoupon
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
- // No coupon selected, handle reward points or reset discount
420
- alert('Please select a valid coupon or apply rewards points.');
 
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');