-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.php
163 lines (135 loc) · 4.11 KB
/
cart.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="logo.png" type="image/png">
<title>Digital Lunchbox | Cart</title>
<link rel="stylesheet" href="styles.css"> <!-- Link to your CSS file -->
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 20px;
}
.container {
max-width: 900px;
margin: auto;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h1 {
color: #333;
margin-bottom: 20px;
}
.cart-item {
border-bottom: 1px solid #ddd;
padding: 10px 0;
display: flex;
justify-content: space-between;
align-items: center;
}
.cart-item:last-child {
border-bottom: none;
}
.cart-item img {
max-width: 100px;
border-radius: 4px;
}
.cart-item-details {
flex: 1;
margin-left: 20px;
}
.cart-item-name {
font-size: 1.2em;
margin: 0;
}
.cart-item-price {
color: #333;
}
.cart-item-quantity {
margin-top: 5px;
color: #666;
}
.cart-item-remove {
background-color: #dc3545;
color: white;
border: none;
padding: 5px 10px;
border-radius: 4px;
cursor: pointer;
}
.cart-item-remove:hover {
background-color: #c82333;
}
.checkout-btn {
background-color: #28a745;
color: white;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
font-size: 1.2em;
margin-top: 20px;
display: block;
width: 100%;
text-align: center;
}
.checkout-btn:hover {
background-color: #218838;
}
</style>
</head>
<body>
<div class="container">
<a class="nav-link custom-nav-link" id="nav-link5" href="index.php">Home </a>
<h1>Your Cart</h1>
<div id="cart-items">
<!-- Cart items will be dynamically inserted here -->
</div>
<button class="checkout-btn" onclick="checkout()">Order Now</button>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const cartItemsContainer = document.getElementById("cart-items");
let cart = JSON.parse(localStorage.getItem('cart')) || [];
// Function to display cart items
function displayCart() {
cartItemsContainer.innerHTML = ''; // Clear the container
if (cart.length === 0) {
cartItemsContainer.innerHTML = '<p>Your cart is empty.</p>';
return;
}
cart.forEach(item => {
const cartItem = document.createElement("div");
cartItem.className = "cart-item";
cartItem.innerHTML = `
<img src="https://via.placeholder.com/100" alt="${item.name}"> <!-- Placeholder image -->
<div class="cart-item-details">
<p class="cart-item-name">${item.name}</p>
<p class="cart-item-price">KES ${item.price}</p>
<p class="cart-item-quantity">Quantity: ${item.quantity}</p>
</div>
<button class="cart-item-remove" onclick="removeFromCart('${item.name}')">Remove</button>
`;
cartItemsContainer.appendChild(cartItem);
});
}
// Function to remove item from cart
window.removeFromCart = function(name) {
cart = cart.filter(item => item.name !== name);
localStorage.setItem('cart', JSON.stringify(cart));
displayCart();
}
// Function to proceed to checkout
window.checkout = function() {
window.location.href = 'order.php'; // Replace with your checkout page
}
displayCart();
});
</script>
</body>
</html>