Admin UI at /admin/orders to view, filter, and inspect orders. Adds list_orders/1 and count_orders_by_status/0 to the Orders context, status filter tabs, clickable order table with streams, and a detail page showing items, totals, and shipping address. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
43 lines
1.0 KiB
Elixir
43 lines
1.0 KiB
Elixir
defmodule SimpleshopTheme.OrdersFixtures do
|
|
@moduledoc """
|
|
Test helpers for creating orders.
|
|
"""
|
|
|
|
alias SimpleshopTheme.Orders
|
|
|
|
def order_fixture(attrs \\ %{}) do
|
|
attrs = Enum.into(attrs, %{})
|
|
|
|
items = [
|
|
%{
|
|
variant_id: "var_#{System.unique_integer([:positive])}",
|
|
name: Map.get(attrs, :product_name, "Test product"),
|
|
variant: Map.get(attrs, :variant_title, "Red / Large"),
|
|
price: Map.get(attrs, :unit_price, 1999),
|
|
quantity: Map.get(attrs, :quantity, 1)
|
|
}
|
|
]
|
|
|
|
order_attrs = %{
|
|
items: items,
|
|
customer_email: Map.get(attrs, :customer_email, "customer@example.com"),
|
|
currency: Map.get(attrs, :currency, "gbp")
|
|
}
|
|
|
|
{:ok, order} = Orders.create_order(order_attrs)
|
|
|
|
case attrs[:payment_status] do
|
|
"paid" ->
|
|
{:ok, order} = Orders.mark_paid(order, "pi_test_#{System.unique_integer([:positive])}")
|
|
order
|
|
|
|
"failed" ->
|
|
{:ok, order} = Orders.mark_failed(order)
|
|
order
|
|
|
|
_ ->
|
|
order
|
|
end
|
|
end
|
|
end
|