Example #1
0
def undo_remove_product(product_number, quantity):
    current_order = Order.load(current_user)
    if not current_order:
        current_order = Order()
        if not current_user.is_anonymous:
            current_user.current_order = current_order
    line = current_order.add_line(
        product_number=product_number,
        quantity=quantity
    )
    current_order.save()

    flash('Returned {} of "{}" to cart.'.format(line.quantity, line.label))
    return redirect(request.args.get('origin') or url_for('shop.cart'))
Example #2
0
def add_to_cart(product_number):
    form = AddProductForm(prefix=product_number)
    if form.validate_on_submit:
        qty = form.quantity.data
        pn = product_number
        current_order = Order.load(current_user)
        if not current_order:
            current_order = Order()
            if not current_user.is_anonymous:
                current_user.current_order = current_order
        line = current_order.add_line(product_number=pn, quantity=qty)
        current_order.save()
        flash(
            'Added {0} of "{1}" to shopping cart.'.format(line.quantity,
                                                          line.label)
        )
        return redirect(request.args.get('origin') or url_for('shop.cart'))