add denormalized product fields and use Product structs throughout

Adds cheapest_price, compare_at_price, in_stock, on_sale columns to
products table (recomputed from variants after each sync). Shop
components now work with Product structs directly instead of plain
maps from PreviewData. Renames .name to .title, adds Product display
helpers (primary_image, hover_image, option_types) and ProductImage
helpers (display_url, direct_url, source_width). Adds Products context
query functions for storefront use (list_visible_products,
get_visible_product, list_categories with DB-level sort/filter).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-13 01:26:39 +00:00
parent 0b4fe031b7
commit 35e0386abb
20 changed files with 1000 additions and 328 deletions

View File

@@ -0,0 +1,12 @@
defmodule SimpleshopTheme.Repo.Migrations.AddCachedProductFields do
use Ecto.Migration
def change do
alter table(:products) do
add :cheapest_price, :integer, null: false, default: 0
add :compare_at_price, :integer
add :in_stock, :boolean, null: false, default: true
add :on_sale, :boolean, null: false, default: false
end
end
end