Collections
Collections allow you to organize products into categories that customers can browse on your storefront.
Features
- Multiple Collections: Create unlimited collections to organize your products
- Product Assignment: Products can belong to multiple collections
- Collection Images: Add hero images to make collections visually appealing
- Ordering: Drag and drop to reorder collections and products within them
- Active/Inactive: Toggle collections on/off without deleting them
Creating Collections
- Go to Admin > Collections in your store dashboard
- Click New Collection
- Enter a name and optional description
- Upload a collection image (recommended: 4:3 aspect ratio)
- Click Create
Adding Products to Collections
- Open a collection from the Collections page
- Click Add Products
- Select products from the dropdown
- Products appear immediately in the collection
Customer View
Customers can browse collections at /collections on your storefront. Each collection shows:
- Collection name and image
- Product count
- Products within that collection
Troubleshooting: Collections Not Displaying
If collections appear in the admin but not on the customer-facing storefront, this is typically caused by Row Level Security (RLS) policies in Supabase.
Root Cause
The admin API uses a service role key which bypasses RLS, while the customer-facing API uses the anon key which is subject to RLS policies.
Required RLS Policies
Run the following SQL in your Supabase SQL Editor to fix:
-- Enable RLS on tables
ALTER TABLE public.collections ENABLE ROW LEVEL SECURITY;
ALTER TABLE public.product_collections ENABLE ROW LEVEL SECURITY;
-- Drop existing policies for clean re-creation
DROP POLICY IF EXISTS "Collections are viewable by everyone" ON public.collections;
DROP POLICY IF EXISTS "Product collections are viewable by everyone" ON public.product_collections;
-- Allow anyone to view active collections
CREATE POLICY "Collections are viewable by everyone"
ON public.collections FOR SELECT
TO anon, authenticated
USING (is_active = true);
-- Allow anyone to view product-collection links
CREATE POLICY "Product collections are viewable by everyone"
ON public.product_collections FOR SELECT
TO anon, authenticated
USING (true);
-- Grant SELECT permissions
GRANT SELECT ON public.collections TO anon, authenticated;
GRANT SELECT ON public.product_collections TO anon, authenticated;
PostgREST Schema Cache
After applying RLS policies, Supabase's PostgREST layer may cache the old schema. If collections still don't appear:
- Wait 2-3 minutes for cache expiration
- Or go to Project Settings > API and look for "Reload schema cache"
- Hard refresh your storefront page (Ctrl+Shift+R)
Verifying the Fix
Test the API directly in your browser:
https://your-store.gosovereign.io/api/collections
You should see a JSON response with your collections:
{
"collections": [
{
"id": "...",
"name": "Summer Collection",
"slug": "summer-collection",
"product_count": 5
}
]
}
Debug Endpoints
For advanced troubleshooting, use these debug endpoints:
?debug=1- Shows environment configuration (storeId, Supabase connection)?debug=2- Shows raw database query results
Common Issues
| Symptom | Cause | Fix |
|---------|-------|-----|
| Admin shows collections, storefront empty | RLS blocking anon access | Apply RLS policies above |
| API returns empty array, no error | PostgREST cache | Wait or reload schema |
| API returns 500 error | Missing env vars | Check Vercel deployment settings |
| Products in collection not showing | Product status filter | Ensure products have status: "active" |
Technical Details
The collections feature uses two tables:
collections- Stores collection metadata (name, slug, image, is_active)product_collections- Junction table linking products to collections (many-to-many)
The customer API at /api/collections queries both tables. The query avoids JOINs to prevent RLS cache issues and instead fetches product counts separately.
Key files:
/app/api/collections/route.ts- List all collections/app/api/collections/[slug]/route.ts- Get collection with products/app/collections/page.tsx- Customer collections page/app/collections/[slug]/page.tsx- Single collection view