The SansiStore favorites system lets buyers bookmark products they want to revisit later. A heart icon on every product card and on the product detail page toggles the item in or out of the favorites list. For guests, favorites are persisted inDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ProcesosAgilesUMSS/sansistore/llms.txt
Use this file to discover all available pages before exploring further.
localStorage; on sign-in, local favorites are automatically merged with any Firestore favorites and synced back to the cloud.
Favorites Page (/favoritos)
The /favoritos Astro page renders the same <FeaturedProducts> component used by the main catalog, but with favoritesOnly={true} and the title "Mis favoritos". This means the full catalog UI — category filter, search, sort, offers toggle, and pagination — is available inside the favorites view.
favoritesOnly is true, filterCatalogProducts() restricts the product list to IDs present in the favoriteIds set returned by useFavorites(). A buyer with no saved favorites sees an empty-state card with a link back to /productos.
The useFavorites Hook
useFavorites (src/features/favorites/hooks/useFavorites.ts) is the single source of truth for all favorites state. It is consumed by <ProductCard>, the product detail page’s <ProductInfoSection>, and <FeaturedProducts>.
Initialization and Sync
On mount,useFavorites subscribes to Firebase Auth state changes. When a user signs in:
- Local favorites are read from
localStorageviagetLocalFavorites(). - Remote favorites are fetched from
users/{uid}/favoriteItemsviagetFavoriteItems(). - The two lists are merged — remote items take precedence, deduplication is by
productId: - The merged list is written back to Firestore via
syncFavoritesToFirestore()and saved tolocalStorage.
Toggle Behavior
toggleFavorite(productId) is optimistic — it updates local state immediately, then synchronizes with Firestore. On error it rolls back to the previous state:
The <FavoriteButton> Component
<FavoriteButton> (src/features/favorites/components/FavoriteButton.tsx) renders the heart icon. It is used on product cards and on the product detail page. The button exposes data-testid="favorite-button-{slug}" for E2E testing:
aria-label reads either "Agregar {name} a favoritos" or "Quitar {name} de favoritos" depending on current state, and aria-pressed reflects the current favorite state ("true" / "false").
Firestore Data Model
Favorites for authenticated users are stored in theusers/{uid}/favoriteItems subcollection. Each document ID is the productId.
Firestore Operations
Guest vs. Authenticated Behavior
- Guest User
- Authenticated User
Favorites are stored in
localStorage under the key sansistore_favorites as a JSON array of FavoriteItem objects. All toggle operations are purely local. The /favoritos page works fully for guests.Unauthenticated users can browse favorites and add items to the cart from the
/favoritos page without restrictions. Sign-in is only required for cloud sync and cross-device persistence.Adding to Cart from Favorites
The favorites page uses the same<ProductCard> component as the main catalog, wrapped in a <CartProvider>. This means the add-to-cart button (rendered by <ProductCard>) is fully functional on /favoritos — buyers can add items directly to the cart without leaving the page.
From the <FeaturedProducts> perspective, favoritesOnly is purely a filter predicate; the cart integration, quantity controls, and checkout flow are identical to the main catalog.
End-to-End Tests
Favorites behavior is covered by Playwright tests intests/favorites/favorites.spec.ts: