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 <noreply@anthropic.com>
This commit is contained in:
jamey 2026-02-09 18:12:57 +00:00
parent 90b0242a06
commit 19b4a5bd59
3 changed files with 151 additions and 17 deletions

View File

@ -66,6 +66,8 @@ defmodule SimpleshopTheme.Theme.CSSCache do
def invalidate do def invalidate do
:ets.delete(@table_name, :site_theme) :ets.delete(@table_name, :site_theme)
:ok :ok
rescue
ArgumentError -> :ok
end end
@doc """ @doc """

View File

@ -556,7 +556,19 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Art Prints", category: "Art Prints",
in_stock: true, 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", id: "3",
@ -570,7 +582,19 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Art Prints", category: "Art Prints",
in_stock: true, 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", id: "4",
@ -584,7 +608,20 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Art Prints", category: "Art Prints",
in_stock: true, 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", id: "5",
@ -598,7 +635,19 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Art Prints", category: "Art Prints",
in_stock: true, 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 # Apparel
%{ %{
@ -796,7 +845,40 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Apparel", category: "Apparel",
in_stock: true, 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", id: "8",
@ -810,7 +892,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Apparel", category: "Apparel",
in_stock: true, in_stock: true,
on_sale: false on_sale: false,
variants: [
%{id: "tb1", title: "One size", price: 1999, options: %{}, is_available: true}
]
}, },
%{ %{
id: "9", id: "9",
@ -824,7 +909,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Apparel", category: "Apparel",
in_stock: true, in_stock: true,
on_sale: false on_sale: false,
variants: [
%{id: "tb2", title: "One size", price: 1999, options: %{}, is_available: true}
]
}, },
# Homewares # Homewares
%{ %{
@ -839,7 +927,26 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Homewares", category: "Homewares",
in_stock: true, 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", id: "11",
@ -853,7 +960,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Homewares", category: "Homewares",
in_stock: true, in_stock: true,
on_sale: false on_sale: false,
variants: [
%{id: "cu1", title: "18×18", price: 2999, options: %{}, is_available: true}
]
}, },
%{ %{
id: "12", id: "12",
@ -867,7 +977,17 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Homewares", category: "Homewares",
in_stock: true, 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 # Stationery
%{ %{
@ -882,7 +1002,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Stationery", category: "Stationery",
in_stock: true, in_stock: true,
on_sale: false on_sale: false,
variants: [
%{id: "nb1", title: "Journal", price: 1999, options: %{}, is_available: true}
]
}, },
%{ %{
id: "14", id: "14",
@ -896,7 +1019,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Stationery", category: "Stationery",
in_stock: true, in_stock: true,
on_sale: false on_sale: false,
variants: [
%{id: "nb2", title: "Journal", price: 1999, options: %{}, is_available: true}
]
}, },
# Accessories # Accessories
%{ %{
@ -911,7 +1037,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Accessories", category: "Accessories",
in_stock: true, in_stock: true,
on_sale: false on_sale: false,
variants: [
%{id: "pc1", title: "iPhone 15", price: 2499, options: %{}, is_available: true}
]
}, },
%{ %{
id: "16", id: "16",
@ -925,7 +1054,10 @@ defmodule SimpleshopTheme.Theme.PreviewData do
hover_source_width: @mockup_source_width, hover_source_width: @mockup_source_width,
category: "Accessories", category: "Accessories",
in_stock: true, in_stock: true,
on_sale: false on_sale: false,
variants: [
%{id: "ls1", title: "13 inch", price: 3499, options: %{}, is_available: true}
]
} }
] ]
end end

View File

@ -103,11 +103,11 @@ defmodule SimpleshopThemeWeb.ShopLive.ProductShowTest do
assert html =~ "disabled" assert html =~ "disabled"
end end
test "shows 'One size' for products without options", %{conn: conn} do test "shows single variant for products with one option", %{conn: conn} do
# Product "2" (Ocean Waves Art Print) has no option_types # Product "2" (Ocean Waves Art Print) has a single size variant
{:ok, _view, html} = live(conn, ~p"/products/2") {:ok, _view, html} = live(conn, ~p"/products/2")
assert html =~ "One size" assert html =~ "12×18"
end end
end end