user press 'button pill'  - web2py.js does ajax request with URL = 
('cart_callback', ...) and writes response to  html element with id = 
target = 'items%s'%p.id 

On Tuesday, July 2, 2019 at 3:35:03 PM UTC+3, mostwanted wrote:
>
> Can anyone please explain to me in lay-man terms how the code below works! 
> It is a function for adding items to the shopping cart. I am trying to 
> use the same concept to have customers add item sizes as well as they add 
> the items to the cart but i am missing something!
>
> *VIEW*
> <br />
>     <span id="{{='item%s'%p.id}}" style="font-weight: bold; color: red;">
> {{=session.cart.get(p.id,0)}}</span> in cart - {{=A('add to 
> cart',callback=URL('cart_callback',vars=dict(id=p.id
> ,action='add')),target='item%s'%p.id,_class='button pill')}}
>     <br />
>
> *CART VIEW*
> </td></tr>
>   {{for id, qty in cart.items():}}{{p=db.product(id)}}
>   <tr id="boughtItems">
>       <td><span style="font-weight: bold;">{{=p.item}}</span></td>
>       <td><span style="font-weight: bold;">{{=MoneyFormat(p.price)}}
> </span></td>
>       <td><span id="{{='item%s'%p.id}}" style="font-weight: bold;">
> {{=qty}}</span></td>
>       <td><span style="font-weight: bold;">{{=MoneyFormat(qty*p.price)}}
> </span></td>
>       <td>
>
> *CONTROLLER*
> def cart_callback():
>     id = int(request.vars.id)
>     if request.vars.action == 'add':
>         session.cart[id]=session.cart.get(id,0)+1
>     if request.vars.action == 'sub':
>         session.cart[id]=max(0,session.cart.get(id,0)-1)
>     return str(session.cart[id])
>
> Regards
>
> Mostwanted
>
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/b6aa4897-655a-4257-9b13-e50b3cc8511d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to