diff --git a/lib/simpleshop_theme_web/live/shop_live/product_show.ex b/lib/simpleshop_theme_web/live/shop_live/product_show.ex new file mode 100644 index 0000000..4046279 --- /dev/null +++ b/lib/simpleshop_theme_web/live/shop_live/product_show.ex @@ -0,0 +1,58 @@ +defmodule SimpleshopThemeWeb.ShopLive.ProductShow do + use SimpleshopThemeWeb, :live_view + + alias SimpleshopTheme.Settings + alias SimpleshopTheme.Media + alias SimpleshopTheme.Theme.{CSSCache, CSSGenerator, PreviewData} + + @impl true + def mount(%{"id" => id}, _session, socket) do + theme_settings = Settings.get_theme_settings() + + generated_css = + case CSSCache.get() do + {:ok, css} -> css + :miss -> + css = CSSGenerator.generate(theme_settings) + CSSCache.put(css) + css + end + + logo_image = Media.get_logo() + header_image = Media.get_header() + + 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) + + # Get related products (exclude current product, take 4) + related_products = + products + |> 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 + ] + + socket = + socket + |> assign(:page_title, product.name) + |> assign(:theme_settings, theme_settings) + |> assign(:generated_css, generated_css) + |> assign(:logo_image, logo_image) + |> assign(:header_image, header_image) + |> assign(:product, product) + |> assign(:gallery_images, gallery_images) + |> assign(:related_products, related_products) + |> assign(:quantity, 1) + + {:ok, socket} + end +end diff --git a/lib/simpleshop_theme_web/live/shop_live/product_show.html.heex b/lib/simpleshop_theme_web/live/shop_live/product_show.html.heex new file mode 100644 index 0000000..5b78c58 --- /dev/null +++ b/lib/simpleshop_theme_web/live/shop_live/product_show.html.heex @@ -0,0 +1,44 @@ +