Skip to content

Instantly share code, notes, and snippets.

@shankardevy

shankardevy/cart_view.ex Secret

Last active Aug 18, 2017
Embed
What would you like to do?
defmodule MangoWeb.CartView do
use MangoWeb, :view
alias Mango.Sales.Order
def cart_count(%Plug.Conn{} = conn) do
cart_count(conn.assigns.cart)
end
def cart_count(%Order{} = cart) do
Enum.reduce(cart.line_items, 0, fn(item, acc) ->
acc + item.quantity
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment