Hello everyone
I'm building an app where users are going to use a barcode scanner to
add products to a cart.
In the session I keep up a dictionary of products in cart, so if a
product is scanned twice it will increase quantity rather than add
another entry.
That worked fine, but now I wanted to add a form so that users can
update quantity by typing the number in the form. So when a new
barcode is scanned and not in the dictionary I create a new form and
add it (to another dictionary). The form displays, but I just can't
make it work. So I'm wondering if this actually possible, or if I'm
doing something wrong. I attach the code. I'm by no means an expert on
this incredible framework, so any suggestions or corrections are
welcome.
----- code starts -----
form = FORM(INPUT(_name="search", requires=IS_NOT_EMPTY()),
INPUT(_type="submit", _value="Search"),
_name="form_search")
if form.accepts(request.vars,session,formname="form_search"):
rows=db(db.productos.barcode==request.vars.search).select()
if len(rows) == 1:
product = rows.first()
if product.id in session.cart:
session.cart_qty[product.id]+=1
session.qty_forms[product.id][0]
['_value']=session.cart_qty[product.id]
else:
session.cart[product.id]=producto
session.cart_qty[product.id]=1
qty_form=FORM(INPUT( _name="qty", _value=1),
INPUT(_type="hidden",
_name="prod_id",
_value=product.id),
INPUT(_type="submit",_value=T("Update"),_style="display:none;"),
_name="formqty"+str(product.id))
if qty_form.accepts(request.vars, session,
formname="formqty"+str(product.id)):
session.cart_qty[request.vars.prod_id]+=1
temp_qty =
session.cart_qty[request.vars.prod_id]
session.qty_forms[request.vars.prod_id][0]['_value'] = temp_qty
session.qty_forms[product.id]=qty_form
----- code starts -----