feat: wire shop LiveViews to real product data

PreviewData now queries the Products context when real products exist,
falling back to mock data otherwise. Shop pages automatically display
synced Printify products.

Fixes:
- Printify image position was string ("front"), now uses index
- Category extraction improved to match more Printify tags
- ProductShow finds products by slug for real data

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-01-31 23:07:37 +00:00
parent 81520754ee
commit c818d0399c
4 changed files with 118 additions and 32 deletions

View File

@@ -25,23 +25,24 @@ defmodule SimpleshopThemeWeb.ShopLive.ProductShow do
products = PreviewData.products()
# Find product by ID (preview data uses integer IDs)
product_id = String.to_integer(id)
product = Enum.find(products, List.first(products), fn p -> p.id == product_id end)
# Find product by slug or ID (real products use slugs, mock data uses string IDs)
product = find_product(products, id)
# Get related products (exclude current product, take 4)
related_products =
products
|> Enum.reject(fn p -> p.id == product_id end)
|> Enum.reject(fn p -> p.id == product.id end)
|> Enum.take(4)
# Build gallery images
gallery_images = [
product.image_url,
product.hover_image_url,
product.image_url,
product.hover_image_url
]
# Build gallery images (filter out nils)
gallery_images =
[
product.image_url,
product.hover_image_url,
product.image_url,
product.hover_image_url
]
|> Enum.reject(&is_nil/1)
socket =
socket
@@ -62,6 +63,13 @@ defmodule SimpleshopThemeWeb.ShopLive.ProductShow do
{:ok, socket}
end
# Find product by slug first (real products), then try ID match (mock data)
defp find_product(products, id) do
Enum.find(products, fn p -> p[:slug] == id end) ||
Enum.find(products, fn p -> p.id == id end) ||
List.first(products)
end
@impl true
def render(assigns) do
~H"""