示例#1
0
def shop_cart():
    categories = getData.load_cate()
    quan, price = utils.cart_stats(session.get('cart'))
    cart_info = {'total_quantity': quan, 'total_amount': price}
    return render_template('shop_cart.html',
                           categories=categories,
                           cart_info=cart_info)
示例#2
0
def delete_item(b_id):
    data = request.json
    book_id = str(data.get('id'))

    cart = session.get('cart')
    for idx, b in enumerate(cart.values()):
        if b['id'] == b_id:
            del cart[idx]
            break

    cart = session['cart']

    if book_id in cart:
        cart[book_id]['quantity'] = 0
        cart[book_id]['subTotal'] = 0

    session['cart'] = cart

    total_quan, total_amount = utils.cart_stats(session['cart'])
    return jsonify({
        "message": "Xoa thanh cong",
        "data": {
            "book_id": b_id
        },
        'total_amount': total_amount,
        'total_quantity': total_quan
    })
示例#3
0
def remove_from_cart():
    data = request.json
    book_id = str(data.get('id'))
    book_name = data.get('name')
    image = data.get('image')
    price = data.get('price')

    cart = session['cart']
    if book_id in cart:  # co san pham trong gio
        quan = cart[book_id]['quantity']
        cart[book_id]['quantity'] = int(quan) - 1
        subp = cart[book_id]['subTotal']
        cart[book_id]['subTotal'] = float(subp) - price
    else:  # chua co san pham trong gio
        cart[book_id] = {
            "id": book_id,
            "name": book_name,
            "image": image,
            "price": price,
            "quantity": 1,
            "subTotal": price
        }

    session['cart'] = cart

    total_quan, total_amount = utils.cart_stats(session['cart'])

    return jsonify({
        "message": "Cập nhật giỏ hàng thành công",
        'total_amount': total_amount,
        'total_quantity': total_quan
    })
示例#4
0
def shop_filter():
    categories = getData.load_cate()
    author_list = getData.load_author()
    book_list = getData.load_books()
    kw = request.args.get("kw")
    min_price = request.args.get("min_price")
    max_price = request.args.get("max_price")
    cate_id = request.args.get("category_id")
    author_id = request.args.get("author_id")
    books = getData.filter_book(cate_id=cate_id,
                                author_id=author_id,
                                min_price=min_price,
                                max_price=max_price,
                                kw=kw)
    quan, price = utils.cart_stats(session.get('cart'))
    cart_info = {'total_quantity': quan, 'total_amount': price}

    return render_template('shop_list.html',
                           books=books,
                           book_list=book_list,
                           kw=kw,
                           min_price=min_price,
                           cate_id=cate_id,
                           author_id=author_id,
                           categories=categories,
                           author_list=author_list,
                           cart_info=cart_info)
示例#5
0
def my_account():
    categories = getData.load_cate()
    quan, price = utils.cart_stats(session.get('cart'))
    cart_info = {'total_quantity': quan, 'total_amount': price}
    if current_user.is_authenticated:
        return render_template("my-account.html",
                               categories=categories,
                               cart_info=cart_info)
    return redirect(url_for('index'))
示例#6
0
def checkout():
    categories = getData.load_cate()
    if request.method == 'POST':

        if utils.add_invoice(session.get('cart')):
            del session['cart']

            return jsonify({"message": "Đặt hàng thành công"})

    quan, price = utils.cart_stats(session.get('cart'))
    cart_info = {'total_quantity': quan, 'total_amount': price}
    return render_template('checkout.html',
                           categories=categories,
                           cart_info=cart_info)
示例#7
0
def index():
    categories = getData.load_cate()
    books = Book.query.all()
    booklm = Book.query.limit(10).all()
    book_list = getData.load_books()
    authors = Author.query.limit(8).all()

    quan, price = utils.cart_stats(session.get('cart'))
    cart_info = {'total_quantity': quan, 'total_amount': price}
    return render_template('index.html',
                           categories=categories,
                           booklm=booklm,
                           books=books,
                           authors=authors,
                           book_list=book_list,
                           cart_info=cart_info)
示例#8
0
def book_detail(book_id):
    categories = getData.load_cate()
    book = getData.get_detail_book(book_id)
    books = Book.query.all()
    book_list = getData.load_books()
    authors = getData.get_author_of_book(book_id)
    images = getData.load_image('300x452', book_id=book_id)
    quan, price = utils.cart_stats(session.get('cart'))
    cart_info = {'total_quantity': quan, 'total_amount': price}

    return render_template('book_detail.html',
                           book=book,
                           books=books,
                           book_list=book_list,
                           categories=categories,
                           authors=authors,
                           images=images,
                           cart_info=cart_info)
示例#9
0
def shop_list(page_num):
    categories = getData.load_cate()
    author_list = getData.load_author()
    books = Book.query.all()
    book_list = getData.load_books()
    book_pagi = Book.query.paginate(per_page=12, page=page_num, error_out=True)
    all_pages = book_pagi.iter_pages()
    quan, price = utils.cart_stats(session.get('cart'))
    cart_info = {'total_quantity': quan, 'total_amount': price}

    return render_template('shop_list.html',
                           book_pagi=book_pagi,
                           book_list=book_list,
                           books=books,
                           categories=categories,
                           author_list=author_list,
                           cart_info=cart_info,
                           page_num=page_num,
                           all_pages=all_pages)