rename project from SimpleshopTheme to Berrypod

All modules, configs, paths, and references updated.
836 tests pass, zero warnings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-18 21:23:15 +00:00
parent c65e777832
commit 9528700862
300 changed files with 23932 additions and 1349 deletions

View File

@@ -0,0 +1,19 @@
defmodule BerrypodWeb.Shop.Cart do
use BerrypodWeb, :live_view
alias Berrypod.Cart
@impl true
def mount(_params, _session, socket) do
{:ok, assign(socket, page_title: "Cart")}
end
@impl true
def render(assigns) do
assigns = assign(assigns, :cart_page_subtotal, Cart.calculate_subtotal(assigns.cart_items))
~H"""
<BerrypodWeb.PageTemplates.cart {assigns} />
"""
end
end

View File

@@ -0,0 +1,46 @@
defmodule BerrypodWeb.Shop.CheckoutSuccess do
use BerrypodWeb, :live_view
alias Berrypod.Orders
@impl true
def mount(%{"session_id" => session_id}, _session, socket) do
order = Orders.get_order_by_stripe_session(session_id)
# Subscribe to order status updates (webhook may arrive after redirect)
if order && connected?(socket) do
Phoenix.PubSub.subscribe(Berrypod.PubSub, "order:#{order.id}:status")
end
# Clear the cart after successful checkout
socket =
if order && connected?(socket) do
BerrypodWeb.CartHook.broadcast_and_update(socket, [])
else
socket
end
socket =
socket
|> assign(:page_title, "Order confirmed")
|> assign(:order, order)
{:ok, socket}
end
def mount(_params, _session, socket) do
{:ok, redirect(socket, to: ~p"/")}
end
@impl true
def handle_info({:order_paid, order}, socket) do
{:noreply, assign(socket, :order, order)}
end
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.checkout_success {assigns} />
"""
end
end

View File

@@ -0,0 +1,184 @@
defmodule BerrypodWeb.Shop.Collection do
use BerrypodWeb, :live_view
alias Berrypod.Products
@sort_options [
{"featured", "Featured"},
{"newest", "Newest"},
{"price_asc", "Price: Low to High"},
{"price_desc", "Price: High to Low"},
{"name_asc", "Name: A-Z"},
{"name_desc", "Name: Z-A"}
]
@impl true
def mount(_params, _session, socket) do
socket =
socket
|> assign(:sort_options, @sort_options)
|> assign(:current_sort, "featured")
{:ok, socket}
end
@impl true
def handle_params(%{"slug" => slug} = params, _uri, socket) do
sort = params["sort"] || "featured"
case load_collection(slug, sort) do
{:ok, title, category, products} ->
{:noreply,
socket
|> assign(:page_title, title)
|> assign(:collection_title, title)
|> assign(:current_category, category)
|> assign(:current_sort, sort)
|> assign(:products, products)}
:not_found ->
{:noreply,
socket
|> put_flash(:error, "Collection not found")
|> push_navigate(to: ~p"/collections/all")}
end
end
defp load_collection("all", sort) do
{:ok, "All Products", nil, Products.list_visible_products(sort: sort)}
end
defp load_collection("sale", sort) do
{:ok, "Sale", :sale, Products.list_visible_products(on_sale: true, sort: sort)}
end
defp load_collection(slug, sort) do
case Enum.find(Products.list_categories(), &(&1.slug == slug)) do
nil ->
:not_found
category ->
products = Products.list_visible_products(category: category.name, sort: sort)
{:ok, category.name, category, products}
end
end
@impl true
def handle_event("sort_changed", %{"sort" => sort}, socket) do
slug =
case socket.assigns.current_category do
nil -> "all"
:sale -> "sale"
category -> category.slug
end
{:noreply, push_patch(socket, to: ~p"/collections/#{slug}?sort=#{sort}")}
end
defp collection_path(slug, "featured"), do: ~p"/collections/#{slug}"
defp collection_path(slug, sort), do: ~p"/collections/#{slug}?sort=#{sort}"
@impl true
def render(assigns) do
~H"""
<.shop_layout {layout_assigns(assigns)} active_page="collection">
<main id="main-content">
<.collection_header
title={@collection_title}
product_count={length(@products)}
/>
<div class="page-container collection-body">
<.collection_filter_bar
categories={@categories}
current_slug={
case @current_category do
:sale -> "sale"
nil -> nil
cat -> cat.slug
end
}
sort_options={@sort_options}
current_sort={@current_sort}
/>
<.product_grid theme_settings={@theme_settings}>
<%= for product <- @products do %>
<.product_card
product={product}
theme_settings={@theme_settings}
mode={@mode}
variant={:default}
show_category={@current_category in [nil, :sale]}
/>
<% end %>
</.product_grid>
<%= if @products == [] do %>
<div class="collection-empty">
<p>No products found in this collection.</p>
<.link navigate={~p"/collections/all"} class="collection-empty-link">
View all products
</.link>
</div>
<% end %>
</div>
</main>
</.shop_layout>
"""
end
defp collection_filter_bar(assigns) do
~H"""
<div class="filter-bar">
<nav
aria-label="Collection filters"
id="collection-filters"
phx-hook="CollectionFilters"
class="collection-filters"
>
<ul class="collection-filter-pills">
<li>
<.link
navigate={collection_path("all", @current_sort)}
aria-current={@current_slug == nil && "page"}
class={["collection-filter-pill", @current_slug == nil && "active"]}
>
All
</.link>
</li>
<li>
<.link
navigate={collection_path("sale", @current_sort)}
aria-current={@current_slug == "sale" && "page"}
class={["collection-filter-pill", @current_slug == "sale" && "active"]}
>
Sale
</.link>
</li>
<%= for category <- @categories do %>
<li>
<.link
navigate={collection_path(category.slug, @current_sort)}
aria-current={@current_slug == category.slug && "page"}
class={["collection-filter-pill", @current_slug == category.slug && "active"]}
>
{category.name}
</.link>
</li>
<% end %>
</ul>
</nav>
<form phx-change="sort_changed">
<.shop_select
name="sort"
options={@sort_options}
selected={@current_sort}
aria-label="Sort products"
/>
</form>
</div>
"""
end
end

View File

@@ -0,0 +1,22 @@
defmodule BerrypodWeb.Shop.ComingSoon do
use BerrypodWeb, :live_view
@impl true
def mount(_params, _session, socket) do
{:ok, assign(socket, :page_title, "Coming soon")}
end
@impl true
def render(assigns) do
~H"""
<main class="flex min-h-screen items-center justify-center px-6 text-center" role="main">
<div>
<h1 class="text-3xl font-bold tracking-tight sm:text-4xl">{@theme_settings.site_name}</h1>
<p class="mt-4 text-lg text-[var(--t-text-muted)]">
We're getting things ready. Check back soon.
</p>
</div>
</main>
"""
end
end

View File

@@ -0,0 +1,15 @@
defmodule BerrypodWeb.Shop.Contact do
use BerrypodWeb, :live_view
@impl true
def mount(_params, _session, socket) do
{:ok, assign(socket, :page_title, "Contact")}
end
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.contact {assigns} />
"""
end
end

