def list_order(): div = DIV() num_car = 0 tong_tien = 0 carts = '' table = TABLE(_class='table') table.append( TR(TH('Sản phẩm'), TH('Số lượng'), TH(''), TH('Giá'), TH(B('Thành tiền')), TH(B('Chức năng')))) if request.cookies.has_key('cart_shop'): carts = eval(request.cookies['cart_shop'].value) from plugin_cms import CmsModel from plugin_cms import CmsFolder cms = CmsModel() db = cms.db cms.define_table('san_pham') from plugin_app import number_format for cart in carts: cart = eval(cart) row = db((db.san_pham.id == cart['id'])).select().first() if row: tong_tien += int(row.gia_san_pham) * int(cart['num']) thanh_tien = int(row.gia_san_pham) * int(cart['num']) input_num = INPUT(_type='text', _class='integer', _value=cart['num'], _name='number_pr_%s' % (row.id), _style="width: 55px; text-align: center;") ajax = "ajax('%s', ['number_pr_%s'], 'wr_list_order')" % (URL( c='plugin_app', f='update_carts', args=[request.args(0), row.id, 'delete']), row.id) ajax1 = "ajax('%s', ['number_pr_%s'], 'wr_list_order')" % (URL( c='plugin_app', f='update_carts', args=[request.args(0), row.id, 'update']), row.id) table.append( TR( TD(row.name, ': '), TD(input_num), TD(' * '), TD(number_format(row.gia_san_pham), ' VNĐ'), TD(B(number_format(thanh_tien), ' VNĐ')), TD(DIV(A(SPAN(_class='glyphicon glyphicon-floppy-save'), 'Cập nhật', _onclick=ajax1, _class='btn btn-primary'), _class='btn-group'), A(SPAN(_class='glyphicon glyphicon-remove'), 'Xóa', _onclick=ajax, _class='btn btn-danger'), _class='setting'))) num_car += 1 div.append(table) p_tong = DIV(SPAN('Tổng tiền: ')) p_tong.append( str(number_format(tong_tien) if tong_tien != 0 else '0') + ' VNĐ') div.append(B(p_tong, _class='text-right')) return div
def add_cart(): pid = request.vars.pid ar_carts =[] if request.cookies.has_key ('cart_shop'): carts = eval(request.cookies['cart_shop'].value) i=0 for cart in carts: cart = eval(cart) if cart['id']==pid: ar_carts.append(str({'id':str(cart['id']) ,'num':str(int(cart['num'])+1)})) i+=1 else: ar_carts.append(str({'id':str(cart['id']) ,'num':str(cart['num'])})) if i==0: ar_carts.append(str({'id':pid ,'num':str(1)})) else: ar_carts.append(str({'id':pid ,'num':str(1)})) response.cookies['cart_shop'] = str(ar_carts) response.cookies['cart_shop']['expires'] = 24 * 3600 response.cookies['cart_shop']['path'] = '/' response.flash = T("Add new cart!") # load view_carts() nhung ko request duoc cookies moi div = DIV() num_car = 0 tong_tien = 0 carts = ar_carts from plugin_cms import CmsModel from plugin_cms import CmsFolder cms = CmsModel() db = cms.db cms.define_table('san_pham') from plugin_app import number_format for cart in carts: cart = eval(cart) row = db((db.san_pham.id==cart['id'])).select().first() if row: div1 = DIV(_class='list_cart') ul = UL() ul.append(LI(row.name)) ul.append(LI(SPAN('Số lượng: '),cart['num'])) ul.append(LI(SPAN('Giá: '),number_format(row.gia_san_pham),' VNĐ')) div1.append(DIV(IMG(_src=cms.get_avatar('san_pham',row.avatar),_class='thumbnail'),_class='col-md-4 box_ivinh')) div1.append(DIV(ul,_class='col-md-8 box_ivinh')) div.append(div1) div.append(HR()) tong_tien += int(row.gia_san_pham)* int(cart['num']) num_car +=1 p_tong = DIV(SPAN('Tổng tiền: ')) p_tong.append(str(number_format(tong_tien))+' VNĐ') div.append(B(p_tong,_class='text-right')) div.append(A('Gửi đơn hàng',_href=URL(c='portal',f='folder',args=['checkout']),_class='btn btn-success')) return div
def view_carts(): div = DIV() num_car = 0 tong_tien = 0 carts = '' try: if request.cookies.has_key('cart_shop'): carts = eval(request.cookies['cart_shop'].value) from plugin_cms import CmsModel from plugin_cms import CmsFolder cms = CmsModel() db = cms.db cms.define_table('san_pham') from plugin_app import number_format for cart in carts: cart = eval(cart) row = db((db.san_pham.id == cart['id']) & (db.san_pham.folder == CmsFolder().get_folder( request.args(0)))).select().first() if row: div1 = DIV(_class='list_cart') ul = UL() ul.append(LI(row.name)) ul.append(LI(SPAN('Số lượng: '), cart['num'])) ul.append( LI(SPAN('Giá: '), number_format(row.gia_san_pham), ' VNĐ')) div1.append( DIV(IMG(_src=cms.get_avatar('san_pham', row.avatar), _class='thumbnail'), _class='col-md-4 box_ivinh')) div1.append(DIV(ul, _class='col-md-8 box_ivinh')) div.append(div1) div.append(HR()) tong_tien += int(row.gia_san_pham) * int(cart['num']) num_car += 1 if num_car > 0: p_tong = DIV(SPAN('Tổng tiền: ')) p_tong.append(str(number_format(tong_tien)) + ' VNĐ') div.append(B(p_tong, _class='text-right')) div.append( A('Thanh toán', _href=URL(c='portal', f='folder', args=request.args(0), vars=dict(page='cart')), _class='btn btn-success')) else: div.append('Giỏ hàng trống') except Exception, e: return e
def update_carts(): pid = request.args(1) number = 'number_pr_%s' % (pid) number_pr = request.vars[number] ar_carts = [] if request.args(2) == 'delete': if request.cookies.has_key('cart_shop'): carts = eval(request.cookies['cart_shop'].value) i = 0 for cart in carts: cart = eval(cart) if cart['id'] == pid: i += 1 else: ar_carts.append( str({ 'id': str(cart['id']), 'num': str(cart['num']) })) if i == 0: ar_carts.append(str({'id': pid, 'num': str(1)})) else: ar_carts.append(str({'id': pid, 'num': str(1)})) elif request.args(2) == 'update': if request.cookies.has_key('cart_shop'): carts = eval(request.cookies['cart_shop'].value) i = 0 for cart in carts: cart = eval(cart) if cart['id'] == pid: ar_carts.append( str({ 'id': str(cart['id']), 'num': str(number_pr) })) i += 1 else: ar_carts.append( str({ 'id': str(cart['id']), 'num': str(cart['num']) })) if i == 0: ar_carts.append(str({'id': pid, 'num': str(1)})) else: ar_carts.append(str({'id': pid, 'num': str(1)})) response.cookies['cart_shop'] = str(ar_carts) response.cookies['cart_shop']['expires'] = 24 * 3600 response.cookies['cart_shop']['path'] = '/' div = DIV() num_car = 0 tong_tien = 0 table = TABLE(_class='table') table.append( TR(TH('Sản phẩm'), TH('Số lượng'), TH(''), TH('Giá'), TH(B('Thành tiền')), TH(B('Chức năng')))) carts = ar_carts from plugin_cms import CmsModel from plugin_cms import CmsFolder cms = CmsModel() db = cms.db cms.define_table('san_pham') from plugin_app import number_format for cart in carts: cart = eval(cart) row = db((db.san_pham.id == cart['id'])).select().first() if row: tong_tien += int(row.gia_san_pham) * int(cart['num']) thanh_tien = int(row.gia_san_pham) * int(cart['num']) input_num = INPUT(_type='text', _value=cart['num'], _name='number_pr_%s' % (row.id), _style="width: 55px; text-align: center;") ajax = "ajax('%s', ['number_pr_%s'], 'wr_list_order')" % (URL( c='plugin_app', f='update_carts', args=[request.args(0), row.id, 'delete']), row.id) ajax1 = "ajax('%s', ['number_pr_%s'], 'wr_list_order')" % (URL( c='plugin_app', f='update_carts', args=[request.args(0), row.id, 'update']), row.id) table.append( TR( TD(row.name, ': '), TD(input_num), TD(' * '), TD(number_format(row.gia_san_pham), ' VNĐ'), TD(B(number_format(thanh_tien), ' VNĐ')), TD(DIV(A(SPAN(_class='glyphicon glyphicon-floppy-save'), 'Cập nhật', _onclick=ajax1, _class='btn btn-primary'), _class='btn-group'), A(SPAN(_class='glyphicon glyphicon-remove'), 'Xóa', _onclick=ajax, _class='btn btn-danger'), _class='setting'))) num_car += 1 div.append(table) p_tong = DIV(SPAN('Tổng tiền: ')) p_tong.append(str(number_format(tong_tien)) + ' VNĐ') div.append(B(p_tong, _class='text-right')) response.flash = T('Cập nhật thành công.') return div
def view_order(): div = DIV(_id="view_order") num_car = 0 tong_tien = 0 carts ='' if request.cookies.has_key('cart_shop'): carts = eval(request.cookies['cart_shop'].value) from plugin_cms import CmsModel from plugin_cms import CmsFolder cms = CmsModel() db = cms.db cms.define_table('san_pham') from plugin_app import number_format table = TABLE(_class='table') table.append(TR(TH('Sản phẩm'),TH('Số lượng'),TH(''),TH('Giá'),TH(B('Thành tiền')))) for cart in carts: cart = eval(cart) row = db((db.san_pham.id==cart['id'])&(db.san_pham.folder== CmsFolder().get_folder(request.args(0)))).select().first() if row: tong_tien += int(row.gia_san_pham)* int(cart['num']) input_num = INPUT(_type='text',_value=cart['num']) table.append(TR(TD(row.name,': '),TD(input_num),TD(' * '),TD(number_format(row.gia_san_pham),' VNĐ'),TD(B(number_format(tong_tien),' VNĐ')))) div.append(table) num_car +=1 p_tong = DIV(SPAN('Tổng tiền: ')) p_tong.append(str(number_format(tong_tien))+' VNĐ') div.append(B(p_tong,_class='text-right')) form = FORM() div1 = DIV(_class="form-group") div1.append(LABEL('Họ và tên')) div1.append(INPUT(_type='text',_class="form-control",_placeholder="Họ và tên" )) form.append(div1) div1 = DIV(_class="form-group") div1.append(LABEL('Email')) div1.append(INPUT(_type='text',_class="form-control",_placeholder="Email")) form.append(div1) div1 = DIV(_class="form-group") div1.append(LABEL('Điện thoại')) div1.append(INPUT(_type='text',_class="form-control",_placeholder="Điện thoại")) form.append(div1) div1 = DIV(_class="form-group") div1.append(LABEL('Địa chỉ nhận hàng')) div1.append(INPUT(_type='text',_class="form-control",_placeholder="Địa chỉ nhận hàng")) form.append(div1) div1 = DIV(_class="form-group") div1.append(LABEL('Lời nhắn')) div1.append(TEXTAREA(_class="form-control",_rows="3",_placeholder="Lời nhắn")) form.append(div1) div1 = DIV(_class="form-group") div1.append(LABEL('Lời nhắn')) div1.append(TEXTAREA(_class="form-control",_rows="3",_placeholder="Lời nhắn")) form.append(div1) ajax = "ajax('%s', [], 'order_view')"%(URL(f='act_add_cart',args=request.args)) form.append(A('Gửi đặt hàng',_onclick=ajax, _class='btn btn-success')) div.append(form) return div
def view_don_hang(): from plugin_app import number_format don_hang_id = request.args(1) don_hang = cms.define_table('don_hang') don_hang_item = cms.define_table('don_hang_item') san_pham = cms.define_table('san_pham') rows_don_hang = cms.db.don_hang[don_hang_id] query = (don_hang_item.r_don_hang == don_hang_id) rows_don_hang_item = cms.db(query).select() div = DIV() table = TABLE(_class='table') table.append(TR(TH('Khách hàng'), TD(rows_don_hang.nguoi_nhan_hang))) table.append(TR(TH('Địa chỉ nhận hàng'), TD(rows_don_hang.dia_chi))) table.append(TR(TH('Lời nhắn:'), TD(rows_don_hang.loi_nhan))) div.append(table) div.append(H4('Chi tiết đơn hàng')) table = TABLE(_class='table') table.append( TR(TH('Stt', _style="width: 30px;"), TH('Tên sản phẩm'), TH('Số lượng'), TH('Đơn giá'), TH('Thành tiền'))) i = 1 for row in rows_don_hang_item: if row.r_san_pham.r_folder == int(request.args(0)): table.append( TR( TD(i, _class='text-center'), TD(row.r_san_pham.name), TD(row.so_luong), TD(number_format(row.gia_ban), ' VNĐ'), TD(number_format(int(row.gia_ban) * int(row.so_luong)), ' VNĐ'))) i += 1 div.append(table) div_bt = DIV(_class="modal-footer") div_st = DIV(_class="btn-group") div_st.append( BUTTON(T('Cập nhật trạng thái'), _type="button", _class="btn btn-default dropdown-toggle", **{ "_data-toggle": "dropdown", "_aria-expanded": "false" })) don_hang_status = cms.define_table('don_hang_status') row_status = cms.db(don_hang_status.id > 0).select() ul_st = UL(_class="dropdown-menu") for s in row_status: # ajax = "ajax('%s', [], '')"%(URL(f='update_don_hang',args=request.args,vars=dict('status'=s.id))) ul_st.append(LI(A(s.name, _class="btn btn-default"))) div_st.append((ul_st)) # div_bt.append((div_st)) # div_bt.append(A('Xóa đơn hàng',_class="btn btn-default")) div_bt.append( A('Gửi phản hồi', _href="mailto:%s?Subject=Xin chào khách hàng %s" % (rows_don_hang.email, rows_don_hang.nguoi_nhan_hang), _class="btn btn-primary")) div_bt.append( A('Thoát', _class="btn btn-default", **{"_data-dismiss": "modal"})) div.append(div_bt) return div