-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorderConfirmation.js
40 lines (34 loc) · 1.45 KB
/
orderConfirmation.js
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
document.addEventListener('DOMContentLoaded', () => {
// Retrieve the checked-out items from localStorage (not the cart)
let order = JSON.parse(localStorage.getItem('order')) || [];
if (order.length === 0) {
document.getElementById('order-details').innerHTML = '<p>No items found in your order.</p>';
document.getElementById('total-amount').innerText = '0';
return;
}
// Display order details
const orderDetailsContainer = document.getElementById('order-details');
let totalAmount = 0;
order.forEach(item => {
const orderItem = document.createElement('div');
orderItem.classList.add('order-item');
orderItem.innerHTML = `
<h3>${item.name}</h3>
<p>Rs. ${item.price} x ${item.quantity}</p>
<p>Total: Rs. ${item.price * item.quantity}</p>
`;
orderDetailsContainer.appendChild(orderItem);
// Update total amount
totalAmount += item.price * item.quantity;
});
// Display total amount
const totalAmountElement = document.getElementById('total-amount');
if (totalAmountElement) {
totalAmountElement.innerText = totalAmount;
}
// Go back to products page
const goBackBtn = document.getElementById('go-back-btn');
goBackBtn.addEventListener('click', () => {
window.location.href = 'products-page-1.html'; // Redirect to product listing page
});
});