I wanna be able to have my users select size on the items they are 
selecting and be able to send it to cart with the other details of the 
selected item, i dont know how to achieve this, any ideas?

<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 />


*<select><option selected="selecred">Choose Size</option><option>1</option>*



*<option>2</option><option>3</option><option>4</option>**<option>5</option>*
*</select>*



On Tuesday, July 2, 2019 at 8:40:54 PM UTC+2, Val K wrote:
>
> 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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/5e14e674-aef3-4895-897c-326b4cbb53a5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to