Spaces:
Running
Running
File size: 10,591 Bytes
327ffe3 | 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 | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Your Cart - ByteBazaar</title>
<link rel="icon" type="image/x-icon" href="/static/favicon.ico">
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://unpkg.com/feather-icons"></script>
</head>
<body class="bg-gray-50">
<!-- Navigation -->
<nav class="bg-white shadow-sm">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div class="flex justify-between h-16">
<div class="flex">
<div class="flex-shrink-0 flex items-center">
<a href="index.html" class="flex items-center">
<i data-feather="shopping-cart" class="text-primary h-6 w-6"></i>
<span class="ml-2 text-xl font-bold text-gray-900">ByteBazaar</span>
</a>
</div>
<div class="hidden sm:ml-6 sm:flex sm:space-x-8">
<a href="index.html" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Home</a>
<a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Explore</a>
<a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Categories</a>
<a href="#" class="border-transparent text-gray-500 hover:border-gray-300 hover:text-gray-700 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Sell</a>
<a href="cart.html" class="border-primary text-gray-900 inline-flex items-center px-1 pt-1 border-b-2 text-sm font-medium">Cart</a>
</div>
</div>
<div class="hidden sm:ml-6 sm:flex sm:items-center">
<div class="relative">
<input type="text" class="border border-gray-300 rounded-full py-2 px-4 pl-10 focus:outline-none focus:ring-2 focus:ring-primary focus:border-transparent" placeholder="Search products...">
<i data-feather="search" class="absolute left-3 top-2.5 text-gray-400"></i>
</div>
<button class="ml-4 bg-primary text-white px-4 py-2 rounded-md text-sm font-medium hover:bg-primary-600 transition duration-150 ease-in-out">Sign In</button>
<button class="ml-4 bg-secondary text-white px-4 py-2 rounded-md text-sm font-medium hover:bg-secondary-600 transition duration-150 ease-in-out">Sign Up</button>
</div>
<div class="-mr-2 flex items-center sm:hidden">
<button type="button" class="inline-flex items-center justify-center p-2 rounded-md text-gray-400 hover:text-gray-500 hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-primary">
<i data-feather="menu"></i>
</button>
</div>
</div>
</div>
</nav>
<!-- Cart Section -->
<div class="max-w-7xl mx-auto py-12 px-4 sm:px-6 lg:px-8">
<h1 class="text-3xl font-bold text-gray-900 mb-8">Your Shopping Cart</h1>
<div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
<!-- Cart Items -->
<div class="lg:col-span-2">
<div id="cart-items" class="bg-white shadow-sm rounded-lg divide-y divide-gray-200">
<!-- Items will be populated by JavaScript -->
<div class="p-6 text-center text-gray-500">
Your cart is empty. Start shopping now!
</div>
</div>
</div>
<!-- Order Summary -->
<div>
<div class="bg-white shadow-sm rounded-lg p-6">
<h2 class="text-lg font-medium text-gray-900 mb-4">Order Summary</h2>
<div class="space-y-4">
<div class="flex justify-between">
<span class="text-gray-600">Subtotal</span>
<span id="subtotal" class="text-gray-900">$0.00</span>
</div>
<div class="flex justify-between">
<span class="text-gray-600">Tax</span>
<span id="tax" class="text-gray-900">$0.00</span>
</div>
<div class="flex justify-between border-t border-gray-200 pt-4">
<span class="text-lg font-medium text-gray-900">Total</span>
<span id="total" class="text-lg font-medium text-gray-900">$0.00</span>
</div>
</div>
<button id="checkout-btn" class="mt-6 w-full bg-primary text-white py-3 rounded-md text-base font-medium hover:bg-primary-600 transition duration-150 ease-in-out">
Proceed to Checkout
</button>
<p class="mt-4 text-sm text-gray-500">
or <a href="index.html" class="text-primary font-medium hover:underline">continue shopping</a>
</p>
</div>
</div>
</div>
</div>
<script>
// Initialize cart from localStorage
let cart = JSON.parse(localStorage.getItem('cart')) || [];
// Update cart display
function updateCartDisplay() {
const cartItemsContainer = document.getElementById('cart-items');
const subtotalElement = document.getElementById('subtotal');
const taxElement = document.getElementById('tax');
const totalElement = document.getElementById('total');
if (cart.length === 0) {
cartItemsContainer.innerHTML = `
<div class="p-6 text-center text-gray-500">
Your cart is empty. Start shopping now!
</div>
`;
subtotalElement.textContent = '$0.00';
taxElement.textContent = '$0.00';
totalElement.textContent = '$0.00';
return;
}
// Calculate totals
const subtotal = cart.reduce((sum, item) => sum + item.price, 0);
const tax = subtotal * 0.08; // 8% tax
const total = subtotal + tax;
// Update summary
subtotalElement.textContent = `$${subtotal.toFixed(2)}`;
taxElement.textContent = `$${tax.toFixed(2)}`;
totalElement.textContent = `$${total.toFixed(2)}`;
// Render cart items
cartItemsContainer.innerHTML = '';
cart.forEach((item, index) => {
const itemElement = document.createElement('div');
itemElement.className = 'p-6 flex items-start';
itemElement.innerHTML = `
<div class="flex-shrink-0 h-20 w-20 rounded-md overflow-hidden bg-gray-200">
<img src="http://static.photos/technology/200x200/${index + 1}" alt="${item.name}" class="h-full w-full object-cover">
</div>
<div class="ml-4 flex-1">
<div class="flex justify-between text-base font-medium text-gray-900">
<h3>${item.name}</h3>
<p class="ml-4">$${item.price.toFixed(2)}</p>
</div>
<div class="mt-2 flex justify-between text-sm text-gray-500">
<div>
<button class="text-primary hover:text-primary-600" onclick="removeItem(${index})">Remove</button>
</div>
<div class="flex items-center">
<button class="text-gray-400 hover:text-gray-600" onclick="updateQuantity(${index}, -1)">
<i data-feather="minus" class="h-4 w-4"></i>
</button>
<span class="mx-2">1</span>
<button class="text-gray-400 hover:text-gray-600" onclick="updateQuantity(${index}, 1)">
<i data-feather="plus" class="h-4 w-4"></i>
</button>
</div>
</div>
</div>
`;
cartItemsContainer.appendChild(itemElement);
});
feather.replace();
}
// Remove item from cart
function removeItem(index) {
cart.splice(index, 1);
localStorage.setItem('cart', JSON.stringify(cart));
updateCartDisplay();
updateCartCount();
}
// Update item quantity (currently just 1 per item)
function updateQuantity(index, change) {
// In a real app, you would update the quantity here
// For now, we'll just show an alert
alert('Quantity adjustment functionality coming soon!');
}
// Update cart count in header
function updateCartCount() {
const cartCount = document.getElementById('cart-count');
if (cartCount) {
cartCount.textContent = cart.length;
cartCount.style.display = cart.length > 0 ? 'flex' : 'none';
}
}
// Checkout button handler
document.getElementById('checkout-btn').addEventListener('click', () => {
if (cart.length === 0) {
alert('Your cart is empty!');
return;
}
alert('Proceeding to checkout!');
// In a real app, this would redirect to a checkout page
});
// Initialize on page load
document.addEventListener('DOMContentLoaded', () => {
updateCartDisplay();
updateCartCount();
});
</script>
</body>
</html> |