-
-
Save shankardevy/fe73a83d4ebd6efdc6c4684062f9439d 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 = "?" | |
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 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment