From 19b4a5bd5947556122389c0e217983e2853720fb Mon Sep 17 00:00:00 2001 From: jamey Date: Mon, 9 Feb 2026 18:12:57 +0000 Subject: [PATCH] add variants to all mock products and fix CSSCache race condition All 16 mock products now have at least one variant so add-to-cart works in demo mode. CSSCache.invalidate/0 rescues ArgumentError when the ETS table doesn't exist yet (seed_defaults runs before CSSCache starts). Co-Authored-By: Claude Opus 4.6 --- lib/simpleshop_theme/theme/css_cache.ex | 2 + lib/simpleshop_theme/theme/preview_data.ex | 160 ++++++++++++++++-- .../live/shop_live/product_show_test.exs | 6 +- 3 files changed, 151 insertions(+), 17 deletions(-) diff --git a/lib/simpleshop_theme/theme/css_cache.ex b/lib/simpleshop_theme/theme/css_cache.ex index c863e32..781af1b 100644 --- a/lib/simpleshop_theme/theme/css_cache.ex +++ b/lib/simpleshop_theme/theme/css_cache.ex @@ -66,6 +66,8 @@ defmodule SimpleshopTheme.Theme.CSSCache do def invalidate do :ets.delete(@table_name, :site_theme) :ok + rescue + ArgumentError -> :ok end @doc """ diff --git a/lib/simpleshop_theme/theme/preview_data.ex b/lib/simpleshop_theme/theme/preview_data.ex index 8a2074e..d5e7322 100644 --- a/lib/simpleshop_theme/theme/preview_data.ex +++ b/lib/simpleshop_theme/theme/preview_data.ex @@ -556,7 +556,19 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Art Prints", in_stock: true, - on_sale: false + on_sale: false, + option_types: [ + %{name: "Size", type: :size, values: [%{id: 1, title: "12×18"}]} + ], + variants: [ + %{ + id: "p4", + title: "12×18", + price: 2400, + options: %{"Size" => "12×18"}, + is_available: true + } + ] }, %{ id: "3", @@ -570,7 +582,19 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Art Prints", in_stock: true, - on_sale: false + on_sale: false, + option_types: [ + %{name: "Size", type: :size, values: [%{id: 1, title: "12×18"}]} + ], + variants: [ + %{ + id: "p5", + title: "12×18", + price: 2400, + options: %{"Size" => "12×18"}, + is_available: true + } + ] }, %{ id: "4", @@ -584,7 +608,20 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Art Prints", in_stock: true, - on_sale: true + on_sale: true, + option_types: [ + %{name: "Size", type: :size, values: [%{id: 1, title: "12×18"}]} + ], + variants: [ + %{ + id: "p6", + title: "12×18", + price: 2800, + compare_at_price: 3200, + options: %{"Size" => "12×18"}, + is_available: true + } + ] }, %{ id: "5", @@ -598,7 +635,19 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Art Prints", in_stock: true, - on_sale: false + on_sale: false, + option_types: [ + %{name: "Size", type: :size, values: [%{id: 1, title: "12×18"}]} + ], + variants: [ + %{ + id: "p7", + title: "12×18", + price: 2400, + options: %{"Size" => "12×18"}, + is_available: true + } + ] }, # Apparel %{ @@ -796,7 +845,40 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Apparel", in_stock: true, - on_sale: true + on_sale: true, + option_types: [ + %{ + name: "Size", + type: :size, + values: [%{id: 1, title: "M"}, %{id: 2, title: "L"}, %{id: 3, title: "XL"}] + } + ], + variants: [ + %{ + id: "h1", + title: "M", + price: 4499, + compare_at_price: 4999, + options: %{"Size" => "M"}, + is_available: true + }, + %{ + id: "h2", + title: "L", + price: 4499, + compare_at_price: 4999, + options: %{"Size" => "L"}, + is_available: true + }, + %{ + id: "h3", + title: "XL", + price: 4499, + compare_at_price: 4999, + options: %{"Size" => "XL"}, + is_available: true + } + ] }, %{ id: "8", @@ -810,7 +892,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Apparel", in_stock: true, - on_sale: false + on_sale: false, + variants: [ + %{id: "tb1", title: "One size", price: 1999, options: %{}, is_available: true} + ] }, %{ id: "9", @@ -824,7 +909,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Apparel", in_stock: true, - on_sale: false + on_sale: false, + variants: [ + %{id: "tb2", title: "One size", price: 1999, options: %{}, is_available: true} + ] }, # Homewares %{ @@ -839,7 +927,26 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Homewares", in_stock: true, - on_sale: false + on_sale: false, + option_types: [ + %{name: "Size", type: :size, values: [%{id: 1, title: "11oz"}, %{id: 2, title: "15oz"}]} + ], + variants: [ + %{ + id: "m1", + title: "11oz", + price: 1499, + options: %{"Size" => "11oz"}, + is_available: true + }, + %{ + id: "m2", + title: "15oz", + price: 1699, + options: %{"Size" => "15oz"}, + is_available: true + } + ] }, %{ id: "11", @@ -853,7 +960,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Homewares", in_stock: true, - on_sale: false + on_sale: false, + variants: [ + %{id: "cu1", title: "18×18", price: 2999, options: %{}, is_available: true} + ] }, %{ id: "12", @@ -867,7 +977,17 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Homewares", in_stock: true, - on_sale: true + on_sale: true, + variants: [ + %{ + id: "bl1", + title: "50×60", + price: 5999, + compare_at_price: 6999, + options: %{}, + is_available: true + } + ] }, # Stationery %{ @@ -882,7 +1002,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Stationery", in_stock: true, - on_sale: false + on_sale: false, + variants: [ + %{id: "nb1", title: "Journal", price: 1999, options: %{}, is_available: true} + ] }, %{ id: "14", @@ -896,7 +1019,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Stationery", in_stock: true, - on_sale: false + on_sale: false, + variants: [ + %{id: "nb2", title: "Journal", price: 1999, options: %{}, is_available: true} + ] }, # Accessories %{ @@ -911,7 +1037,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Accessories", in_stock: true, - on_sale: false + on_sale: false, + variants: [ + %{id: "pc1", title: "iPhone 15", price: 2499, options: %{}, is_available: true} + ] }, %{ id: "16", @@ -925,7 +1054,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do hover_source_width: @mockup_source_width, category: "Accessories", in_stock: true, - on_sale: false + on_sale: false, + variants: [ + %{id: "ls1", title: "13 inch", price: 3499, options: %{}, is_available: true} + ] } ] end diff --git a/test/simpleshop_theme_web/live/shop_live/product_show_test.exs b/test/simpleshop_theme_web/live/shop_live/product_show_test.exs index dd2d4a2..5a87fec 100644 --- a/test/simpleshop_theme_web/live/shop_live/product_show_test.exs +++ b/test/simpleshop_theme_web/live/shop_live/product_show_test.exs @@ -103,11 +103,11 @@ defmodule SimpleshopThemeWeb.ShopLive.ProductShowTest do assert html =~ "disabled" end - test "shows 'One size' for products without options", %{conn: conn} do - # Product "2" (Ocean Waves Art Print) has no option_types + test "shows single variant for products with one option", %{conn: conn} do + # Product "2" (Ocean Waves Art Print) has a single size variant {:ok, _view, html} = live(conn, ~p"/products/2") - assert html =~ "One size" + assert html =~ "12×18" end end