Permalink
Browse files

update of quantity of items in carts is now possible

  • Loading branch information...
1 parent 7675ca2 commit 615676393e13e30b3895e6c5e889d15887311adb Mino committed May 9, 2010
Showing with 24 additions and 4 deletions.
  1. +23 −3 src/cart.erl
  2. +1 −1 wwwroot/cartItem.html
View
@@ -10,8 +10,8 @@
-include_lib ("nitrogen/include/wf.inc").
-include("records.hrl").
+-include("utils.hrl").
--define(i2l(Integer),integer_to_list(Integer)).
%%====================================================================
%% Template Functions
@@ -44,7 +44,9 @@ list(Template) ->
quantityTextbox() ->
quantityTextbox("").
quantityTextbox(Class) ->
- #textbox{class=Class, text=?i2l(product:quantity())}.
+ #textbox{class=Class,
+ id="Qty"++?i2l(product:id()),
+ text=?i2l(product:quantity())}.
rowTotal() ->
price:toString(product:quantity() * product:raw_price()).
@@ -60,6 +62,11 @@ deleteLink() ->
postback={delete,product:id()}},
#link{text="delete", actions=Delegate}.
+updateLink() ->
+ Delegate = #event{type=click, delegate=cart,
+ postback={update,product:id()}},
+ #link{text="update", actions=Delegate}.
+
%%====================================================================
%% External Functions
%%====================================================================
@@ -131,7 +138,20 @@ event({delete,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}),
wf:redirect("").
-
@@ -7,7 +7,7 @@
</td>
<td>[[[product:price()]]]</td>
<td>[[[cart:rowTotal()]]]</td>
- <td>updateBtn</td>
+ <td>[[[cart:updateLink()]]]</td>
<td>[[[cart:deleteLink()]]]</td>
</tr>

0 comments on commit 6156763

Please sign in to comment.