feat: add /collections/:slug routes with category filtering
- Add ShopLive.Collection LiveView for collection pages - Add products_by_category/1 and category_by_slug/1 to PreviewData - Support /collections/all for all products view - Remove /products route and ShopLive.Products (replaced by collections) - Update all links to use /collections/all instead of /products - Update category nav to link to /collections/:slug - Update PDP breadcrumb to link to specific collection URL structure now follows Shopify convention: - /collections/all - All products - /collections/art-prints - Art Prints collection - /collections/apparel - Apparel collection - etc. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -114,6 +114,34 @@ defmodule SimpleshopTheme.Theme.PreviewData do
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns a category by its slug.
|
||||
|
||||
Returns nil if not found.
|
||||
"""
|
||||
def category_by_slug(slug) do
|
||||
Enum.find(categories(), fn cat -> cat.slug == slug end)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns products filtered by category slug.
|
||||
|
||||
If slug is nil or "all", returns all products.
|
||||
"""
|
||||
def products_by_category(nil), do: products()
|
||||
def products_by_category("all"), do: products()
|
||||
|
||||
def products_by_category(slug) do
|
||||
case category_by_slug(slug) do
|
||||
nil ->
|
||||
[]
|
||||
|
||||
category ->
|
||||
products()
|
||||
|> Enum.filter(fn product -> product.category == category.name end)
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Checks if the shop has real products.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user