Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -139,17 +139,37 @@ def menu_page():
|
|
| 139 |
# Route for handling order
|
| 140 |
@app.route("/order", methods=["POST"])
|
| 141 |
def place_order():
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
# Route for the order summary page
|
| 155 |
@app.route("/order-summary", methods=["GET"])
|
|
|
|
| 139 |
# Route for handling order
|
| 140 |
@app.route("/order", methods=["POST"])
|
| 141 |
def place_order():
|
| 142 |
+
order_data = request.json
|
| 143 |
+
item_name = order_data.get('item')
|
| 144 |
+
quantity = order_data.get('quantity')
|
| 145 |
+
|
| 146 |
+
if not item_name or not quantity:
|
| 147 |
+
return jsonify({"error": "Item and quantity are required."}), 400
|
| 148 |
+
|
| 149 |
+
# Assuming `sf.Customer_Login__c` is where user login details are saved
|
| 150 |
+
try:
|
| 151 |
+
customer_login = sf.query(f"SELECT Id FROM Customer_Login__c WHERE Email__c = '{user_email}' LIMIT 1")
|
| 152 |
+
customer_id = customer_login['records'][0]['Id']
|
| 153 |
+
|
| 154 |
+
order = {
|
| 155 |
+
'Order_Item__c': item_name,
|
| 156 |
+
'Quantity__c': quantity,
|
| 157 |
+
'Customer__c': customer_id, # Linking the order to the customer by email
|
| 158 |
+
'Status__c': 'Pending',
|
| 159 |
+
'Total_Amount__c': calculate_total_price(item_name, quantity), # You will need to implement this calculation
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
order_response = sf.Order__c.create(order)
|
| 163 |
+
return jsonify({"success": True, "order_id": order_response['id']}), 200
|
| 164 |
+
except Exception as e:
|
| 165 |
+
return jsonify({"error": f"Error placing the order: {str(e)}"}), 500
|
| 166 |
+
|
| 167 |
+
# Helper function to calculate the total price (implement as per your pricing logic)
|
| 168 |
+
def calculate_total_price(item_name, quantity):
|
| 169 |
+
item = sf.query(f"SELECT Price__c FROM Menu_Item__c WHERE Name = '{item_name}' LIMIT 1")
|
| 170 |
+
price = item['records'][0]['Price__c']
|
| 171 |
+
return price * quantity
|
| 172 |
+
|
| 173 |
|
| 174 |
# Route for the order summary page
|
| 175 |
@app.route("/order-summary", methods=["GET"])
|