Update app.py
Browse files
app.py
CHANGED
|
@@ -642,6 +642,7 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 642 |
"Please provide your phone number and delivery address.")
|
| 643 |
|
| 644 |
# Step 4: Parse phone & address (for single or multi-dish orders), then skip extras.
|
|
|
|
| 645 |
if state and state.flow == "order" and state.step == 3:
|
| 646 |
phone_pattern = r'(\+?\d{10,15})'
|
| 647 |
phone_match = re.search(phone_pattern, message)
|
|
@@ -663,14 +664,34 @@ async def process_order_flow(user_id: str, message: str) -> str:
|
|
| 663 |
return "Thank you. Please provide your delivery address."
|
| 664 |
shipping_cost = calculate_shipping_cost(state.data["address"])
|
| 665 |
state.data["shipping_cost"] = shipping_cost
|
|
|
|
| 666 |
# Automatically set extras to empty since we're not using extras anymore.
|
| 667 |
state.data["extras"] = ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 668 |
# Skip extras prompt and jump directly to confirmation (Step 7)
|
| 669 |
state.step = 7
|
| 670 |
-
return (f"
|
| 671 |
-
f"
|
| 672 |
-
f"
|
| 673 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
|
| 675 |
|
| 676 |
# 7) Step 7: Order Confirmation and Payment Link Generation
|
|
|
|
| 642 |
"Please provide your phone number and delivery address.")
|
| 643 |
|
| 644 |
# Step 4: Parse phone & address (for single or multi-dish orders), then skip extras.
|
| 645 |
+
# --- Step 4: Parse phone & address, compute order summary, and jump to confirmation ---
|
| 646 |
if state and state.flow == "order" and state.step == 3:
|
| 647 |
phone_pattern = r'(\+?\d{10,15})'
|
| 648 |
phone_match = re.search(phone_pattern, message)
|
|
|
|
| 664 |
return "Thank you. Please provide your delivery address."
|
| 665 |
shipping_cost = calculate_shipping_cost(state.data["address"])
|
| 666 |
state.data["shipping_cost"] = shipping_cost
|
| 667 |
+
|
| 668 |
# Automatically set extras to empty since we're not using extras anymore.
|
| 669 |
state.data["extras"] = ""
|
| 670 |
+
|
| 671 |
+
# Compute order summary details:
|
| 672 |
+
if "orders" in state.data:
|
| 673 |
+
dish_summary = ", ".join(state.data["orders"].keys())
|
| 674 |
+
quantity_total = sum(state.data["orders"].values())
|
| 675 |
+
total_price = 0
|
| 676 |
+
for dish, qty in state.data["orders"].items():
|
| 677 |
+
total_price += get_dish_price(dish) * qty
|
| 678 |
+
total_price += shipping_cost
|
| 679 |
+
else:
|
| 680 |
+
dish_summary = state.data.get("dish", "")
|
| 681 |
+
quantity_total = state.data.get("quantity", 1)
|
| 682 |
+
total_price = (quantity_total * get_dish_price(dish_summary)) + shipping_cost
|
| 683 |
+
|
| 684 |
# Skip extras prompt and jump directly to confirmation (Step 7)
|
| 685 |
state.step = 7
|
| 686 |
+
return (f"Order Summary:\n"
|
| 687 |
+
f"Dish(es): {dish_summary}\n"
|
| 688 |
+
f"Quantity: {quantity_total}\n"
|
| 689 |
+
f"Phone: {state.data.get('phone_number', '')}\n"
|
| 690 |
+
f"Address: {state.data.get('address', '')}\n"
|
| 691 |
+
f"Shipping Cost: N{shipping_cost}\n"
|
| 692 |
+
f"Total Price: N{total_price}\n"
|
| 693 |
+
"Confirm order? (yes/no)")
|
| 694 |
+
|
| 695 |
|
| 696 |
|
| 697 |
# 7) Step 7: Order Confirmation and Payment Link Generation
|