Skip to main content
// Sample product data (you can replace this with your actual product data) const products = [ { id: 1, name: 'Product 1', price: 19.99, image: 'https://via.placeholder.com/150' }, { id: 2, name: 'Product 2', price: 29.99, image: 'https://via.placeholder.com/150' }, { id: 3, name: 'Product 3', price: 39.99, image: 'https://via.placeholder.com/150' }, // Add more products as needed ]; let cart = []; // Function to render product list function renderProducts() { const productList = document.querySelector('.product-list'); productList.innerHTML = ''; products.forEach(product => { const productElement = document.createElement('div'); productElement.classList.add('product-item'); productElement.innerHTML = ` ${product.name}

${product.name}

$${product.price.toFixed(2)}

`; productList.appendChild(productElement); }); } // Function to add item to cart function addToCart(productId) { const product = products.find(p => p.id === productId); if (product) { cart.push(product); updateCartCount(); } } // Function to update cart count function updateCartCount() { const cartCount = document.getElementById('cart-count'); cartCount.textContent = cart.length; } // Function to render cart items function renderCart() { const cartItems = document.getElementById('cart-items'); const cartTotal = document.getElementById('cart-total'); cartItems.innerHTML = ''; let total = 0; cart.forEach(item => { const itemElement = document.createElement('div'); itemElement.innerHTML = `

${item.name} - $${item.price.toFixed(2)}

`; cartItems.appendChild(itemElement); total += item.price; }); cartTotal.textContent = total.toFixed(2); } // Event listeners document.addEventListener('DOMContentLoaded', () => { renderProducts(); const cartIcon = document.querySelector('.cart-icon'); const modal = document.getElementById('cart-modal'); const closeModal = document.getElementById('close-modal'); const checkoutBtn = document.getElementById('checkout-btn'); cartIcon.addEventListener('click', () => { renderCart(); modal.style.display = 'block'; }); closeModal.addEventListener('click', () => { modal.style.display = 'none'; }); checkoutBtn.addEventListener('click', () => { alert('Checkout functionality not implemented in this example.'); }); window.addEventListener('click', (event) => { if (event.target === modal) { modal.style.display = 'none'; } }); });

Comments

Popular posts from this blog

Mtshop

 Here’s a sample Privacy Policy for an application named "MyShop." This document provides a foundation and can be customized to align with your application's specific practices, legal requirements, and jurisdiction. Privacy Policy for MyShop Effective Date : [Insert Date] Last Updated : [Insert Date] MyShop ("we," "our," or "us") values your privacy and is committed to protecting your personal data. This Privacy Policy explains how we collect, use, disclose, and safeguard your information when you use our application, "MyShop" (the "App"). Please read this policy carefully. If you do not agree with the terms, please do not use the App. 1. Information We Collect a. Information You Provide to Us Account Information : Name, email address, phone number, and password. Payment Information : Billing address, payment method, and transaction details. Profile Information : Profile picture, preferences, and any addi...