Subbu1304 commited on
Commit
9e988d1
·
verified ·
1 Parent(s): d59069d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +68 -30
app.py CHANGED
@@ -126,43 +126,81 @@ 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
-
 
166
 
167
 
168
 
 
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
+ try:
167
+ if cart_item_result['totalSize'] > 0:
168
+ # If the custom dish is already in the cart, update the quantity and price
169
+ cart_item = cart_item_result['records'][0]
170
+
171
+ # Make sure quantity is an integer (rounded if necessary)
172
+ new_quantity = int(cart_item['Quantity__c']) + 1 # Increase quantity by 1 and ensure it's an integer
173
+ new_price = price * new_quantity # Update price based on new quantity
174
+
175
+ # Update the cart item in Salesforce
176
+ updated_cart_item = {
177
+ 'Quantity__c': new_quantity,
178
+ 'Price__c': new_price
179
+ }
180
+
181
+ cart_item_update = sf.Cart_Item__c.update(cart_item['Id'], updated_cart_item)
182
 
183
+ else:
184
+ # If the custom dish is not in the cart, create a new cart item
185
+ cart_item = {
186
+ 'Name': dish_name,
187
+ 'Price__c': price,
188
+ 'Base_Price__c': price,
189
+ 'Image1__c': item_image_url,
190
+ 'Quantity__c': 1, # Default quantity is 1
191
+ 'Add_Ons__c': '', # Set Add_ons__c to empty
192
+ 'Add_Ons_Price__c': 0, # Set Add_ons_Price__c to 0
193
+ 'Customer_Email__c': email # Associate the custom dish with the logged-in user
194
+ }
195
 
196
+ # Insert the custom dish as a Cart_Item__c record in Salesforce
197
+ cart_result = sf.Cart_Item__c.create(cart_item)
198
 
199
+ # Redirect to the cart page after successfully adding or updating the cart item
200
+ return redirect(url_for("cart"))
201
 
202
+ except Exception as e:
203
+ return jsonify({"success": False, "error": str(e)}), 500
204
 
205
 
206