Loading Wonderful Dragon Fruit...
Premium organic pitaya harvested from the heart of South Africa. Sustainable farming, vibrant flavor, delivered to your door.
Freshly picked and packed with care
Sweet, juicy, and bursting with antioxidants. Perfect for breakfast bowls.
In Stock
Milder flavor with crunchy black seeds. Ideal for smoothies.
In Stock
A generous assortment of red and white varieties. Great value.
Low Stock${product.desc}
Stock: ${product.stock > 0 ? product.stock : 'Out of Stock'}
Was: ${formatPrice(product.oldPrice)}
Now: ${formatPrice(product.price)}
`; productsGrid.appendChild(productCard); }); } function addToCart(id) { const cart = JSON.parse(localStorage.getItem('cart')) || {}; if (cart[id]) { cart[id].qty++; } else { const product = products.find(p => p.id === id); cart[id] = { product, qty: 1 }; } localStorage.setItem('cart', JSON.stringify(cart)); updateCartCount(); renderCart(); checkStock(id); } function removeFromCart(id) { const cart = JSON.parse(localStorage.getItem('cart')) || {}; delete cart[id]; localStorage.setItem('cart', JSON.stringify(cart)); updateCartCount(); renderCart(); } function updateQty(id, delta) { const cart = JSON.parse(localStorage.getItem('cart')) || {}; if (cart[id]) { cart[id].qty += delta; if (cart[id].qty <= 0) { delete cart[id]; } } localStorage.setItem('cart', JSON.stringify(cart)); updateCartCount(); renderCart(); } function renderCart() { const cartItems = document.getElementById('cart-items'); cartItems.innerHTML = ''; const cart = JSON.parse(localStorage.getItem('cart')) || {}; Object.keys(cart).forEach(id => { const item = cart[id]; const cartItem = document.createElement('div'); cartItem.classList.add('cart-item'); cartItem.innerHTML = `Price: ${formatPrice(item.product.price)}
Qty: ${item.qty}
`; cartItems.appendChild(cartItem); }); const cartTotal = document.getElementById('cart-total'); const total = Object.keys(cart).reduce((acc, id) => { return acc + cart[id].product.price * cart[id].qty; }, 0); cartTotal.textContent = `Total: ${formatPrice(total)}`; } function toggleCart() { const cartOverlay = document.querySelector('.cart-overlay'); cartOverlay.classList.toggle('open'); } function whatsappCheckout() { const cart = JSON.parse(localStorage.getItem('cart')) || {}; const message = Object.keys(cart).map(id => { return `${cart[id].product.name} x${cart[id].qty}`; }).join('\n'); const total = Object.keys(cart).reduce((acc, id) => { return acc + cart[id].product.price * cart[id].qty; }, 0); message += `\nTotal: ${formatPrice(total)}`; window.open(`https://wa.me/27834474639?text=${encodeURIComponent(message)}`); } function checkStock(id) { const product = products.find(p => p.id === id); if (product.stock <= 3) { document.querySelector(`[data-id="${id}"]`).parentElement.querySelector('.stock').textContent = `Low Stock (${product.stock})`; } else if (product.stock === 0) { document.querySelector(`[data-id="${id}"]`).parentElement.querySelector('.stock').textContent = 'Out of Stock'; document.querySelector(`[data-id="${id}"]`).disabled = true; } product.stock--; } function updateCartCount() { const cartCount = document.getElementById('cart-count'); const cart = JSON.parse(localStorage.getItem('cart')) || {}; const count = Object.keys(cart).reduce((acc, id) => { return acc + cart[id].qty; }, 0); cartCount.textContent = count; } function heroCarousel() { const heroSlides = document.querySelectorAll('.hero-slide'); let currentSlide = 0; setInterval(() => { heroSlides[currentSlide].classList.remove('active'); currentSlide = (currentSlide + 1) % heroSlides.length; heroSlides[currentSlide].classList.add('active'); }, 5000); } function revealElements() { const revealElements = document.querySelectorAll('.reveal'); const observer = new IntersectionObserver((entries) => { entries.forEach((entry) => { if (entry.isIntersecting) { entry.target.classList.add('visible'); } }); }, { threshold: 0.5 }); revealElements.forEach((element) => { observer.observe(element); }); } function toggleMenu() { const hamburger = document.querySelector('.hamburger'); const navLinks = document.getElementById('nav-links'); hamburger.classList.toggle('active'); navLinks.classList.toggle('active'); } function showToast(msg) { const toast = document.getElementById('toast'); toast.textContent = msg; toast.classList.add('visible'); setTimeout(() => { toast.classList.remove('visible'); }, 2000); } document.addEventListener('DOMContentLoaded', () => { renderProducts(); heroCarousel(); revealElements(); updateCartCount(); renderCart(); }); document.addEventListener('scroll', () => { const nav = document.getElementById('nav'); if (window.scrollY > 0) { nav.classList.add('scrolled'); } else { nav.classList.remove('scrolled'); } }); document.addEventListener('click', (e) => { if (e.target.classList.contains('add-to-cart')) { addToCart(e.target.dataset.id); } else if (e.target.classList.contains('remove-from-cart')) { removeFromCart(e.target.dataset.id); } else if (e.target.classList.contains('qty-minus')) { updateQty(e.target.dataset.id, -1); } else if (e.target.classList.contains('qty-plus')) { updateQty(e.target.dataset.id, 1); } else if (e.target.id === 'checkout-btn') { whatsappCheckout(); } else if (e.target.classList.contains('hamburger')) { toggleMenu(); } });