def add_to_cart():
    if 'cart' not in session:
        session['cart'] = {}   #tao ra gio hang rong

    cart = session['cart']

    #data = request.json
    #lay du lieu tu js/main.js
    data = json.loads(request.data)
    id = str(data.get("id"))
    room_number = data.get("room_number")
    price = data.get("price", 0)

    if id in cart:
        cart[id]['quantity'] = cart[id]['quantity'] + 1
    else: #chua co sp trong gio hang
        cart[id] = {
            "id": id,
            "room_number": room_number,
            "price": price,
            "quantity": 1
        }

    session['cart'] = cart

    quantity, amount = utils.cart_stats(cart)

    return jsonify({
        "total_quantity": quantity,
        "total_amount": amount
    })
def check_out():
    quantity, amount = utils.cart_stats(session.get('cart'))
    cart_info = {
        "total_quantity": quantity,
        "total_amount": amount
    }
    return render_template('checkout.html', cart_info=cart_info)
예제 #3
0
def add_to_cart():
    if 'cart' not in session:
        session['cart'] = {}

    cart = session['cart']

    data = json.loads(request.data)

    id = str(data.get("id"))
    name = data.get("name")
    price = data.get("price", 0)
    if id in cart:
        del cart[id]
    else:
        cart[id] = {
            "id": id,
            "name": name,
            "price": price,
            "quantity": 1
        }
    session['cart'] = cart
    quantity, amount = utils.cart_stats(cart)
    list_ticket = utils.list_ticket_in_cart(cart)
    return jsonify({
        "total_quantity": quantity,
        "total_amount": amount,
        "list_ticket": list_ticket,
    })
예제 #4
0
def common_data():
    q, s = utils.cart_stats()
    return {
        'categories': dao.read_categories(),
        'cart_quantity': q,
        'cart_sum': s
    }
예제 #5
0
def cart():
    cart = session.get('cart')
    quantity, amount = utils.cart_stats(cart)
    list_ticket = utils.list_ticket_in_cart(cart)

    return jsonify({
        "total_quantity": quantity,
        "total_amount": amount,
        "list_ticket": list_ticket,
    })