-
-
Save shankardevy/18f23aae6e5bad38e8286c66d5f685f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MangoWeb.CartController do | |
use MangoWeb, :controller | |
alias Mango.Sales | |
def add(conn, %{"cart" => cart_params}) do | |
cart = conn.assigns.cart | |
case Sales.add_to_cart(cart, cart_params) do | |
{:ok, _} -> | |
%{"product_name" => name, "pack_size" => size, "quantity" => qty} = cart_params | |
message = "Product added to cart - #{name}(#{size}) x #{qty} qty" | |
conn | |
|> put_flash(:info, message) | |
|> redirect(to: page_path(conn, :index)) | |
{:error, _} -> | |
conn | |
|> put_flash(:info, "Error adding product to cart") | |
|> redirect(to: page_path(conn, :index)) | |
end | |
end | |
def show(conn, _params) do | |
cart = conn.assigns.cart | |
render conn, "show.html", cart: cart | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment