File size: 9,670 Bytes
b20c67f | 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 | // Product Data
const products = {
vegPickles: [
{
id: 1,
name: "Avakaya (Mango Pickle)",
description: "The king of pickles; raw mango pieces with mustard and chili.",
price: 299,
originalPrice: 349,
image: "http://static.photos/food/640x360/5",
weightOptions: ["250g", "500g", "1kg"],
spiceLevel: 3,
shelfLife: "6 months",
ingredients: "Raw mango, mustard seeds, red chili powder, fenugreek, turmeric, salt, oil",
rating: 4.8,
isBestseller: true
},
{
id: 2,
name: "Bellam Avakaya",
description: "Sweet and spicy mango pickle made with Jaggery.",
price: 329,
originalPrice: 379,
image: "http://static.photos/food/640x360/6",
weightOptions: ["250g", "500g"],
spiceLevel: 2,
shelfLife: "6 months",
ingredients: "Raw mango, jaggery, mustard seeds, red chili powder, fenugreek, turmeric, salt, oil",
rating: 4.7,
isSpecial: true
},
// Add more veg pickles...
],
nonVegPickles: [
{
id: 101,
name: "Chicken Boneless Pickle",
description: "Tender chunks marinated in ginger-garlic and garam masala.",
price: 449,
originalPrice: 499,
image: "http://static.photos/food/640x360/7",
weightOptions: ["250g", "500g"],
spiceLevel: 3,
shelfLife: "3 months",
ingredients: "Chicken, ginger, garlic, garam masala, red chili powder, turmeric, salt, oil",
rating: 4.9,
isBestseller: true
},
// Add more non-veg pickles...
],
vadiyalu: [
{
id: 201,
name: "Gummadi Vadiyalu",
description: "Ash gourd (pumpkin) chunks mixed with urad dal batter.",
price: 199,
originalPrice: 249,
image: "http://static.photos/food/640x360/8",
weightOptions: ["250g", "500g", "1kg"],
spiceLevel: 1,
shelfLife: "12 months",
ingredients: "Ash gourd, urad dal, green chilies, salt",
rating: 4.5
},
// Add more vadiyalu...
],
masalas: [
{
id: 301,
name: "Biryani Masala",
description: "Hyderabadi-style aromatic blend.",
price: 149,
originalPrice: 179,
image: "http://static.photos/food/640x360/9",
weightOptions: ["100g", "250g"],
spiceLevel: 2,
shelfLife: "12 months",
ingredients: "Cinnamon, cardamom, cloves, bay leaves, star anise, mace, nutmeg, pepper",
rating: 4.7,
isNew: true
},
// Add more masalas...
]
};
// Cart System
let cart = JSON.parse(localStorage.getItem('cart')) || [];
let isLoggedIn = localStorage.getItem('isLoggedIn') === 'true';
// DOM Elements
const productGrids = {
veg: document.querySelector('#veg-pickles .product-grid'),
nonVeg: document.querySelector('#nonveg-pickles .product-grid'),
vadiyalu: document.querySelector('#vadiyalu .product-grid'),
masalas: document.querySelector('#masalas .product-grid')
};
// Initialize the app
document.addEventListener('DOMContentLoaded', () => {
renderProducts();
setupEventListeners();
// Check if user is logged in
if (isLoggedIn) {
updateUserUI();
}
});
// Render all products
function renderProducts() {
renderProductCategory('veg', products.vegPickles);
renderProductCategory('nonVeg', products.nonVegPickles);
renderProductCategory('vadiyalu', products.vadiyalu);
renderProductCategory('masalas', products.masalas);
}
// Render products for a specific category
function renderProductCategory(category, products) {
const grid = productGrids[category];
grid.innerHTML = '';
products.forEach(product => {
const productCard = document.createElement('div');
productCard.className = 'product-card';
productCard.innerHTML = `
<img src="${product.image}" alt="${product.name}" class="product-image">
${product.isBestseller ? '<span class="product-badge">Bestseller</span>' : ''}
${product.isNew ? '<span class="product-badge" style="background-color: var(--secondary);">New</span>' : ''}
${product.isSpecial ? '<span class="product-badge" style="background-color: #8b5cf6;">Special</span>' : ''}
<div class="product-info">
<h3 class="product-title">${product.name}</h3>
<div class="product-rating">
${renderRatingStars(product.rating)}
<span class="product-spice">${renderSpiceLevel(product.spiceLevel)}</span>
</div>
<div class="product-price">
₹${product.price}
${product.originalPrice ? `<span class="product-original-price">₹${product.originalPrice}</span>` : ''}
</div>
<p class="text-sm text-gray-600 mb-2">Shelf Life: ${product.shelfLife}</p>
<div class="product-actions">
<button class="btn btn-primary btn-add-to-cart" data-id="${product.id}">
<i class="fas fa-shopping-cart mr-2"></i>Add to Cart
</button>
<button class="btn btn-outline btn-icon btn-wishlist" data-id="${product.id}">
<i class="far fa-heart"></i>
</button>
</div>
</div>
`;
grid.appendChild(productCard);
});
}
// Render rating stars
function renderRatingStars(rating) {
let stars = '';
const fullStars = Math.floor(rating);
const hasHalfStar = rating % 1 >= 0.5;
for (let i = 0; i < 5; i++) {
if (i < fullStars) {
stars += '<i class="fas fa-star text-yellow-400"></i>';
} else if (i === fullStars && hasHalfStar) {
stars += '<i class="fas fa-star-half-alt text-yellow-400"></i>';
} else {
stars += '<i class="far fa-star text-yellow-400"></i>';
}
}
return stars;
}
// Render spice level indicator
function renderSpiceLevel(level) {
let spice = '';
for (let i = 0; i < level; i++) {
spice += '🌶️';
}
return spice;
}
// Setup event listeners
function setupEventListeners() {
// Add to cart buttons
document.querySelectorAll('.btn-add-to-cart').forEach(button => {
button.addEventListener('click', (e) => {
if (!isLoggedIn) {
document.querySelector('custom-login-modal').openModal();
return;
}
const productId = parseInt(e.target.closest('button').dataset.id);
addToCart(productId);
showToast('Product added to cart!');
});
});
// Wishlist buttons
document.querySelectorAll('.btn-wishlist').forEach(button => {
button.addEventListener('click', (e) => {
if (!isLoggedIn) {
document.querySelector('custom-login-modal').openModal();
return;
}
const productId = parseInt(e.target.closest('button').dataset.id);
toggleWishlist(productId);
});
});
// User login event
document.addEventListener('userLoggedIn', () => {
isLoggedIn = true;
localStorage.setItem('isLoggedIn', 'true');
updateUserUI();
});
}
// Add product to cart
function addToCart(productId) {
// Find product in all categories
let product = null;
for (const category in products) {
product = products[category].find(p => p.id === productId);
if (product) break;
}
if (!product) return;
// Check if product already in cart
const existingItem = cart.find(item => item.id === productId);
if (existingItem) {
existingItem.quantity += 1;
} else {
cart.push({
...product,
quantity: 1,
selectedWeight: product.weightOptions[0]
});
}
localStorage.setItem('cart', JSON.stringify(cart));
updateCartCount();
}
// Toggle product in wishlist
function toggleWishlist(productId) {
// In a real app, this would be saved to backend
const button = document.querySelector(`.btn-wishlist[data-id="${productId}"]`);
const icon = button.querySelector('i');
if (icon.classList.contains('far')) {
icon.classList.remove('far');
icon.classList.add('fas');
showToast('Added to wishlist!');
} else {
icon.classList.remove('fas');
icon.classList.add('far');
showToast('Removed from wishlist!');
}
}
// Update cart count in navbar
function updateCartCount() {
const count = cart.reduce((total, item) => total + item.quantity, 0);
const event = new CustomEvent('cartUpdated', { detail: count });
document.dispatchEvent(event);
}
// Update UI when user logs in
function updateUserUI() {
const event = new CustomEvent('userStatusChanged', { detail: isLoggedIn });
document.dispatchEvent(event);
}
// Show toast notification
function showToast(message) {
const toast = document.getElementById('toast');
toast.textContent = message;
toast.classList.remove('hidden');
setTimeout(() => {
toast.classList.add('hidden');
}, 3000);
} |