Spaces:
Sleeping
Sleeping
Update templates/cart.html
Browse files- templates/cart.html +22 -38
templates/cart.html
CHANGED
@@ -288,17 +288,18 @@
|
|
288 |
{% if coupons %}
|
289 |
<div class="coupon-selection">
|
290 |
<label>
|
291 |
-
|
292 |
-
Apply Coupon
|
293 |
</label>
|
294 |
-
<select id="couponDropdown" class="form-select mt-2"
|
295 |
<option value="">Select a coupon</option>
|
296 |
{% for coupon in coupons %}
|
297 |
<option value="{{ coupon }}">{{ coupon }}</option>
|
298 |
-
|
299 |
</select>
|
300 |
</div>
|
301 |
{% endif %}
|
|
|
302 |
<div class="bill-details">
|
303 |
<div class="label">Cart Total</div>
|
304 |
<div class="amount">${{ subtotal }}</div>
|
@@ -379,51 +380,34 @@
|
|
379 |
.catch(err => console.error("Error:", err));
|
380 |
}
|
381 |
function toggleCouponDropdown() {
|
382 |
-
let couponCheckbox = document.getElementById('couponCheckbox');
|
383 |
let couponDropdown = document.getElementById('couponDropdown');
|
384 |
-
|
385 |
-
|
386 |
-
couponDropdown.disabled = !couponCheckbox.checked;
|
387 |
-
|
388 |
-
// If unchecked, reset discount and total
|
389 |
-
if (!couponCheckbox.checked) {
|
390 |
-
document.getElementById("discountText").innerText = `Discount: $0`;
|
391 |
-
document.getElementById("totalBillText").innerText = `Total Bill: ${{ subtotal }}`;
|
392 |
-
}
|
393 |
}
|
394 |
|
395 |
function calculateDiscount() {
|
396 |
-
let couponCheckbox = document.getElementById('couponCheckbox');
|
397 |
let couponDropdown = document.getElementById('couponDropdown');
|
398 |
let subtotal = parseFloat("{{ subtotal }}");
|
399 |
|
400 |
-
// If
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
}
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
// Apply 10% discount
|
413 |
-
let discount = subtotal * 0.10;
|
414 |
-
let total = subtotal - discount;
|
415 |
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
document.getElementById("totalBillText").innerText = `$${subtotal.toFixed(2)}`;
|
424 |
-
}
|
425 |
}
|
426 |
|
|
|
427 |
function proceedToOrder() {
|
428 |
let couponCheckbox = document.getElementById('couponCheckbox');
|
429 |
let couponDropdown = document.getElementById('couponDropdown');
|
|
|
288 |
{% if coupons %}
|
289 |
<div class="coupon-selection">
|
290 |
<label>
|
291 |
+
Apply Coupon
|
292 |
+
<a href="javascript:void(0);" id="applyCouponLink" onclick="toggleCouponDropdown()"> + Apply Coupon</a>
|
293 |
</label>
|
294 |
+
<select id="couponDropdown" class="form-select mt-2" style="display:none;" onchange="calculateDiscount()">
|
295 |
<option value="">Select a coupon</option>
|
296 |
{% for coupon in coupons %}
|
297 |
<option value="{{ coupon }}">{{ coupon }}</option>
|
298 |
+
{% endfor %}
|
299 |
</select>
|
300 |
</div>
|
301 |
{% endif %}
|
302 |
+
|
303 |
<div class="bill-details">
|
304 |
<div class="label">Cart Total</div>
|
305 |
<div class="amount">${{ subtotal }}</div>
|
|
|
380 |
.catch(err => console.error("Error:", err));
|
381 |
}
|
382 |
function toggleCouponDropdown() {
|
|
|
383 |
let couponDropdown = document.getElementById('couponDropdown');
|
384 |
+
// Toggle the visibility of the coupon dropdown
|
385 |
+
couponDropdown.style.display = couponDropdown.style.display === "none" ? "block" : "none";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
}
|
387 |
|
388 |
function calculateDiscount() {
|
|
|
389 |
let couponDropdown = document.getElementById('couponDropdown');
|
390 |
let subtotal = parseFloat("{{ subtotal }}");
|
391 |
|
392 |
+
// If a coupon is selected
|
393 |
+
let selectedCoupon = couponDropdown.value.trim();
|
394 |
+
if (!selectedCoupon || selectedCoupon.toLowerCase() === "none") {
|
395 |
+
alert("Please select a valid coupon.");
|
396 |
+
document.getElementById("discountText").innerText = `Discount: $0`;
|
397 |
+
document.getElementById("totalBillText").innerText = `Total Bill: $${subtotal.toFixed(2)}`;
|
398 |
+
return;
|
399 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
|
401 |
+
// Apply a 10% discount (or your desired logic here)
|
402 |
+
let discount = subtotal * 0.10;
|
403 |
+
let total = subtotal - discount;
|
404 |
|
405 |
+
// Update the UI with discount and new total
|
406 |
+
document.getElementById("discountText").innerText = `$${discount.toFixed(2)}`;
|
407 |
+
document.getElementById("totalBillText").innerText = `$${total.toFixed(2)}`;
|
|
|
|
|
408 |
}
|
409 |
|
410 |
+
|
411 |
function proceedToOrder() {
|
412 |
let couponCheckbox = document.getElementById('couponCheckbox');
|
413 |
let couponDropdown = document.getElementById('couponDropdown');
|