Esempio n. 1
0
def get_product_ids_from_cart(uid):
    product_ids = []
    cart = carts.get_cart(uid)
    for item in cart:
        product = item.item_id
        product_ids.append(product)
    return product_ids
Esempio n. 2
0
def display(auth_context):
    """
    View function for displaying the checkout page.

    Parameters:
       auth_context (dict): The authentication context of request.
                            See middlewares/auth.py for more information.
    Output:
       Rendered HTML page.
    """

    products = []
    # Prepares the checkout form.
    # See middlewares/form_validation.py for more information.
    form = CheckOutForm()
    product_id = request.args.get('id')
    from_cart = request.args.get('from_cart')
    # Checkout one single item if parameter id presents in the URL query string.
    # Checkout all the items in the user's cart if parameter from_cart presents
    # in the URL query string and parameter id is absent.
    if product_id:
        product = product_catalog.get_product(product_id)
        products.append(product)
        checkout_type = 'product'
        return render_template('checkout.html',
                               products=products,
                               auth_context=auth_context,
                               form=form,
                               bucket=product_catalog.BUCKET,
                               checkout_type=checkout_type,
                               product_id=product_id)
    elif from_cart:
        uid = auth_context.get('uid')
        cart = carts.get_cart(uid)
        for item in cart:
            product = product_catalog.get_product(item.item_id)
            products.append(product)
        checkout_type = 'cart'
        return render_template('checkout.html',
                               products=products,
                               auth_context=auth_context,
                               form=form,
                               bucket=product_catalog.BUCKET,
                               checkout_type=checkout_type)

    return redirect(url_for('product_catalog_page.display'))
Esempio n. 3
0
def get_cart(uid):
    """
    Endpoint for getting cart items

    Args:
        uid (String): User ID

    Returns:
        JSON object describing user cart. Returns empty JSON if cart doesn't exist.
    """
    cart = carts.get_cart(uid)
    response = []
    for item in cart:
        response.append({
            'item_id': item.item_id,
            'document_id': item.document_id,
            'modify_time': item.modify_time,
            'uid': item.uid
        })
    return jsonify(response), 200
Esempio n. 4
0
def display(auth_context):
    """
    View function for displaying the contents of the cart.

    Parameters:
        auth_context (dict): The authentication context of request.
                             See middlewares/auth.py for more information.
    Output:
        Rendered HTML page.
    """

    cart = carts.get_cart(auth_context.get('uid'))
    for item in cart:
        product = product_catalog.get_product(item.item_id)
        item.info = product

    return render_template("cart.html",
                           cart=cart,
                           auth_context=auth_context,
                           bucket=product_catalog.BUCKET)