Beispiel #1
0
def order_checkout(user, storeId, orderID):
    order_fields = order_schema.load(request.json)

    store = Store.query.filter_by(id=storeId, user_id=user.id).first()
    if not store:
        return abort(400, description="Incorrect storeID in URL")

    order = Order.query.filter_by(id=orderID)
    if not order:
        return abort(400, description="orderID does not exist")

    order.update(order_fields)
    db.session.commit()
    return jsonify(order_schema.dump(order[0]))
Beispiel #2
0
def order_create():
    # create new order
    order_fields = order_schema.load(request.json)

    shipping_id = request.args["shipping_id"]
    shipping_id = OrderShipping.query.filter_by(id=shipping_id).first()

    new_order = Order()
    new_order.date_ordered = order_fields["date_ordered"]
    new_order.shipped = order_fields["shipped"]

    shipping_id.orders.append(new_order)
    db.session.commit()

    return jsonify(order_schema.dump(new_order))
Beispiel #3
0
def order_create(storeId, customerID):
    order_fields = order_schema.load(request.json)

    new_order = Order()
    new_order.order_placed = order_fields["order_placed"]
    cart = order_fields["cart"]
    for item in cart:
        item_query = Product.query.filter_by(id=item).first()
        new_order.orders_products.append(item_query)
        db.session.commit()
    new_order.customer_id = customerID

    customer = Customer.query.filter_by(id=customerID).first()
    if not customer:
        return abort(400, description="Incorrect customer")

    customer.order.append(new_order)
    db.session.commit()

    return jsonify(order_schema.dump(new_order))
Beispiel #4
0
def order_index():
    order = Order.query.all()
    serialized_data = order_schema.dump(order)
    return jsonify(serialized_data)
Beispiel #5
0
def order_show(id):
    # return single order
    order = Order.query.get(id)
    return jsonify(order_schema.dump(order))