logindirectmenu3 / templates /order_summary.html
geethareddy's picture
Create order_summary.html
7c227d7 verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order Summary - Biryani Hub</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f8f8f8;
margin: 0;
padding: 0;
}
.summary-container {
max-width: 800px;
margin: 0 auto;
padding: 20px;
background-color: #fff;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
border-radius: 8px;
margin-top: 50px;
}
h1 {
text-align: center;
font-size: 2.5rem;
color: #333;
margin-bottom: 20px;
}
.order-item {
border-bottom: 1px solid #eee;
padding: 15px 0;
}
.order-total {
font-size: 1.5rem;
font-weight: bold;
text-align: right;
margin-top: 20px;
}
.confirm-btn {
display: block;
width: 100%;
padding: 15px;
font-size: 1.2rem;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
text-align: center;
}
.confirm-btn:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="summary-container">
<h1>Order Summary</h1>
<div id="order-items">
<!-- Order items will be inserted here dynamically -->
</div>
<div class="order-total" id="order-total">Total: $0.00</div>
<button class="confirm-btn" onclick="confirmOrder()">Confirm Order</button>
</div>
<script>
let cart = JSON.parse(localStorage.getItem("cart")) || [];
function loadOrderSummary() {
let orderHTML = "";
let total = 0;
cart.forEach((item, index) => {
total += item.price * item.quantity;
orderHTML += `
<div class="order-item">
<h3>${item.name}</h3>
<p>Quantity: ${item.quantity}</p>
<p>Price: $${item.price.toFixed(2)}</p>
</div>
`;
});
document.getElementById("order-items").innerHTML = orderHTML;
document.getElementById("order-total").innerText = `Total: $${total.toFixed(2)}`;
}
function confirmOrder() {
if (cart.length === 0) {
alert("No items in order!");
return;
}
// Send order data to backend
fetch("/order", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({ cart })
})
.then(response => response.json())
.then(data => {
if (data.success) {
alert("Order confirmed!");
localStorage.removeItem("cart");
window.location.href = "/menu";
} else {
alert("Order failed. Please try again.");
}
})
.catch(error => console.error("Error confirming order:", error));
}
window.onload = loadOrderSummary;
</script>
</body>
</html>