${product.name}
Priced per ${product.unit}.
const CART_KEY = 'mmb_cart';
function getCart() {
try {
return JSON.parse(localStorage.getItem(CART_KEY)) || [];
} catch {
return [];
}
}
function saveCart(cart) {
localStorage.setItem(CART_KEY, JSON.stringify(cart));
updateCartCount();
}
function updateCartCount() {
const count = getCart().reduce((sum, item) => sum + item.quantity, 0);
const node = document.getElementById('cart-count');
if (node) node.textContent = count;
}
function addToCart(productId, quantity) {
const qty = Number(quantity || 1);
if (qty <= 0) return;
const product = window.PRODUCTS.find(p => p.id === productId);
if (!product) return;
const cart = getCart();
const existing = cart.find(item => item.id === productId);
if (existing) existing.quantity += qty;
else cart.push({ id: product.id, name: product.name, price: product.price, quantity: qty });
saveCart(cart);
alert(`${product.name} added to cart.`);
}
function clearCart() {
localStorage.removeItem(CART_KEY);
updateCartCount();
renderCheckout();
}
function formatMoney(value) {
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(value);
}
function calculateTotals(cart) {
const subtotal = cart.reduce((sum, item) => sum + (item.price * item.quantity), 0);
const discount = subtotal >= 100 ? subtotal * 0.10 : 0;
return { subtotal, discount, total: subtotal - discount };
}
function productCard(product) {
return `
Priced per ${product.unit}.${product.name}
Your cart is empty.
'; } else { cartItems.innerHTML = cart.map(item => `Name: ${values.name}
Phone: ${values.phone}
Email: ${values.email}
Pickup date: ${values.pickupDate}
Method: ${values.fulfillment}
Location: ${values.location || 'Not provided'}
Notes: ${values.notes || 'None'}
Items
${orderLines}
Total: ${formatMoney(totals.total)}
Next step: connect this form to Square, GoDaddy Commerce, Formspree, or your email to accept live submissions and payments.
`; result.classList.remove('hidden'); result.innerHTML = message; result.scrollIntoView({ behavior: 'smooth' }); }); const clearButton = document.getElementById('clear-cart'); if (clearButton) clearButton.addEventListener('click', clearCart); } document.addEventListener('DOMContentLoaded', () => { updateCartCount(); renderProducts(); renderCheckout(); initCheckoutForm(); });