Example #1
0
    def order(order_id):
        get_order = Order.get_or_none(Order.id == order_id)
        if not order:
            return abort(404)

        prod = Products.get_or_none(Products.id == get_order.product_id)
        total_price = prod.price * get_order.quantite
        if (prod.weight < 500):
            shipping_price = 5
        elif prod.weight < 2000:
            shipping_price = 10
        else:
            shipping_price = 25

        order_json = {
            "order": {
                "id": get_order.id,
                "total_price": total_price,
                "email": null,
                "credit_card": {},
                "shipping_information": {},
                "paid": false,
                "transaction": {},
                "product": {
                    "id": get_order.product_id,
                    "quantity": get_order.quantite
                },
                "shipping_price": shipping_price
            }
        }

        data_order = json.dumps(order_json)
        order_data = json.loads(data_order)
        for product in order_data['order']:
            prod_id = product['id']
            prod_quant = product['quantity']

        order = order_data['order']
        return views.view_order(order, prod_id, prod_quant)