View File

@@ -0,0 +1,66 @@
defmodule BerrypodWeb.Shop.Content do
use BerrypodWeb, :live_view
alias Berrypod.Theme.PreviewData
@impl true
def mount(_params, _session, socket) do
{:ok, socket}
end
@impl true
def handle_params(_params, _uri, socket) do
config = page_config(socket.assigns.live_action)
{:noreply, assign(socket, config)}
end
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.content {assigns} />
"""
end
defp page_config(:about) do
%{
page_title: "About",
active_page: "about",
hero_title: "About the studio",
hero_description: "Your story goes here this is sample content for the demo shop",
hero_background: :sunken,
image_src: "/mockups/night-sky-blanket-3",
image_alt: "Night sky blanket draped over a chair",
content_blocks: PreviewData.about_content()
}
end
defp page_config(:delivery) do
%{
page_title: "Delivery & returns",
active_page: "delivery",
hero_title: "Delivery & returns",
hero_description: "Everything you need to know about shipping and returns",
content_blocks: PreviewData.delivery_content()
}
end
defp page_config(:privacy) do
%{
page_title: "Privacy policy",
active_page: "privacy",
hero_title: "Privacy policy",
hero_description: "How we handle your personal information",
content_blocks: PreviewData.privacy_content()
}
end
defp page_config(:terms) do
%{
page_title: "Terms of service",
active_page: "terms",
hero_title: "Terms of service",
hero_description: "The legal bits",
content_blocks: PreviewData.terms_content()
}
end
end

View File

@@ -0,0 +1,24 @@
defmodule BerrypodWeb.Shop.Home do
use BerrypodWeb, :live_view
alias Berrypod.Products
@impl true
def mount(_params, _session, socket) do
products = Products.list_visible_products(limit: 8)
socket =
socket
|> assign(:page_title, "Home")
|> assign(:products, products)
{:ok, socket}
end
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.home {assigns} />
"""
end
end

View File

