where is the product? where is the add to cart? use the the netflix logo but with NGETFLIX
3876e34 verified Download script.js from CharlieMack900/create-a-simple-stor-i8phncx: direct link, hf CLI and curl.
- Browser
- Download file 3.75 kB
-
https://huggingface.co/spaces/CharlieMack900/create-a-simple-stor-i8phncx/resolve/main/script.js
- Command line
-
hf download hf://spaces/CharlieMack900/create-a-simple-stor-i8phncx/script.js
-
curl -L -o script.js https://huggingface.co/spaces/CharlieMack900/create-a-simple-stor-i8phncx/resolve/main/script.js
3.75 kB
| let cart = []; | |
| // Product data | |
| const products = { | |
| 'day-pass': { | |
| name: 'Day Pass', | |
| price: 5, | |
| duration: '24 hours', | |
| image: 'http://static.photos/red/200x200/1' | |
| }, | |
| 'week-pass': { | |
| name: 'Week Pass', | |
| price: 30, | |
| duration: '7 days', | |
| image: 'http://static.photos/red/200x200/2' | |
| }, | |
| 'month-pass': { | |
| name: 'Month Pass', | |
| price: 100, | |
| duration: '30 days', | |
| image: 'http://static.photos/red/200x200/3' | |
| } | |
| }; | |
| // Add to cart function | |
| function addToCart(productId) { | |
| cart.push(products[productId]); | |
| updateCart(); | |
| openCart(); | |
| } | |
| // Update cart display | |
| function updateCart() { | |
| const cartItemsEl = document.getElementById('cartItems'); | |
| const cartTotalEl = document.getElementById('cartTotal'); | |
| const checkoutItemsEl = document.getElementById('checkoutItems'); | |
| const checkoutTotalEl = document.getElementById('checkoutTotal'); | |
| // Clear existing items | |
| cartItemsEl.innerHTML = ''; | |
| // Add each item to cart display | |
| cart.forEach(item => { | |
| const itemEl = document.createElement('div'); | |
| itemEl.className = 'flex justify-between py-2 border-b border-gray-700'; | |
| itemEl.innerHTML = ` | |
| <div class="flex items-center gap-4"> | |
| <img src="${item.image}" alt="${item.name}" class="w-12 h-12 rounded-md object-cover"> | |
| <div> | |
| <h3 class="font-bold">${item.name}</h3> | |
| <p class="text-sm text-gray-400">${item.duration}</p> | |
| </div> | |
| </div> | |
| <div class="font-bold">₱${item.price}</div> | |
| `; | |
| cartItemsEl.appendChild(itemEl); | |
| }); | |
| // Calculate total | |
| const total = cart.reduce((sum, item) => sum + item.price, 0); | |
| cartTotalEl.textContent = `₱${total}`; | |
| // Update checkout summary | |
| checkoutItemsEl.textContent = `${cart.length} item${cart.length !== 1 ? 's' : ''}`; | |
| checkoutTotalEl.textContent = `₱${total}`; | |
| } | |
| // Cart modal functions | |
| function openCart() { | |
| document.getElementById('cartModal').classList.remove('hidden'); | |
| } | |
| function closeCart() { | |
| document.getElementById('cartModal').classList.add('hidden'); | |
| } | |
| // Checkout functions | |
| function proceedToCheckout() { | |
| closeCart(); | |
| document.getElementById('checkoutModal').classList.remove('hidden'); | |
| } | |
| function closeCheckout() { | |
| document.getElementById('checkoutModal').classList.add('hidden'); | |
| } | |
| // Payment functions | |
| function proceedToPayment() { | |
| const email = document.getElementById('email').value; | |
| if (!email) { | |
| alert('Please enter your email address'); | |
| return; | |
| } | |
| closeCheckout(); | |
| // Set payment details | |
| const total = cart.reduce((sum, item) => sum + item.price, 0); | |
| document.getElementById('paymentAmount').textContent = `₱${total}`; | |
| document.getElementById('paymentEmail').textContent = email; | |
| document.getElementById('paymentModal').classList.remove('hidden'); | |
| } | |
| function closePayment() { | |
| document.getElementById('paymentModal').classList.add('hidden'); | |
| } | |
| function completePayment() { | |
| closePayment(); | |
| document.getElementById('successModal').classList.remove('hidden'); | |
| // In a real app, you would send the order to your backend here | |
| console.log('Order completed:', { | |
| email: document.getElementById('email').value, | |
| items: cart, | |
| total: cart.reduce((sum, item) => sum + item.price, 0) | |
| }); | |
| // Reset cart | |
| cart = []; | |
| updateCart(); | |
| } | |
| function closeSuccess() { | |
| document.getElementById('successModal').classList.add('hidden'); | |
| } | |
| // Initialize | |
| document.addEventListener('DOMContentLoaded', () => { | |
| updateCart(); | |
| }); |