Subbu1304 commited on
Commit
dc65d69
·
verified ·
1 Parent(s): 0bb757e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -66
app.py CHANGED
@@ -126,81 +126,43 @@ def generate_custom_dish():
126
  cart_item_query = f"SELECT Id, Quantity__c, Price__c, Base_Price__c FROM Cart_Item__c WHERE Customer_Email__c = '{email}' AND Name = '{dish_name}'"
127
  cart_item_result = sf.query(cart_item_query)
128
 
129
- # if cart_item_result['totalSize'] > 0:
130
- # # If the custom dish is already in the cart, update the quantity and price
131
- # cart_item = cart_item_result['records'][0]
132
- # new_quantity = cart_item['Quantity__c'] + 1 # Increase quantity by 1
133
- # new_price = price * new_quantity # Update price based on new quantity
134
 
135
- # # Update the cart item in Salesforce
136
- # updated_cart_item = {
137
- # 'Quantity__c': new_quantity,
138
- # 'Price__c': new_price
139
- # }
140
 
141
- # cart_item_update = sf.Cart_Item__c.update(cart_item['Id'], updated_cart_item)
142
-
143
- # else:
144
- # # If the custom dish is not in the cart, create a new cart item
145
- # cart_item = {
146
- # 'Name': dish_name,
147
- # 'Price__c': price,
148
- # 'Base_Price__c': price,
149
- # 'Image1__c': item_image_url,
150
- # 'Quantity__c': 1, # Default quantity is 1
151
- # 'Add_Ons__c': '', # Set Add_ons__c to empty
152
- # 'Add_Ons_Price__c': 0, # Set Add_ons_Price__c to 0
153
- # 'Customer_Email__c': email # Associate the custom dish with the logged-in user
154
- # }
155
-
156
- # # Insert the custom dish as a Cart_Item__c record in Salesforce
157
- # cart_result = sf.Cart_Item__c.create(cart_item)
158
-
159
- # # Redirect to the cart page after successfully adding or updating the cart item
160
- # return redirect(url_for("cart"))
161
-
162
- # except Exception as e:
163
- # return jsonify({"success": False, "error": str(e)}), 500
164
-
165
- if cart_item_result['totalSize'] > 0:
166
- # If the custom dish is already in the cart, update the quantity and price
167
- cart_item = cart_item_result['records'][0]
168
-
169
- # Make sure quantity is an integer (rounded if necessary)
170
- new_quantity = int(cart_item['Quantity__c']) + 1 # Increase quantity by 1 and ensure it's an integer
171
- new_price = price * new_quantity # Update price based on new quantity
172
-
173
- # Update the cart item in Salesforce
174
- updated_cart_item = {
175
- 'Quantity__c': new_quantity,
176
- 'Price__c': new_price
177
- }
178
-
179
- cart_item_update = sf.Cart_Item__c.update(cart_item['Id'], updated_cart_item)
180
 
181
- else:
182
- # If the custom dish is not in the cart, create a new cart item
183
- cart_item = {
184
- 'Name': dish_name,
185
- 'Price__c': price,
186
- 'Base_Price__c': price,
187
- 'Image1__c': item_image_url,
188
- 'Quantity__c': 1, # Default quantity is 1
189
- 'Add_Ons__c': '', # Set Add_ons__c to empty
190
- 'Add_Ons_Price__c': 0, # Set Add_ons_Price__c to 0
191
- 'Customer_Email__c': email # Associate the custom dish with the logged-in user
192
- }
193
 
194
- # Insert the custom dish as a Cart_Item__c record in Salesforce
195
- cart_result = sf.Cart_Item__c.create(cart_item)
196
 
197
  # Redirect to the cart page after successfully adding or updating the cart item
198
  return redirect(url_for("cart"))
199
 
200
- except Exception as e:
201
- return jsonify({"success": False, "error": str(e)}), 500
202
-
203
 
 
204
 
205
  import re
206
  @app.route("/edit_profile", methods=["GET", "POST"])
 
126
  cart_item_query = f"SELECT Id, Quantity__c, Price__c, Base_Price__c FROM Cart_Item__c WHERE Customer_Email__c = '{email}' AND Name = '{dish_name}'"
127
  cart_item_result = sf.query(cart_item_query)
128
 
129
+ if cart_item_result['totalSize'] > 0:
130
+ # If the custom dish is already in the cart, update the quantity and price
131
+ cart_item = cart_item_result['records'][0]
132
+ new_quantity = cart_item['Quantity__c'] + 1 # Increase quantity by 1
133
+ new_price = price * new_quantity # Update price based on new quantity
134
 
135
+ # Update the cart item in Salesforce
136
+ updated_cart_item = {
137
+ 'Quantity__c': new_quantity,
138
+ 'Price__c': new_price
139
+ }
140
 
141
+ cart_item_update = sf.Cart_Item__c.update(cart_item['Id'], updated_cart_item)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
 
143
+ else:
144
+ # If the custom dish is not in the cart, create a new cart item
145
+ cart_item = {
146
+ 'Name': dish_name,
147
+ 'Price__c': price,
148
+ 'Base_Price__c': price,
149
+ 'Image1__c': item_image_url,
150
+ 'Quantity__c': 1, # Default quantity is 1
151
+ 'Add_Ons__c': '', # Set Add_ons__c to empty
152
+ 'Add_Ons_Price__c': 0, # Set Add_ons_Price__c to 0
153
+ 'Customer_Email__c': email # Associate the custom dish with the logged-in user
154
+ }
155
 
156
+ # Insert the custom dish as a Cart_Item__c record in Salesforce
157
+ cart_result = sf.Cart_Item__c.create(cart_item)
158
 
159
  # Redirect to the cart page after successfully adding or updating the cart item
160
  return redirect(url_for("cart"))
161
 
162
+ except Exception as e:
163
+ return jsonify({"success": False, "error": str(e)}), 500
 
164
 
165
+
166
 
167
  import re
168
  @app.route("/edit_profile", methods=["GET", "POST"])