Spaces:
Runtime error
Runtime error
Create templates/cart.html
Browse files- templates/cart.html +77 -0
templates/cart.html
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Cart</title>
|
| 7 |
+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<div class="container mt-4">
|
| 11 |
+
<h1 class="text-center">Cart</h1>
|
| 12 |
+
<div id="cart-items" class="mt-4"></div>
|
| 13 |
+
<div class="d-flex justify-content-between align-items-center mt-4">
|
| 14 |
+
<h5>Total: ₹<span id="cart-total">0.00</span></h5>
|
| 15 |
+
<button class="btn btn-success" onclick="placeOrder()">Place Order</button>
|
| 16 |
+
</div>
|
| 17 |
+
</div>
|
| 18 |
+
|
| 19 |
+
<div class="modal fade" id="thankYouModal" tabindex="-1" aria-hidden="true">
|
| 20 |
+
<div class="modal-dialog">
|
| 21 |
+
<div class="modal-content">
|
| 22 |
+
<div class="modal-body">
|
| 23 |
+
<h5>Thank you for your order!</h5>
|
| 24 |
+
</div>
|
| 25 |
+
<div class="modal-footer">
|
| 26 |
+
<button class="btn btn-primary" onclick="goToMenu()">Back to Menu</button>
|
| 27 |
+
</div>
|
| 28 |
+
</div>
|
| 29 |
+
</div>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<script>
|
| 33 |
+
const cart = JSON.parse(localStorage.getItem('cart')) || [];
|
| 34 |
+
|
| 35 |
+
function renderCart() {
|
| 36 |
+
const cartItemsDiv = document.getElementById('cart-items');
|
| 37 |
+
const cartTotalSpan = document.getElementById('cart-total');
|
| 38 |
+
let total = 0;
|
| 39 |
+
|
| 40 |
+
cartItemsDiv.innerHTML = '';
|
| 41 |
+
cart.forEach(item => {
|
| 42 |
+
total += item.price * item.quantity;
|
| 43 |
+
cartItemsDiv.innerHTML += `
|
| 44 |
+
<div class="d-flex justify-content-between align-items-center mb-3">
|
| 45 |
+
<div>${item.name} - ₹${item.price} x ${item.quantity}</div>
|
| 46 |
+
<div>
|
| 47 |
+
<button class="btn btn-danger btn-sm" onclick="removeItem('${item.name}')">Remove</button>
|
| 48 |
+
</div>
|
| 49 |
+
</div>
|
| 50 |
+
`;
|
| 51 |
+
});
|
| 52 |
+
cartTotalSpan.innerText = total.toFixed(2);
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
function removeItem(name) {
|
| 56 |
+
const index = cart.findIndex(item => item.name === name);
|
| 57 |
+
if (index !== -1) {
|
| 58 |
+
cart.splice(index, 1);
|
| 59 |
+
localStorage.setItem('cart', JSON.stringify(cart));
|
| 60 |
+
renderCart();
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
function placeOrder() {
|
| 65 |
+
localStorage.clear();
|
| 66 |
+
const modal = new bootstrap.Modal(document.getElementById('thankYouModal'));
|
| 67 |
+
modal.show();
|
| 68 |
+
}
|
| 69 |
+
|
| 70 |
+
function goToMenu() {
|
| 71 |
+
window.location.href = "/";
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
renderCart();
|
| 75 |
+
</script>
|
| 76 |
+
</body>
|
| 77 |
+
</html>
|