Update app.py
Browse files
app.py
CHANGED
@@ -52,20 +52,23 @@ def reorder(order_id):
|
|
52 |
WHERE Id = '{order_id}' AND Customer_Email__c = '{customer_email}'
|
53 |
"""
|
54 |
result = sf.query(query)
|
55 |
-
|
56 |
-
|
57 |
-
if not
|
58 |
return jsonify({"success": False, "error": "Order not found"})
|
59 |
|
|
|
|
|
60 |
# Parse the order details (you might want to adjust this depending on your actual Order_Details__c format)
|
61 |
order_details = order.get('Order_Details__c', "").split("\n")
|
62 |
|
63 |
for item in order_details:
|
64 |
item_details = item.split(" | ")
|
65 |
|
|
|
66 |
if len(item_details) > 1:
|
67 |
item_name = item_details[0].strip()
|
68 |
-
quantity = int(item_details[1].split("x")[1].strip())
|
69 |
addons = item_details[2].replace("Add-Ons:", "").strip()
|
70 |
instructions = item_details[3].replace("Instructions:", "").strip()
|
71 |
price = float(item_details[4].replace("Price:", "").replace("$", "").strip())
|
@@ -80,18 +83,18 @@ def reorder(order_id):
|
|
80 |
WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'
|
81 |
"""
|
82 |
result_cart = sf.query(query_cart)
|
83 |
-
cart_items = result_cart.get("records", [])
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
|
|
88 |
existing_quantity = cart_items[0]['Quantity__c']
|
89 |
existing_addons = cart_items[0].get('Add_Ons__c', "None")
|
90 |
existing_addons_price = cart_items[0].get('Add_Ons_Price__c', 0)
|
91 |
existing_instructions = cart_items[0].get('Instructions__c', "")
|
92 |
|
|
|
93 |
combined_addons = f"{existing_addons}; {addons}".strip("; ")
|
94 |
-
|
95 |
combined_instructions = f"{existing_instructions} | {instructions}".strip(" | ")
|
96 |
|
97 |
sf.Cart_Item__c.update(cart_item_id, {
|
|
|
52 |
WHERE Id = '{order_id}' AND Customer_Email__c = '{customer_email}'
|
53 |
"""
|
54 |
result = sf.query(query)
|
55 |
+
|
56 |
+
# Ensure that the order exists
|
57 |
+
if not result.get("records"):
|
58 |
return jsonify({"success": False, "error": "Order not found"})
|
59 |
|
60 |
+
order = result["records"][0] # Safely access the first record
|
61 |
+
|
62 |
# Parse the order details (you might want to adjust this depending on your actual Order_Details__c format)
|
63 |
order_details = order.get('Order_Details__c', "").split("\n")
|
64 |
|
65 |
for item in order_details:
|
66 |
item_details = item.split(" | ")
|
67 |
|
68 |
+
# Ensure that item details are in the correct format
|
69 |
if len(item_details) > 1:
|
70 |
item_name = item_details[0].strip()
|
71 |
+
quantity = int(item_details[1].split("x")[1].strip()) # Safely extract quantity
|
72 |
addons = item_details[2].replace("Add-Ons:", "").strip()
|
73 |
instructions = item_details[3].replace("Instructions:", "").strip()
|
74 |
price = float(item_details[4].replace("Price:", "").replace("$", "").strip())
|
|
|
83 |
WHERE Customer_Email__c = '{customer_email}' AND Name = '{item_name}'
|
84 |
"""
|
85 |
result_cart = sf.query(query_cart)
|
|
|
86 |
|
87 |
+
# Ensure there are cart items found for this product
|
88 |
+
if result_cart.get("records"):
|
89 |
+
cart_items = result_cart["records"]
|
90 |
+
cart_item_id = cart_items[0]['Id'] # Safely access the first record
|
91 |
existing_quantity = cart_items[0]['Quantity__c']
|
92 |
existing_addons = cart_items[0].get('Add_Ons__c', "None")
|
93 |
existing_addons_price = cart_items[0].get('Add_Ons_Price__c', 0)
|
94 |
existing_instructions = cart_items[0].get('Instructions__c', "")
|
95 |
|
96 |
+
# Combine addons and instructions
|
97 |
combined_addons = f"{existing_addons}; {addons}".strip("; ")
|
|
|
98 |
combined_instructions = f"{existing_instructions} | {instructions}".strip(" | ")
|
99 |
|
100 |
sf.Cart_Item__c.update(cart_item_id, {
|