Rahulrsk's picture
Create a website for e-commerce for Indian pickles like a 15+ types of Indian veg pickels and 7+ types non veg pickles 10+ types of Vadiyalu and pappads and 10+ types of masalas and Karappodulu and and product details and when some one try to buy or add favorite or craft they need to login the page using mobile number or google and admin can add or delete the products and easy to buy the product on my website and need location access to get address and and my company name is "rb pickel store " and menctio the logo also.
b20c67f verified
Raw History Blame Contribute Delete
9.67 kB
// 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);
}