feat: add Cart page and themed error pages
- Add ShopLive.Cart at /cart using shared PageTemplates - Update ErrorHTML to render fully themed 404/500 pages - Add dev-only error preview routes at /dev/errors/404 and /dev/errors/500 - Update error page tests for themed output Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
68
lib/simpleshop_theme_web/live/shop_live/cart.ex
Normal file
68
lib/simpleshop_theme_web/live/shop_live/cart.ex
Normal file
@@ -0,0 +1,68 @@
|
||||
defmodule SimpleshopThemeWeb.ShopLive.Cart do
|
||||
use SimpleshopThemeWeb, :live_view
|
||||
|
||||
alias SimpleshopTheme.Settings
|
||||
alias SimpleshopTheme.Media
|
||||
alias SimpleshopTheme.Theme.{CSSCache, CSSGenerator, PreviewData}
|
||||
|
||||
@impl true
|
||||
def mount(_params, _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()
|
||||
|
||||
# For now, use preview data for cart items
|
||||
# In a real implementation, this would come from session/database
|
||||
cart_page_items = PreviewData.cart_items()
|
||||
cart_page_subtotal = Enum.reduce(cart_page_items, 0, fn item, acc ->
|
||||
acc + item.product.price * item.quantity
|
||||
end)
|
||||
|
||||
socket =
|
||||
socket
|
||||
|> assign(:page_title, "Cart")
|
||||
|> assign(:theme_settings, theme_settings)
|
||||
|> assign(:generated_css, generated_css)
|
||||
|> assign(:logo_image, logo_image)
|
||||
|> assign(:header_image, header_image)
|
||||
|> assign(:cart_page_items, cart_page_items)
|
||||
|> assign(:cart_page_subtotal, cart_page_subtotal)
|
||||
|> assign(:mode, :shop)
|
||||
|> assign(:cart_items, PreviewData.cart_drawer_items())
|
||||
|> assign(:cart_count, length(cart_page_items))
|
||||
|> assign(:cart_subtotal, format_subtotal(cart_page_subtotal))
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<SimpleshopThemeWeb.PageTemplates.cart
|
||||
theme_settings={@theme_settings}
|
||||
logo_image={@logo_image}
|
||||
header_image={@header_image}
|
||||
cart_page_items={@cart_page_items}
|
||||
cart_page_subtotal={@cart_page_subtotal}
|
||||
mode={@mode}
|
||||
cart_items={@cart_items}
|
||||
cart_count={@cart_count}
|
||||
cart_subtotal={@cart_subtotal}
|
||||
/>
|
||||
"""
|
||||
end
|
||||
|
||||
defp format_subtotal(subtotal_pence) do
|
||||
"£#{Float.round(subtotal_pence / 100, 2)}"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user