All checks were successful
deploy / deploy (push) Successful in 3m32s
- add product_id to order_items (migration + schema + create_order) - cart recovery email now includes a direct product link per item - extend session cookie max_age to 7 days so carts survive browser restarts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
37 lines
881 B
Elixir
37 lines
881 B
Elixir
defmodule Berrypod.Orders.OrderItem do
|
|
use Ecto.Schema
|
|
import Ecto.Changeset
|
|
|
|
@primary_key {:id, :binary_id, autogenerate: true}
|
|
@foreign_key_type :binary_id
|
|
|
|
schema "order_items" do
|
|
field :variant_id, :string
|
|
field :product_id, :string
|
|
field :product_name, :string
|
|
field :variant_title, :string
|
|
field :quantity, :integer
|
|
field :unit_price, :integer
|
|
|
|
belongs_to :order, Berrypod.Orders.Order
|
|
|
|
timestamps(type: :utc_datetime)
|
|
end
|
|
|
|
def changeset(item, attrs) do
|
|
item
|
|
|> cast(attrs, [
|
|
:variant_id,
|
|
:product_id,
|
|
:product_name,
|
|
:variant_title,
|
|
:quantity,
|
|
:unit_price,
|
|
:order_id
|
|
])
|
|
|> validate_required([:variant_id, :product_name, :quantity, :unit_price])
|
|
|> validate_number(:quantity, greater_than: 0)
|
|
|> validate_number(:unit_price, greater_than_or_equal_to: 0)
|
|
end
|
|
end
|