nagasurendra commited on
Commit
127463e
·
verified ·
1 Parent(s): 9167a3f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -22
app.py CHANGED
@@ -79,31 +79,18 @@ def generate_custom_dish():
79
  return jsonify({"success": False, "error": "Both fields are required"}), 400
80
 
81
  # Check if the custom dish already exists (case-sensitive check)
82
- query = f"SELECT Id, Name, Total_Ordered__c FROM Custom_Dish__c WHERE Name = '{dish_name}'"
83
  result = sf.query(query)
84
 
85
- # If there are no records returned, result['records'] will be empty
86
  if result['records']:
87
  # Custom dish already exists
 
88
  custom_dish = result['records'][0] # Get the existing custom dish record
89
- total_ordered = custom_dish.get('Total_Ordered__c', 0) # Safe way to access 'Total_Ordered__c'
90
-
91
- # Increment the Total_Ordered__c by 1
92
- new_total_ordered = total_ordered + 1
93
-
94
- # Update the existing custom dish with the new Total_Ordered__c value
95
- update_data = {
96
- 'Total_Ordered__c': new_total_ordered
97
- }
98
-
99
- # Update the existing custom dish in Salesforce
100
- update_result = sf.Custom_Dish__c.update(custom_dish_id, update_data)
101
-
102
- if not update_result.get('success', False): # Ensure 'success' exists
103
- return jsonify({"success": False, "error": "Failed to update custom dish in Salesforce"}), 500
104
 
 
105
  # Set up cart item using the existing custom dish details
106
- price = custom_dish.get('Price__c', 0) # Safe way to access 'Price__c'
107
  email = session.get('user_email') # Assuming you have the user's email in session
108
 
109
  # Create the cart item with custom dish details
@@ -123,7 +110,7 @@ def generate_custom_dish():
123
  # Insert the cart item as a Cart_Item__c record in Salesforce
124
  cart_result = sf.Cart_Item__c.create(cart_item)
125
 
126
- if cart_result.get('success', False):
127
  return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
128
  else:
129
  return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500
@@ -148,13 +135,13 @@ def generate_custom_dish():
148
  'Image2__c': item_image_url2,
149
  'Description__c': description,
150
  'Veg_NonVeg__c': category,
151
- 'Total_Ordered__c': 1 # Set Total_Ordered__c to 1 for new custom dishes
152
  }
153
 
154
  # Insert the custom dish into Salesforce
155
  result = sf.Custom_Dish__c.create(custom_dish)
156
 
157
- if result.get('success', False):
158
  # After creating the custom dish, add it to the Cart_Item__c
159
  email = session.get('user_email') # Assuming you have the user's email in session
160
 
@@ -173,7 +160,7 @@ def generate_custom_dish():
173
  # Insert the custom dish as a Cart_Item__c record in Salesforce
174
  cart_result = sf.Cart_Item__c.create(cart_item)
175
 
176
- if cart_result.get('success', False):
177
  return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
178
  else:
179
  return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500
 
79
  return jsonify({"success": False, "error": "Both fields are required"}), 400
80
 
81
  # Check if the custom dish already exists (case-sensitive check)
82
+ query = f"SELECT Id, Name FROM Custom_Dish__c WHERE Name = '{dish_name}'"
83
  result = sf.query(query)
84
 
85
+ # If the dish exists, use the existing record ID, otherwise create a new one
86
  if result['records']:
87
  # Custom dish already exists
88
+ custom_dish_id = result['records'][0]['Id']
89
  custom_dish = result['records'][0] # Get the existing custom dish record
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
+ # No need to create a new dish, just add it to the cart
92
  # Set up cart item using the existing custom dish details
93
+ price = custom_dish['Price__c'] # Use the existing price
94
  email = session.get('user_email') # Assuming you have the user's email in session
95
 
96
  # Create the cart item with custom dish details
 
110
  # Insert the cart item as a Cart_Item__c record in Salesforce
111
  cart_result = sf.Cart_Item__c.create(cart_item)
112
 
113
+ if cart_result.get('success'):
114
  return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
115
  else:
116
  return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500
 
135
  'Image2__c': item_image_url2,
136
  'Description__c': description,
137
  'Veg_NonVeg__c': category,
138
+ 'Total_Ordered__c': 0
139
  }
140
 
141
  # Insert the custom dish into Salesforce
142
  result = sf.Custom_Dish__c.create(custom_dish)
143
 
144
+ if result.get('success'):
145
  # After creating the custom dish, add it to the Cart_Item__c
146
  email = session.get('user_email') # Assuming you have the user's email in session
147
 
 
160
  # Insert the custom dish as a Cart_Item__c record in Salesforce
161
  cart_result = sf.Cart_Item__c.create(cart_item)
162
 
163
+ if cart_result.get('success'):
164
  return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
165
  else:
166
  return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500