32 lines
707 B
Elixir
32 lines
707 B
Elixir
|
|
defmodule BerrypodWeb.Shop.Pages.Cart do
|
||
|
|
@moduledoc """
|
||
|
|
Cart page handler for the unified Shop.Page LiveView.
|
||
|
|
"""
|
||
|
|
|
||
|
|
import Phoenix.Component, only: [assign: 3]
|
||
|
|
|
||
|
|
alias Berrypod.Pages
|
||
|
|
|
||
|
|
def init(socket, _params, _uri) do
|
||
|
|
page = Pages.get_page("cart")
|
||
|
|
|
||
|
|
socket =
|
||
|
|
socket
|
||
|
|
|> assign(:page_title, "Cart")
|
||
|
|
|> assign(:page, page)
|
||
|
|
|
||
|
|
{:noreply, socket}
|
||
|
|
end
|
||
|
|
|
||
|
|
def handle_params(_params, _uri, socket) do
|
||
|
|
{:noreply, socket}
|
||
|
|
end
|
||
|
|
|
||
|
|
def handle_event(_event, _params, _socket), do: :cont
|
||
|
|
|
||
|
|
# Called from render to compute the subtotal
|
||
|
|
def compute_assigns(assigns) do
|
||
|
|
Map.put(assigns, :cart_page_subtotal, Berrypod.Cart.calculate_subtotal(assigns.cart_items))
|
||
|
|
end
|
||
|
|
end
|