Permalink
Browse files

properly commented products.erl to allow edoc to be generated

  • Loading branch information...
1 parent a9eb819 commit f9bd9d70da7f1fb198e32d5ff8a0eb81c3f4107b Mino committed May 12, 2010
Showing with 110 additions and 15 deletions.
  1. +2 −1 .gitignore
  2. +4 −3 src/cart.erl
  3. +99 −10 src/product.erl
  4. +5 −1 wwwroot/index.html
View
@@ -1,2 +1,3 @@
ebin/*
-Mnesia*
+Mnesia*
+doc/*
View
@@ -21,8 +21,9 @@ add(Quantity, Product) ->
Prods = cc_add(#cartItem{prodId=ProdId,quantity=Quantity},
Cart#cart.products, []),
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
%%====================================================================
@@ -37,7 +38,7 @@ set_cart(Cart) ->
end.
get_cart() ->
- case true of %%check user logged in
+ case false of %%check user logged in
false ->
cookie_cart();
true ->
View
@@ -6,22 +6,63 @@
%%% Created : 29 Apr 2010 by <Mino@X60S>
%%%-------------------------------------------------------------------
-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("records.hrl").
-include("utils.hrl").
-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
%%====================================================================
+
+%%--------------------------------------------------------------------
+%% @private
+%% @spec load(prodId()|product()) -> ok
+%% @doc Load a product into memory.
+
+%% TODO: handle failure
+%% @end
+%%--------------------------------------------------------------------
load(Product) when is_record(Product,product)->
wf:state(product,Product);
load(ProdId) ->
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() ->
case wf:state(pathInfo) of
"112"++ProdId ->
@@ -30,52 +71,100 @@ load() ->
_ -> false
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) ->
Product#product.id.
+%%--------------------------------------------------------------------
+%% @private
+%% @spec get_price(product()) -> integer()
+%% @doc returns the unformatted price of the currently loaded product.
+%% @end
+%%-------------------------------------------------------------------
get_price(Product) ->
Product#product.price.
%%====================================================================
%% Template Functions
%%====================================================================
+
+%%--------------------------------------------------------------------
+%% @spec loadFromPath() -> []
+%% @doc Uses pathinfo to load a product into memory.
+%% @end
+%%-------------------------------------------------------------------
loadFromPath() ->
load(),
[].
-id() ->
- (?PRODUCT)#product.id.
-
+%%--------------------------------------------------------------------
+%% @spec name() -> string()
+%% @doc returns the name of the currently loaded product.
+%% @end
+%%-------------------------------------------------------------------
name() ->
(?PRODUCT)#product.name.
+%%--------------------------------------------------------------------
+%% @deprecated no longer needed
+%% @spec url() -> string()
+%% @doc returns the url of the currently loaded product.
+%% @end
+%%-------------------------------------------------------------------
url() ->
(?PRODUCT)#product.url.
+%%--------------------------------------------------------------------
+%% @spec img() -> string()
+%% @doc returns the path to the image of the currently loaded product.
+%% @end
+%%--------------------------------------------------------------------
img() ->
image:load((?PRODUCT)#product.img).
+%%--------------------------------------------------------------------
+%% @spec description() -> string()
+%% @doc returns the description of the currently loaded product.
+%% @end
+%%--------------------------------------------------------------------
description() ->
(?PRODUCT)#product.description.
+%%--------------------------------------------------------------------
+%% @spec price() -> string()
+%% @doc returns the price of the currently loaded product.
+%% @end
+%%--------------------------------------------------------------------
price() ->
price:toString((?PRODUCT)#product.price).
+%%--------------------------------------------------------------------
+%% @spec buyLink() -> HTML
+%% @doc returns a link that places the currently loaded product
+%% in the cart.
+%% @end
+%%--------------------------------------------------------------------
buyLink() ->
Delegate = #event{type=click, delegate=product, postback={buy,?PRODUCT}},
#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) ->
#textbox{id="Qty" ++ ?i2l(id()),
class=Class,
text=(?PRODUCT)#product.quantity}.
+%% @hidden
event({buy,Product}) ->
Qty = case wf:q("Qty"++ ?i2l(get_Id(Product))) of
[] -> 1;
View
@@ -60,7 +60,11 @@
<div class="block">
<h3>Cart</h3>
[[[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 class="block">

0 comments on commit f9bd9d7

Please sign in to comment.