-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcart.html
302 lines (257 loc) · 10.4 KB
/
cart.html
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Cart Page</title>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" rel="stylesheet">
<style>
/* General styling */
body {
font-family: 'Arial', sans-serif;
background-color: #f8f9fa;
}
.container {
margin-top: 30px;
}
.cart-summary {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 8px;
}
.cart-item {
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border-radius: 8px;
padding: 10px;
background-color: #ffffff;
margin-bottom: 15px;
}
.cart-item img {
border-radius: 5px;
}
.btn {
transition: transform 0.2s ease;
}
.btn:hover {
transform: scale(1.05);
}
/* Styling for Coupon section */
.coupon-section input {
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
border-radius: 5px;
border: 1px solid #ccc;
}
/* Styling for secure checkout message */
.secure-checkout {
font-size: 0.9rem;
color: #4CAF50;
font-weight: 500;
display: flex;
justify-content: center;
align-items: center;
}
.secure-checkout i {
margin-right: 8px;
font-size: 1.2rem;
color: #4CAF50;
}
/* 3D Effects for buttons and icons */
.fa-lock, .fa-tag, .fa-trash-alt {
transition: transform 0.2s ease, color 0.3s ease;
}
.fa-lock:hover, .fa-tag:hover, .fa-trash-alt:hover {
transform: scale(1.2);
color: #28a745;
}
/* Layout tweaks */
.cart-summary h4 {
font-size: 1.2rem;
font-weight: bold;
}
/* Clear Cart Button */
.clear-cart {
background-color: #dc3545;
color: white;
}
.clear-cart:hover {
background-color: #c82333;
}
.btn-link {
color: #007bff;
text-decoration: underline;
}
.btn-link:hover {
color: #0056b3;
}
/* Flexbox layout for arranging sections in a row */
.row-custom {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
}
.col-custom {
flex: 1;
margin: 10px;
max-width: 48%;
}
/* Mobile responsiveness */
@media (max-width: 768px) {
.col-custom {
max-width: 100%;
}
}
</style>
</head>
<body>
<!-- Cart Page -->
<section id="cart-page">
<div class="container">
<h2 class="text-center mb-4">Your Cart</h2>
<!-- Flex row for sections -->
<div class="row-custom">
<!-- Cart Items Section -->
<div class="col-custom">
<div id="cart-items"></div>
</div>
<!-- Cart Summary Section -->
<div class="col-custom">
<div class="cart-summary bg-light p-3 rounded">
<h4>Cart Summary</h4>
<p><strong>Total Items: </strong><span id="total-items">0</span></p>
<p><strong>Total: </strong>₵<span id="total-price">0.00</span></p>
<!-- Clear Cart -->
<div class="text-center mt-3">
<button class="btn clear-cart" id="clear-cart">
<i class="fas fa-trash-alt"></i> Clear Cart
</button>
</div>
<!-- Proceed to Checkout -->
<div class="text-center mt-3">
<!-- Secure Checkout Assurance Section -->
<button class="btn btn-primary" onclick="window.location.href='checkout.html'">Proceed to Checkout</button>
<div class="secure-checkout mt-4">
<i class="fas fa-lock"></i> <span>Your checkout is secure</span>
</div><br>
</div>
</div>
</div>
</div>
<!-- Coupon Section -->
<div class="coupon-section mt-4">
<h4>Have a Coupon?</h4>
<div class="input-group">
<input type="text" id="coupon-code" class="form-control" placeholder="Enter promo code" aria-label="Enter promo code">
<div class="input-group-append">
<button class="btn btn-success" id="apply-coupon-btn">
<i class="fas fa-tag"></i> Apply
</button>
</div>
</div>
<div id="discount-message" class="mt-3"></div>
</div>
</div>
</section>
<!-- Cart Summary Footer Section -->
<div class="cart-summary-footer text-center mt-4">
<div class="row">
<!-- Continue Shopping Button -->
<div class="col-6">
<button class="btn btn-link" onclick="window.location.href='marketplace.html'">
<i class="fas fa-arrow-left"></i> Continue Shopping
</button>
</div>
<!-- Add More Products Button -->
<div class="col-6">
<button class="btn btn-link" onclick="window.location.href='marketplace.html'">
<i class="fas fa-plus"></i> Add More Products
</button>
</div>
</div>
</div>
<script>
// JavaScript to apply coupon code and show discount
const applyCouponBtn = document.getElementById("apply-coupon-btn");
const couponCodeInput = document.getElementById("coupon-code");
const discountMessage = document.getElementById("discount-message");
// Sample coupon code and discount (you can replace this with your dynamic logic)
const validCoupons = {
"SAVE10": 10, // 10% off
"FREESHIP": 5, // 5% off for free shipping
"DISCOUNT20": 20, // 20% off
};
applyCouponBtn.addEventListener("click", function() {
const couponCode = couponCodeInput.value.trim().toUpperCase();
if (validCoupons[couponCode]) {
const discountPercentage = validCoupons[couponCode];
const totalAmount = parseFloat(totalPrice.textContent);
const discountAmount = (discountPercentage / 100) * totalAmount;
const discountedTotal = totalAmount - discountAmount;
discountMessage.innerHTML = `<strong>Discount Applied:</strong> ${discountPercentage}% off<br><strong>New Total:</strong> ₵${discountedTotal.toFixed(2)}`;
discountMessage.classList.add("text-success");
// Update total price with discount
totalPrice.textContent = discountedTotal.toFixed(2);
} else {
discountMessage.innerHTML = `<strong>Invalid coupon code.</strong>`;
discountMessage.classList.add("text-danger");
}
// Clear coupon code input field
couponCodeInput.value = "";
});
</script>
<script>
// JavaScript to display cart items, adjust quantity, and remove items
const cart = JSON.parse(localStorage.getItem("cart")) || [];
const cartItemsContainer = document.getElementById("cart-items");
const totalItems = document.getElementById("total-items");
const totalPrice = document.getElementById("total-price");
const clearCartButton = document.getElementById("clear-cart");
// Function to update the cart view
function updateCart() {
cartItemsContainer.innerHTML = "";
let totalQuantity = 0;
let totalAmount = 0;
if (cart.length === 0) {
cartItemsContainer.innerHTML = "<p>Your cart is empty.</p>";
} else {
cart.forEach((item, index) => {
totalQuantity += parseInt(item.quantity);
totalAmount += parseFloat(item.price.replace('₵', '').replace('/ Kg', '').replace('/ Piece', '').replace('/ Dozen', '')) * item.quantity;
const itemDiv = document.createElement("div");
itemDiv.classList.add("cart-item", "d-flex", "justify-content-between", "align-items-center", "mb-3");
itemDiv.innerHTML = `
<div class="d-flex align-items-center">
<img src="${item.image}" alt="${item.name}" style="width: 50px; height: auto; margin-right: 15px;">
<div>${item.name}</div>
<div>₵${item.price} x ${item.quantity}</div>
</div>
<div>
<button class="btn btn-sm btn-danger remove-item" data-index="${index}"><i class="fas fa-trash-alt"></i> Remove</button>
</div>
`;
cartItemsContainer.appendChild(itemDiv);
});
}
// Update total items and price
totalItems.textContent = totalQuantity;
totalPrice.textContent = totalAmount.toFixed(2);
}
// Event listener for removing items from the cart
cartItemsContainer.addEventListener("click", function(event) {
if (event.target.classList.contains("remove-item")) {
const itemIndex = event.target.getAttribute("data-index");
cart.splice(itemIndex, 1);
localStorage.setItem("cart", JSON.stringify(cart));
updateCart();
}
});
// Event listener for clearing the entire cart
clearCartButton.addEventListener("click", function() {
localStorage.removeItem("cart");
cart.length = 0;
updateCart();
});
// Initialize the cart page
updateCart();
</script>
</body>
</html>