def checkout(): if checkSession() == False: return redirect('login') l = lineItemList() l.getOrder(session['orderid']) ot = 0.0 for item in l.data: ot += float(item['price']) * int(item['quantity']) o = orderList() o.getById(session['orderid']) o.data[0]['status'] = 'completed' o.data[0]['orderprice'] = ot o.update() o = orderList() now = datetime.now() o.set('createtime', str(now)) o.set('status', 'shopping') o.set('userid', session['user']['id']) o.add() o.insert() session['orderid'] = o.data[0]['oid'] print('oid', session['orderid']) print(o.data) return render_template('checkedout.html', title='Check Out Completed')
def order(): if checkSession() == False: return redirect('login') l = lineItemList() if request.args.get('oid') is None: return render_template('error.html', msg='No order id given.') l.getOrder(request.args.get('oid')) if len(l.data) <= 0: return render_template('error.html', msg='No items in cart') print(l.data) #return'' return render_template('order.html', title='Order', lineItems=l.data)
def cart(): if checkSession() == False: return redirect('login') l = lineItemList() l.getOrder(session['orderid']) ot = 0.0 for item in l.data: ot += float(item['price']) * int(item['quantity']) l.getCart(session['orderid']) if len(l.data) <= 0: return render_template('noproduct.html', msg='Please add products') return render_template('cart.html', title='Cart', lineItems=l.data, ot=ot)
def addToCart(): if checkSession() == False: return redirect('login') p = productList() p.getById(request.form.get('pid')) l = lineItemList() l.set('price', p.data[0]['price']) l.set('quantity', request.form.get('quantity')) l.set('oid', session['orderid']) l.set('pid', request.form.get('pid')) l.add() l.insert() print(l.data) return render_template('itemAdded.html', title='Item Added.', msg='Item added.')