Skip to content

Commit

Permalink
update of quantity of items in carts is now possible
Browse files Browse the repository at this point in the history
  • Loading branch information
Mino committed May 9, 2010
1 parent 7675ca2 commit 6156763
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
26 changes: 23 additions & 3 deletions src/cart.erl
Expand Up @@ -10,8 +10,8 @@


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


-define(i2l(Integer),integer_to_list(Integer)).


%%==================================================================== %%====================================================================
%% Template Functions %% Template Functions
Expand Down Expand Up @@ -44,7 +44,9 @@ list(Template) ->
quantityTextbox() -> quantityTextbox() ->
quantityTextbox(""). quantityTextbox("").
quantityTextbox(Class) -> quantityTextbox(Class) ->
#textbox{class=Class, text=?i2l(product:quantity())}. #textbox{class=Class,
id="Qty"++?i2l(product:id()),
text=?i2l(product:quantity())}.


rowTotal() -> rowTotal() ->
price:toString(product:quantity() * product:raw_price()). price:toString(product:quantity() * product:raw_price()).
Expand All @@ -60,6 +62,11 @@ deleteLink() ->
postback={delete,product:id()}}, postback={delete,product:id()}},
#link{text="delete", actions=Delegate}. #link{text="delete", actions=Delegate}.


updateLink() ->
Delegate = #event{type=click, delegate=cart,
postback={update,product:id()}},
#link{text="update", actions=Delegate}.

%%==================================================================== %%====================================================================
%% External Functions %% External Functions
%%==================================================================== %%====================================================================
Expand Down Expand Up @@ -130,8 +137,21 @@ event({delete,ProdId}) ->
Cart = get_cart(), Cart = get_cart(),
Products = [X||X<-Cart#cart.products,X#cartItem.prodId /= ProdId], Products = [X||X<-Cart#cart.products,X#cartItem.prodId /= ProdId],


set_cart(Cart#cart{products=Products}),
wf:redirect("");
event({update,ProdId}) ->
Cart = get_cart(),
Qty = ?l2i(hd(wf:q("Qty"++?i2l(ProdId)))),
Update = fun(Item) ->
case Item#cartItem.prodId == ProdId of
true ->
Item#cartItem{quantity=Qty};
false ->
Item
end
end,
Products = [Update(X)||X<-Cart#cart.products],
set_cart(Cart#cart{products=Products}), set_cart(Cart#cart{products=Products}),
wf:redirect(""). wf:redirect("").





2 changes: 1 addition & 1 deletion wwwroot/cartItem.html
Expand Up @@ -7,7 +7,7 @@
</td> </td>
<td>[[[product:price()]]]</td> <td>[[[product:price()]]]</td>
<td>[[[cart:rowTotal()]]]</td> <td>[[[cart:rowTotal()]]]</td>
<td>updateBtn</td> <td>[[[cart:updateLink()]]]</td>
<td>[[[cart:deleteLink()]]]</td> <td>[[[cart:deleteLink()]]]</td>
</tr> </tr>


0 comments on commit 6156763

Please sign in to comment.