lokesh143 / templates /order-confirmation.html
lokeshloki143's picture
Update templates/order-confirmation.html
4ac92cb verified
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Order Confirmation</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet">
<style>
body {
font-family: Arial, sans-serif;
background-color: #fdf4e3;
color: #333;
}
.top-bar {
background-color: #FF6F3C;
padding: 10px 15px;
display: flex;
align-items: center;
}
.back-link {
display: flex;
align-items: center;
text-decoration: none;
}
.back-arrow {
font-size: 1.8rem;
color: #000;
font-weight: bold;
}
.back-label {
margin-left: 10px;
color: white;
font-weight: bold;
font-size: 1rem;
}
.order-heading {
color: #000;
font-size: 2.5rem;
font-weight: bold;
text-align: center;
margin-top: 30px;
}
.order-container {
max-width: 768px;
margin: 20px auto;
padding: 15px;
background-color: #FFFFFF;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
}
.order-details {
padding: 20px;
background-color: #fff;
border-radius: 12px;
border: 2px solid #fdf4e3;
}
.order-item {
display: flex;
align-items: center;
padding: 10px 0;
border-bottom: 1px solid #f0f0f0;
}
.order-item img {
width: 70px;
height: 70px;
object不少于fit: cover;
border-radius: 5px;
border: 1px solid #ffcc80;
}
.order-item-details {
flex: 1;
margin-left: 15px;
}
.order-item-details small {
display: block;
color: #666;
}
.order-item-price {
font-weight: bold;
color: #2e7d32;
}
.bill-details {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: 10px;
margin-top: 20px;
}
.bill-details .label {
font-weight: 600;
font-size: 1rem;
}
.bill-details .amount {
text-align: right;
font-weight: 600;
font-size: 1rem;
color: #2e7d32;
}
.dotted-line {
border-bottom: 2px dotted #ccc;
margin: 15px 0;
}
.add-more-button {
background-color: #A52A2A;
color: #ffffff;
padding: 12px;
border-radius: 8px;
border: none;
width: 100%;
font-size: 1rem;
cursor: pointer;
margin-top: 20px;
}
.modal {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 1000;
justify-content: center;
align-items: center;
}
.modal-content {
background-color: #fff;
padding: 20px;
border-radius: 10px;
width: 90%;
max-width: 600px;
max-height: 80vh;
overflow-y: auto;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
.modal-content h3 {
text-align: center;
margin-bottom: 20px;
}
.close-modal {
position: absolute;
top: 10px;
right: 15px;
font-size: 1.5rem;
cursor: pointer;
}
.menu-items-container {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 10px;
}
.menu-item {
display: flex;
align-items: center;
justify-content: space-between;
width: calc(50% - 10px);
padding: 10px;
border-radius: 8px;
background-color: #fff;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
border: 2px solid #fdf4e3;
min-height: 70px;
}
.menu-item img {
width: 50px;
height: 50px;
object-fit: cover;
border-radius: 5px;
margin-right: 10px;
border: 1px solid #ffcc80;
}
.menu-item:hover img {
transform: scale(1.05);
}
.menu-item-details {
flex-grow: 1;
font-size: 0.9rem;
}
.menu-item-details strong {
font-size: 1rem;
}
.menu-item-details small {
display: block;
color: #666;
font-size: 0.8rem;
}
.add-back-button {
font-size: 1rem;
width: 30px;
height: 30px;
background-color: #fff;
color: #0FAA39;
border: 2px solid #0FAA39;
border-radius: 50%;
cursor: pointer;
}
.quantity-selector {
display: none;
align-items: center;
}
.quantity-selector button {
width: 28px;
height: 28px;
border: none;
background-color: #f0f0f0;
font-size: 1rem;
border-radius: 4px;
}
.quantity-selector input {
width: 40px;
text-align: center;
border: none;
background-color: #f8f9fa;
font-size: 1rem;
margin: 0 5px;
border-radius: 4px;
}
.customization-section {
display: none;
position: absolute;
top: 100%;
left: 0;
right: 0;
background-color: #fff;
padding: 15px;
border-radius: 8px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
z-index: 10;
border: 2px solid #fdf4e3;
max-height: 300px;
overflow-y: auto;
}
.customization-section.show {
display: block;
}
.customization-section h4 {
font-size: 1.2rem;
margin-bottom: 10px;
}
.customization-section label {
display: block;
margin-bottom: 5px;
font-size: 0.9rem;
}
.customization-section textarea {
width: 100%;
height: 60px;
margin-top: 10px;
padding: 5px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 0.9rem;
}
.customization-actions {
display: flex;
justify-content: space-between;
margin-top: 15px;
}
.customization-actions button {
padding: 8px;
border: none;
border-radius: 5px;
cursor: pointer;
width: 48%;
font-size: 0.9rem;
color: #fff;
}
.add-to-cart-btn {
background-color: #A52A2A;
}
.cancel-customization-btn {
background-color: #6c757d;
}
.modal-actions {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
.action-btn {
padding: 10px;
border: none;
border-radius: 8px;
cursor: pointer;
width: 48%;
color: #fff;
}
.add-items-btn {
background-color: #A52A2A;
}
.cancel-btn {
background-color: #6c757d;
}
</style>
</head>
<body>
<div class="top-bar">
<a href="/menu" class="back-link">
<span class="back-arrow"></span>
<span class="back-label">Back to Menu</span>
</a>
</div>
<div class="order-heading">Order Confirmation</div>
<div class="container">
<div class="order-container">
<div class="order-details">
<h5>Order #{{ order_id }}</h5>
{% if order_items %}
{% for item in order_items %}
<div class="order-item">
<img src="{{ item.Image1__c }}" alt="{{ item.Name }}" onerror="this.src='/static/placeholder.jpg';">
<div class="order-item-details">
<strong>{{ item.Name }} x{{ item.Quantity__c }}</strong>
<small>Add-ons: {{ item.Add_Ons__c or "None" }}</small>
<small>Instructions: {{ item.Instructions__c or "None" }}</small>
</div>
<div class="order-item-price">${{ item.Price__c }}</div>
</div>
{% endfor %}
{% else %}
<p>No items in this order.</p>
{% endif %}
<div class="bill-details">
<div class="label">Subtotal</div>
<div class="amount">${{ subtotal }}</div>
<div class="label">Discount</div>
<div class="amount">-${{ discount }}</div>
<div class="label">Total</div>
<div class="amount">${{ total }}</div>
</div>
<div class="dotted-line"></div>
<button class="add-more-button" onclick="showAddMoreModal()">Add More Items</button>
</div>
</div>
</div>
<div class="modal" id="addMoreModal">
<div class="modal-content">
<span class="close-modal" onclick="closeAddMoreModal()">×</span>
<h3>Add More Items</h3>
<div class="menu-items-container" id="menuItems"></div>
<div class="modal-actions">
<button class="action-btn add-items-btn" onclick="addSelectedItems()">Add Selected Items</button>
<button class="action-btn cancel-btn" onclick="closeAddMoreModal()">Cancel</button>
</div>
</div>
</div>
<script>
let menuItems = [];
let availableAddOns = [];
const orderId = "{{ order_id }}";
const customerEmail = "{{ customer_email }}";
function fetchAddOns() {
return fetch('/cart/fetch_add_ons', {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
.then(response => response.json())
.then(data => {
availableAddOns = data.success ? data.add_ons : [];
})
.catch(err => {
console.error('Error fetching add-ons:', err);
availableAddOns = [];
});
}
function showAddMoreModal() {
fetchAddOns().then(() => {
fetch('/cart/fetch_menu_items', {
method: 'GET',
headers: { 'Content-Type': 'application/json' }
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Menu items response:', data);
if (data.success) {
menuItems = data.menu_items || [];
displayMenuItems();
} else {
alert(data.error || 'Failed to load menu items.');
}
})
.catch(err => {
console.error('Error fetching menu items:', err);
alert('An error occurred while fetching menu items.');
});
});
}
function displayMenuItems() {
const menuItemsContainer = document.getElementById('menuItems');
menuItemsContainer.innerHTML = '';
if (menuItems.length === 0) {
menuItemsContainer.innerHTML = '<p>No menu items available.</p>';
document.getElementById('addMoreModal').style.display = 'flex';
return;
}
menuItems.forEach(item => {
const itemElement = document.createElement('div');
itemElement.className = 'menu-item';
itemElement.innerHTML = `
<img src="${item.Image1__c}" alt="${item.Name}" onerror="this.src='/static/placeholder.jpg';">
<div class="menu-item-details">
<strong>${item.Name}</strong>
<small>${item.Veg_NonVeg__c} | ${item.Section__c}</small>
<small>$${item.Price__c.toFixed(2)}</small>
</div>
<button class="add-back-button" onclick="showQuantitySelector('${item.Name}', ${item.Price__c}, '${item.Image1__c}', this)">+</button>
<div class="quantity-selector" data-item-name="${item.Name}">
<button onclick="updateMenuItemQuantity('${item.Name}', 'decrease')">-</button>
<input type="text" value="1" readonly data-item-name="${item.Name}">
<button onclick="updateMenuItemQuantity('${item.Name}', 'increase')">+</button>
</div>
<div class="customization-section" data-item-name="${item.Name}">
<h4>Customize ${item.Name}</h4>
<div id="addOns-${item.Name}">
${availableAddOns.length > 0 ? availableAddOns.map(addon => `
<label>
<input type="checkbox" value="${addon.name}" data-price="${addon.price}">
${addon.name}
</label>
`).join('') : '<p>No add-ons available</p>'}
</div>
<div>
<strong>Special Instructions</strong>
<textarea placeholder="e.g., Less spicy"></textarea>
</div>
<div class="customization-actions">
<button class="add-to-cart-btn" onclick="addToPendingOrder('${item.Name}', ${item.Price__c}, '${item.Image1__c}')">Add to Order</button>
<button class="cancel-customization-btn" onclick="cancelCustomization('${item.Name}')">Cancel</button>
</div>
</div>
`;
menuItemsContainer.appendChild(itemElement);
});
document.getElementById('addMoreModal').style.display = 'flex';
}
function showQuantitySelector(itemName, itemPrice, itemImage, buttonElement) {
document.querySelectorAll('.quantity-selector').forEach(selector => {
selector.style.display = 'none';
selector.querySelector('input').value = 1;
});
document.querySelectorAll('.customization-section').forEach(section => {
section.classList.remove('show');
section.querySelectorAll('input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
section.querySelector('textarea').value = '';
});
document.querySelectorAll('.add-back-button').forEach(btn => btn.style.display = 'inline-block');
const quantitySelector = buttonElement.nextElementSibling;
quantitySelector.style.display = 'flex';
buttonElement.style.display = 'none';
const customizationSection = quantitySelector.nextElementSibling;
customizationSection.classList.add('show');
}
function updateMenuItemQuantity(itemName, action) {
const quantityInput = document.querySelector(`.quantity-selector[data-item-name="${itemName}"] input`);
let quantity = parseInt(quantityInput.value);
if (action === 'increase') {
quantity++;
} else if (action === 'decrease' && quantity > 1) {
quantity--;
}
quantityInput.value = quantity;
}
function cancelCustomization(itemName) {
const quantitySelector = document.querySelector(`.quantity-selector[data-item-name="${itemName}"]`);
const customizationSection = quantitySelector.nextElementSibling;
const addButton = quantitySelector.previousElementSibling;
quantitySelector.querySelector('input').value = 1;
quantitySelector.style.display = 'none';
customizationSection.classList.remove('show');
addButton.style.display = 'inline-block';
customizationSection.querySelectorAll('input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
customizationSection.querySelector('textarea').value = '';
}
function addToPendingOrder(itemName, itemPrice, itemImage) {
const quantitySelector = document.querySelector(`.quantity-selector[data-item-name="${itemName}"]`);
const quantity = parseInt(quantitySelector.querySelector('input').value);
if (isNaN(quantity) || quantity < 1) {
alert('Invalid quantity!');
return;
}
const customizationSection = document.querySelector(`.customization-section[data-item-name="${itemName}"]`);
const addOns = Array.from(customizationSection.querySelectorAll('input[type="checkbox"]:checked')).map(checkbox => checkbox.value);
const instructions = customizationSection.querySelector('textarea').value.trim();
const data = {
order_id: orderId,
customer_email: customerEmail,
item_name: itemName,
item_price: itemPrice,
item_image: itemImage,
addons: addOns,
instructions: instructions,
quantity: quantity
};
fetch('/cart/add_to_pending_order', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log('Add to pending order response:', data);
if (data.success) {
alert('Item added to order!');
cancelCustomization(itemName);
location.reload();
} else {
alert('Error adding item: ' + (data.error || 'Unknown error'));
}
})
.catch(err => {
console.error('Error adding item to order:', err);
alert('An error occurred while adding the item.');
});
}
function addSelectedItems() {
let itemsAdded = false;
document.querySelectorAll('.quantity-selector').forEach(selector => {
if (selector.style.display === 'flex') {
const itemName = selector.getAttribute('data-item-name');
const quantityInput = selector.querySelector('input');
const quantity = parseInt(quantityInput.value);
if (quantity >= 1) {
const item = menuItems.find(i => i.Name === itemName);
if (item) {
addToPendingOrder(itemName, item.Price__c, item.Image1__c);
itemsAdded = true;
}
}
}
});
if (!itemsAdded) {
alert('No items selected to add.');
}
}
function closeAddMoreModal() {
document.getElementById('addMoreModal').style.display = 'none';
document.querySelectorAll('.quantity-selector').forEach(selector => {
selector.style.display = 'none';
selector.querySelector('input').value = 1;
});
document.querySelectorAll('.customization-section').forEach(section => {
section.classList.remove('show');
section.querySelectorAll('input[type="checkbox"]').forEach(checkbox => checkbox.checked = false);
section.querySelector('textarea').value = '';
});
document.querySelectorAll('.add-back-button').forEach(btn => btn.style.display = 'inline-block');
}
</script>
</body>
</html>