@@ -0,0 +1,199 @@
defmodule BerrypodWeb.Shop.ProductShow do
use BerrypodWeb, :live_view
alias Berrypod.Cart
alias Berrypod.Images.Optimizer
alias Berrypod.Products
alias Berrypod.Products.{Product, ProductImage}
@impl true
def mount(%{"id" => slug}, _session, socket) do
case Products.get_visible_product(slug) do
nil ->
{:ok, push_navigate(socket, to: ~p"/collections/all")}
product ->
related_products =
Products.list_visible_products(
category: product.category,
limit: 4,
exclude: product.id
)
all_images =
(product.images || [])
|> Enum.sort_by(& &1.position)
|> Enum.map(fn img ->
width =
case ProductImage.source_width(img) do
nil -> 1200
sw -> Enum.max(Optimizer.applicable_widths(sw))
end
%{url: ProductImage.url(img, width), color: img.color}
end)
|> Enum.reject(fn img -> is_nil(img.url) end)
option_types = Product.option_types(product)
variants = product.variants || []
{selected_options, selected_variant} = initialize_variant_selection(variants)
available_options = compute_available_options(option_types, variants, selected_options)
display_price = variant_price(selected_variant, product)
gallery_images = filter_gallery_images(all_images, selected_options["Color"])
socket =
socket
|> assign(:page_title, product.title)
|> assign(:product, product)
|> assign(:all_images, all_images)
|> assign(:gallery_images, gallery_images)
|> assign(:related_products, related_products)
|> assign(:quantity, 1)
|> assign(:option_types, option_types)
|> assign(:variants, variants)
|> assign(:selected_options, selected_options)
|> assign(:selected_variant, selected_variant)
|> assign(:available_options, available_options)
|> assign(:display_price, display_price)
{:ok, socket}
end
end
defp initialize_variant_selection([first | _] = _variants) do
{first.options, first}
end
defp initialize_variant_selection([]) do
{%{}, nil}
end
defp compute_available_options(option_types, variants, selected_options) do
Enum.reduce(option_types, %{}, fn opt_type, acc ->
other_options = Map.delete(selected_options, opt_type.name)
available_values =
variants
|> Enum.filter(fn v ->
v.is_available &&
Enum.all?(other_options, fn {k, selected_val} ->
v.options[k] == selected_val
end)
end)
|> Enum.map(fn v -> v.options[opt_type.name] end)
|> Enum.uniq()
Map.put(acc, opt_type.name, available_values)
end)
end
defp variant_price(%{price: price}, _product) when is_integer(price), do: price
defp variant_price(_, %{cheapest_price: price}), do: price
defp variant_price(_, _), do: 0
# If the current combo doesn't match any variant, auto-adjust other options
# to find a valid one. Keeps the just-changed option fixed, adjusts the rest.
defp resolve_valid_combo(variants, option_types, selected_options, changed_option) do
if Enum.any?(variants, fn v -> v.options == selected_options end) do
selected_options
else
matching =
Enum.filter(variants, fn v ->
v.is_available && v.options[changed_option] == selected_options[changed_option]
end)
case matching do
[first | _] ->
Enum.reduce(option_types, selected_options, fn opt_type, acc ->
if opt_type.name == changed_option do
acc
else
Map.put(acc, opt_type.name, first.options[opt_type.name])
end
end)
[] ->
selected_options
end
end
end
defp find_variant(variants, selected_options) do
Enum.find(variants, fn v -> v.options == selected_options end)
end
defp filter_gallery_images(all_images, selected_color) do
if selected_color do
color_images = Enum.filter(all_images, &(&1.color == selected_color))
if color_images == [], do: all_images, else: color_images
else
all_images
end
|> Enum.map(& &1.url)
end
@impl true
def handle_event("select_option", %{"option" => option_name, "selected" => value}, socket) do
variants = socket.assigns.variants
option_types = socket.assigns.option_types
selected_options = Map.put(socket.assigns.selected_options, option_name, value)
selected_options = resolve_valid_combo(variants, option_types, selected_options, option_name)
selected_variant = find_variant(variants, selected_options)
available_options =
compute_available_options(option_types, variants, selected_options)
gallery_images = filter_gallery_images(socket.assigns.all_images, selected_options["Color"])
socket =
socket
|> assign(:selected_options, selected_options)
|> assign(:selected_variant, selected_variant)
|> assign(:available_options, available_options)
|> assign(:display_price, variant_price(selected_variant, socket.assigns.product))
|> assign(:gallery_images, gallery_images)
{:noreply, socket}
end
@impl true
def handle_event("increment_quantity", _params, socket) do
quantity = min(socket.assigns.quantity + 1, 99)
{:noreply, assign(socket, :quantity, quantity)}
end
@impl true
def handle_event("decrement_quantity", _params, socket) do
quantity = max(socket.assigns.quantity - 1, 1)
{:noreply, assign(socket, :quantity, quantity)}
end
@impl true
def handle_event("add_to_cart", _params, socket) do
variant = socket.assigns.selected_variant
if variant do
cart = Cart.add_item(socket.assigns.raw_cart, variant.id, socket.assigns.quantity)
socket =
socket
|> BerrypodWeb.CartHook.broadcast_and_update(cart)
|> assign(:quantity, 1)
|> assign(:cart_drawer_open, true)
|> assign(:cart_status, "#{socket.assigns.product.title} added to cart")
{:noreply, socket}
else
{:noreply, socket}
end
end
@impl true
def render(assigns) do
~H"""
<BerrypodWeb.PageTemplates.pdp {assigns} />
"""
end
end