DSatishchandra commited on
Commit
0e194dc
·
verified ·
1 Parent(s): bcde189

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -11
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
- item_name = request.json.get('item_name')
143
- quantity = request.json.get('quantity')
144
- order_data = {"Item__c": item_name, "Quantity__c": quantity}
145
- sf.Order__c.create(order_data)
146
- return jsonify({"success": True, "message": f"Order for {item_name} placed successfully."})
147
-
148
- # Route to handle the cart
149
- @app.route("/cart", methods=["GET"])
150
- def cart():
151
- cart_items = [] # Placeholder for cart items
152
- return render_template("cart_page.html", cart_items=cart_items)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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"])