Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -118,28 +118,49 @@ def generate_custom_dish():
|
|
| 118 |
if not result.get('success'):
|
| 119 |
return jsonify({"success": False, "error": "Failed to create custom dish in Salesforce"}), 500
|
| 120 |
|
| 121 |
-
#
|
| 122 |
email = session.get('user_email') # Assuming you have the user's email in session
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
'
|
| 129 |
-
'
|
| 130 |
-
'
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
|
|
|
|
|
|
|
|
|
| 135 |
|
| 136 |
-
|
| 137 |
-
|
| 138 |
|
| 139 |
-
|
| 140 |
-
|
| 141 |
else:
|
| 142 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 143 |
|
| 144 |
except Exception as e:
|
| 145 |
return jsonify({"success": False, "error": str(e)}), 500
|
|
@@ -147,7 +168,6 @@ def generate_custom_dish():
|
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
-
|
| 151 |
import re
|
| 152 |
@app.route("/edit_profile", methods=["GET", "POST"])
|
| 153 |
def edit_profile():
|
|
|
|
| 118 |
if not result.get('success'):
|
| 119 |
return jsonify({"success": False, "error": "Failed to create custom dish in Salesforce"}), 500
|
| 120 |
|
| 121 |
+
# Query to check if the cart item already exists for the user
|
| 122 |
email = session.get('user_email') # Assuming you have the user's email in session
|
| 123 |
+
existing_cart_item_query = f"SELECT Id, Name, Quantity__c, Price__c, Base_Price__c FROM Cart_Item__c WHERE Customer_Email__c = '{email}' AND Name = '{dish_name}'"
|
| 124 |
+
existing_cart_item_result = sf.query(existing_cart_item_query)
|
| 125 |
+
|
| 126 |
+
if existing_cart_item_result['totalSize'] > 0:
|
| 127 |
+
# If the cart item exists, update the quantity and price
|
| 128 |
+
existing_cart_item = existing_cart_item_result['records'][0]
|
| 129 |
+
new_quantity = existing_cart_item['Quantity__c'] + 1
|
| 130 |
+
new_price = existing_cart_item['Base_Price__c'] * new_quantity
|
| 131 |
+
|
| 132 |
+
# Update the cart item with new quantity and price
|
| 133 |
+
updated_cart_item = {
|
| 134 |
+
'Id': existing_cart_item['Id'],
|
| 135 |
+
'Quantity__c': new_quantity,
|
| 136 |
+
'Price__c': new_price
|
| 137 |
+
}
|
| 138 |
|
| 139 |
+
# Update the existing Cart_Item__c record in Salesforce
|
| 140 |
+
cart_update_result = sf.Cart_Item__c.update(updated_cart_item)
|
| 141 |
|
| 142 |
+
if not cart_update_result.get('success'):
|
| 143 |
+
return jsonify({"success": False, "error": "Failed to update cart item in Salesforce"}), 500
|
| 144 |
else:
|
| 145 |
+
# If the cart item does not exist, create a new one
|
| 146 |
+
cart_item = {
|
| 147 |
+
'Name': dish_name,
|
| 148 |
+
'Price__c': price,
|
| 149 |
+
'Base_Price__c': price,
|
| 150 |
+
'Image1__c': item_image_url,
|
| 151 |
+
'Quantity__c': 1, # Set the quantity to 1 for the new cart item
|
| 152 |
+
'Add_Ons__c': '', # Set Add_ons__c to empty
|
| 153 |
+
'Add_Ons_Price__c': 0, # Set Add_ons_Price__c to 0
|
| 154 |
+
'Customer_Email__c': email # Associate the custom dish with the logged-in user
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
# Insert the custom dish as a Cart_Item__c record in Salesforce
|
| 158 |
+
cart_result = sf.Cart_Item__c.create(cart_item)
|
| 159 |
+
|
| 160 |
+
if not cart_result.get('success'):
|
| 161 |
+
return jsonify({"success": False, "error": "Failed to add custom dish to the cart"}), 500
|
| 162 |
+
|
| 163 |
+
return redirect(url_for("cart")) # Redirect to the cart page after adding to the cart
|
| 164 |
|
| 165 |
except Exception as e:
|
| 166 |
return jsonify({"success": False, "error": str(e)}), 500
|
|
|
|
| 168 |
|
| 169 |
|
| 170 |
|
|
|
|
| 171 |
import re
|
| 172 |
@app.route("/edit_profile", methods=["GET", "POST"])
|
| 173 |
def edit_profile():
|