Skip to content

Commit

Permalink
properly commented products.erl to allow edoc to be generated
Browse files Browse the repository at this point in the history
  • Loading branch information
Mino committed May 12, 2010
1 parent a9eb819 commit f9bd9d7
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1,2 +1,3 @@
ebin/* ebin/*
Mnesia* Mnesia*
doc/*
7 changes: 4 additions & 3 deletions src/cart.erl
Expand Up @@ -21,8 +21,9 @@ add(Quantity, Product) ->
Prods = cc_add(#cartItem{prodId=ProdId,quantity=Quantity}, Prods = cc_add(#cartItem{prodId=ProdId,quantity=Quantity},
Cart#cart.products, []), Cart#cart.products, []),
set_cart(Cart#cart{products=Prods}), set_cart(Cart#cart{products=Prods}),
wf:update(cart_content,list()). wf:redirect("").

%wf:update(cart_content,list()).
%Cookie issues, need to be fixed.
%%==================================================================== %%====================================================================
%% Internal Functions %% Internal Functions
%%==================================================================== %%====================================================================
Expand All @@ -37,7 +38,7 @@ set_cart(Cart) ->
end. end.


get_cart() -> get_cart() ->
case true of %%check user logged in case false of %%check user logged in
false -> false ->
cookie_cart(); cookie_cart();
true -> true ->
Expand Down
109 changes: 99 additions & 10 deletions src/product.erl
Expand Up @@ -6,22 +6,63 @@
%%% Created : 29 Apr 2010 by <Mino@X60S> %%% Created : 29 Apr 2010 by <Mino@X60S>
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module (product). -module (product).
-compile (export_all). -compile(export_all).

%%-API-----------------------------------------------------------------
-export([load/1,
load/0,
raw_price/0,
get_Id/1,
get_price/1]).

%%-Template------------------------------------------------------------
-export([loadFromPath/0,
id/0,
name/0,
url/0,
img/0,
description/0,
price/0,
buyLink/0,
quantity/0,
quantityTextbox/1]).


-include_lib ("nitrogen/include/wf.inc"). -include_lib ("nitrogen/include/wf.inc").
-include("records.hrl"). -include("records.hrl").
-include("utils.hrl"). -include("utils.hrl").


-define(PRODUCT,wf:state(product)). -define(PRODUCT,wf:state(product)).
%% @type prodId() = integer()

%% @type product() = #product{id=integer(), name=string(),
%% url=string(), cat_id=catId(),
%% img=string(), price=integer(),
%% quantity=integer(),
%% description=string()}


%%==================================================================== %%====================================================================
%% API Functions %% API Functions
%%==================================================================== %%====================================================================

%%--------------------------------------------------------------------
%% @private
%% @spec load(prodId()|product()) -> ok
%% @doc Load a product into memory.

%% TODO: handle failure
%% @end
%%--------------------------------------------------------------------
load(Product) when is_record(Product,product)-> load(Product) when is_record(Product,product)->
wf:state(product,Product); wf:state(product,Product);
load(ProdId) -> load(ProdId) ->
wf:state(product,(db:get_product(ProdId))#product{quantity="1"}). wf:state(product,(db:get_product(ProdId))#product{quantity="1"}).


%%--------------------------------------------------------------------
%% @private
%% @spec load() -> bool()
%% @doc Uses pathinfo to load a product into memory.
%% @end
%%--------------------------------------------------------------------
load() -> load() ->
case wf:state(pathInfo) of case wf:state(pathInfo) of
"112"++ProdId -> "112"++ProdId ->
Expand All @@ -30,52 +71,100 @@ load() ->
_ -> false _ -> false
end. end.


raw_price() -> %%--------------------------------------------------------------------
(?PRODUCT)#product.price. %% @private

%% @spec get_Id(Product::product()) -> integer()
%% @doc return the id of the currently loaded product.
%% @end
%%-------------------------------------------------------------------
get_Id(Product) -> get_Id(Product) ->
Product#product.id. Product#product.id.


%%--------------------------------------------------------------------
%% @private
%% @spec get_price(product()) -> integer()
%% @doc returns the unformatted price of the currently loaded product.
%% @end
%%-------------------------------------------------------------------
get_price(Product) -> get_price(Product) ->
Product#product.price. Product#product.price.


%%==================================================================== %%====================================================================
%% Template Functions %% Template Functions
%%==================================================================== %%====================================================================

%%--------------------------------------------------------------------
%% @spec loadFromPath() -> []
%% @doc Uses pathinfo to load a product into memory.
%% @end
%%-------------------------------------------------------------------
loadFromPath() -> loadFromPath() ->
load(), load(),
[]. [].


id() -> %%--------------------------------------------------------------------
(?PRODUCT)#product.id. %% @spec name() -> string()

%% @doc returns the name of the currently loaded product.
%% @end
%%-------------------------------------------------------------------
name() -> name() ->
(?PRODUCT)#product.name. (?PRODUCT)#product.name.


%%--------------------------------------------------------------------
%% @deprecated no longer needed
%% @spec url() -> string()
%% @doc returns the url of the currently loaded product.
%% @end
%%-------------------------------------------------------------------
url() -> url() ->
(?PRODUCT)#product.url. (?PRODUCT)#product.url.


%%--------------------------------------------------------------------
%% @spec img() -> string()
%% @doc returns the path to the image of the currently loaded product.
%% @end
%%--------------------------------------------------------------------
img() -> img() ->
image:load((?PRODUCT)#product.img). image:load((?PRODUCT)#product.img).


%%--------------------------------------------------------------------
%% @spec description() -> string()
%% @doc returns the description of the currently loaded product.
%% @end
%%--------------------------------------------------------------------
description() -> description() ->
(?PRODUCT)#product.description. (?PRODUCT)#product.description.


%%--------------------------------------------------------------------
%% @spec price() -> string()
%% @doc returns the price of the currently loaded product.
%% @end
%%--------------------------------------------------------------------
price() -> price() ->
price:toString((?PRODUCT)#product.price). price:toString((?PRODUCT)#product.price).


%%--------------------------------------------------------------------
%% @spec buyLink() -> HTML
%% @doc returns a link that places the currently loaded product
%% in the cart.
%% @end
%%--------------------------------------------------------------------
buyLink() -> buyLink() ->
Delegate = #event{type=click, delegate=product, postback={buy,?PRODUCT}}, Delegate = #event{type=click, delegate=product, postback={buy,?PRODUCT}},
#link{text="add to cart", class="icon cart_put", actions=Delegate}. #link{text="add to cart", class="icon cart_put", actions=Delegate}.


quantity() -> %%--------------------------------------------------------------------
(?PRODUCT)#product.quantity. %% @spec quantityTextbox(class()) -> HTML

%% @doc returns a texbox used to enter the quantity of the currently
%% loaded product to add to the cart.
%% @end
%%--------------------------------------------------------------------
quantityTextbox(Class) -> quantityTextbox(Class) ->
#textbox{id="Qty" ++ ?i2l(id()), #textbox{id="Qty" ++ ?i2l(id()),
class=Class, class=Class,
text=(?PRODUCT)#product.quantity}. text=(?PRODUCT)#product.quantity}.


%% @hidden
event({buy,Product}) -> event({buy,Product}) ->
Qty = case wf:q("Qty"++ ?i2l(get_Id(Product))) of Qty = case wf:q("Qty"++ ?i2l(get_Id(Product))) of
[] -> 1; [] -> 1;
Expand Down
6 changes: 5 additions & 1 deletion wwwroot/index.html
Expand Up @@ -60,7 +60,11 @@ <h1>Cookie Cart</h1>
<div class="block"> <div class="block">
<h3>Cart</h3> <h3>Cart</h3>
[[[cart:list()]]] [[[cart:list()]]]
<a href="./cart">Cart</a> <h4>[[[cart:totalPrice()]]]</h4>
<div class="text-right">
<a href="checkout">Checkout</a><br/>
<a href="cart">Show cart</a>
</div>
</div> </div>


<div class="block"> <div class="block">
Expand Down

0 comments on commit f9bd9d7

Please sign in to comment.