Spaces:
Running
Running
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Shopping Cart - Amazon Clone</title> | |
| <link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet"> | |
| <link rel="stylesheet" href="style.css"> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" integrity="sha512-9usAa10IRO0HhonpyAIVpjrylPvoDwiPUiKdWk5t3PyolY1cOd4DSE0Ga+ri4AuTroPR5aQvXU9xC6qOPnzFeg==" crossorigin="anonymous" referrerpolicy="no-referrer" /> | |
| </head> | |
| <body> | |
| <nav class="bg-gray-800 p-4 text-white"> | |
| <div class="container mx-auto flex items-center justify-between"> | |
| <a href="/" class="text-2xl font-bold">Amazon</a> | |
| <div class="flex items-center"> | |
| <input type="text" placeholder="Search" class="bg-gray-700 text-white px-4 py-2 rounded-md mr-2"> | |
| <button class="bg-yellow-500 text-gray-800 px-4 py-2 rounded-md hover:bg-yellow-400">Search</button> | |
| </div> | |
| <div> | |
| <a href="/cart.html" class="hover:text-yellow-500">Cart</a> | |
| </div> | |
| </div> | |
| </nav> | |
| <main class="container mx-auto mt-8"> | |
| <h1 class="text-2xl font-bold mb-4">Shopping Cart</h1> | |
| <div id="cart-items" class="grid grid-cols-1 gap-4"> | |
| <!-- Cart items will be dynamically added here --> | |
| </div> | |
| <div class="mt-8"> | |
| <h2 class="text-xl font-bold">Order Summary</h2> | |
| <p>Subtotal: <span id="subtotal">$0.00</span></p> | |
| <p>Shipping: <span id="shipping">$5.00</span></p> | |
| <p class="font-bold">Total: <span id="total">$0.00</span></p> | |
| <a href="/checkout.html" class="bg-yellow-500 text-gray-800 px-4 py-2 rounded-md hover:bg-yellow-400 inline-block">Proceed to Checkout</a> | |
| </div> | |
| </main> | |
| <footer class="bg-gray-800 p-4 text-white text-center mt-8"> | |
| <p>© 2024 Amazon Clone</p> | |
| </footer> | |
| <script src="script.js"></script> | |
| <script> | |
| function updateCartPage() { | |
| const cartItems = getCartItems(); | |
| const cartItemsContainer = document.getElementById('cart-items'); | |
| const subtotalElement = document.getElementById('subtotal'); | |
| const totalElement = document.getElementById('total'); | |
| cartItemsContainer.innerHTML = ''; // Clear existing cart items | |
| let subtotal = 0; | |
| cartItems.forEach(item => { | |
| const cartItemDiv = document.createElement('div'); | |
| cartItemDiv.classList.add('cart-item', 'flex', 'items-center', 'justify-between', 'border', 'p-4'); | |
| const imageElement = document.createElement('img'); | |
| imageElement.src = item.image; | |
| imageElement.alt = item.name; | |
| imageElement.classList.add('h-20', 'w-20', 'object-cover'); | |
| cartItemDiv.appendChild(imageElement); | |
| const nameElement = document.createElement('p'); | |
| nameElement.textContent = item.name; | |
| cartItemDiv.appendChild(nameElement); | |
| const priceElement = document.createElement('p'); | |
| priceElement.textContent = `$${item.price}`; | |
| cartItemDiv.appendChild(priceElement); | |
| const quantityElement = document.createElement('p'); | |
| quantityElement.textContent = `Quantity: ${item.quantity}`; | |
| cartItemDiv.appendChild(quantityElement); | |
| const removeButton = document.createElement('button'); | |
| removeButton.textContent = 'Remove'; | |
| removeButton.classList.add('bg-red-500', 'text-white', 'px-2', 'py-1', 'rounded-md', 'hover:bg-red-400'); | |
| removeButton.addEventListener('click', () => { | |
| removeFromCart(item.id); | |
| }); | |
| cartItemDiv.appendChild(removeButton); | |
| cartItemsContainer.appendChild(cartItemDiv); | |
| subtotal += item.price * item.quantity; | |
| }); | |
| subtotalElement.textContent = `$${subtotal.toFixed(2)}`; | |
| const total = subtotal + 5; // Shipping is $5 | |
| totalElement.textContent = `$${total.toFixed(2)}`; | |
| } | |
| // Call updateCartPage on page load | |
| updateCartPage(); | |
| </script> | |
| </body> | |
| </html> |