Build the Salar Store storefront and connect products, blogs, and home specials to the Meshkee API.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Alireza Hassani
2026-08-16 01:36:29 +03:30
co-authored by Cursor
parent 2783305f07
commit 7d26eaa838
113 changed files with 3269 additions and 96 deletions
+39
View File
@@ -0,0 +1,39 @@
export type CartItem = {
productId: string;
variantId?: string;
slug: string;
name: string;
image: string;
price: number;
qty: number;
};
const KEY = "salar-cart";
export function getCart(): CartItem[] {
if (typeof window === "undefined") return [];
try {
const raw = window.localStorage.getItem(KEY);
return raw ? (JSON.parse(raw) as CartItem[]) : [];
} catch {
return [];
}
}
export function cartCount() {
return getCart().reduce((sum, item) => sum + item.qty, 0);
}
export function addToCart(item: CartItem) {
const cart = getCart();
const index = cart.findIndex(
(entry) => entry.productId === item.productId && entry.variantId === item.variantId,
);
if (index >= 0) {
cart[index] = { ...cart[index], qty: cart[index].qty + item.qty };
} else {
cart.push(item);
}
window.localStorage.setItem(KEY, JSON.stringify(cart));
window.dispatchEvent(new Event("cart-updated"));
}