-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshop.js
More file actions
48 lines (41 loc) · 1.89 KB
/
shop.js
File metadata and controls
48 lines (41 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
document.getElementById('filterToggle').addEventListener('click', function () {
const sidebar = document.getElementById('filterSidebar');
const chevron = document.getElementById('filterChevron');
// Toggle sidebar visibility
sidebar.classList.toggle('hidden');
// Rotate chevron icon
chevron.classList.toggle('rotate-180');
// Close when clicking outside on mobile
if (!sidebar.classList.contains('hidden')) {
document.addEventListener('click', function closeSidebar(e) {
if (!sidebar.contains(e.target) && e.target.id !== 'filterToggle') {
sidebar.classList.add('hidden');
chevron.classList.remove('rotate-180');
document.removeEventListener('click', closeSidebar);
}
function updateSummary() {
let subtotal = cart.reduce((sum, item) => sum + item.price * item.quantity, 0);
let shipping = 5; // default shipping fee
let discount = 0;
let tax = subtotal * 0.05; // 5% tax
if (appliedPromo) {
const promo = promos[appliedPromo];
if (promo.type === "discount") {
discount = (promo.amount / 100) * subtotal;
} else if (promo.type === "shipping") {
shipping = 0;
}
}
const total = subtotal - discount + tax + shipping;
document.getElementById("summary").innerHTML = `
<p>Subtotal: <strong>$${subtotal.toFixed(2)}</strong></p>
<p>Shipping: <strong>$${shipping.toFixed(2)}</strong></p>
<p>Tax: <strong>$${tax.toFixed(2)}</strong></p>
<p>Discount: <strong>-$${discount.toFixed(2)}</strong></p>
<hr class="my-2">
<p class="text-xl font-bold">Total: <strong>$${total.toFixed(2)}</strong></p>
`;
}
});
}
});