Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,10 @@ from flask.sessions import SecureCookieSessionInterface # Import the class
|
|
| 4 |
from salesforce import get_salesforce_connection
|
| 5 |
from datetime import timedelta
|
| 6 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
# Initialize Flask app and Salesforce connection
|
| 9 |
print("Starting app...")
|
|
@@ -611,15 +615,14 @@ def menu():
|
|
| 611 |
)
|
| 612 |
|
| 613 |
|
| 614 |
-
|
| 615 |
-
def cart():
|
| 616 |
email = session.get('user_email')
|
| 617 |
if not email:
|
| 618 |
return redirect(url_for("login"))
|
| 619 |
|
| 620 |
try:
|
| 621 |
# Fetch cart items with Category and Section
|
| 622 |
-
result = sf.query(f"""
|
| 623 |
SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c, Category__c, Section__c
|
| 624 |
FROM Cart_Item__c
|
| 625 |
WHERE Customer_Email__c = '{email}'
|
|
@@ -629,7 +632,7 @@ def cart():
|
|
| 629 |
subtotal = sum(item['Price__c'] for item in cart_items)
|
| 630 |
|
| 631 |
# Fetch reward points
|
| 632 |
-
customer_result = sf.query(f"""
|
| 633 |
SELECT Reward_Points__c
|
| 634 |
FROM Customer_Login__c
|
| 635 |
WHERE Email__c = '{email}'
|
|
@@ -637,21 +640,19 @@ def cart():
|
|
| 637 |
reward_points = customer_result['records'][0].get('Reward_Points__c', 0) if customer_result['records'] else 0
|
| 638 |
|
| 639 |
# Fetch coupons for the user
|
| 640 |
-
coupon_result = sf.query(f"""
|
| 641 |
SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'
|
| 642 |
""")
|
|
|
|
| 643 |
if coupon_result["records"]:
|
| 644 |
raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
|
| 645 |
coupons = raw_coupons.split("\n") if raw_coupons else []
|
| 646 |
-
else:
|
| 647 |
-
coupons = []
|
| 648 |
|
| 649 |
# Initialize suggestions as an empty list
|
| 650 |
suggestions = []
|
| 651 |
|
| 652 |
# If there are items in the cart, fetch suggestions
|
| 653 |
if cart_items:
|
| 654 |
-
# Get the category and section of the first item in the cart (You can choose which item you want to base suggestions on)
|
| 655 |
first_item = cart_items[0]
|
| 656 |
item_category = first_item.get('Category__c', 'All') # Default to 'All' if not found
|
| 657 |
item_section = first_item.get('Section__c', 'Biryanis') # Default to 'Biryanis' if not found
|
|
@@ -666,10 +667,8 @@ def cart():
|
|
| 666 |
'Soft Drinks': ['Starters', 'Biryanis', 'Curries']
|
| 667 |
}
|
| 668 |
|
| 669 |
-
# Get the complementary sections for the selected section
|
| 670 |
suggested_sections = complementary_sections.get(item_section, [])
|
| 671 |
|
| 672 |
-
# Fetch suggestions from the complementary sections
|
| 673 |
try:
|
| 674 |
for suggested_section in suggested_sections:
|
| 675 |
if item_category == "All":
|
|
@@ -688,10 +687,9 @@ def cart():
|
|
| 688 |
AND Veg_NonVeg__c = '{item_category}'
|
| 689 |
LIMIT 4
|
| 690 |
"""
|
| 691 |
-
suggestion_result = sf.query(query)
|
| 692 |
-
suggestions.extend(suggestion_result.get("records", []))
|
| 693 |
|
| 694 |
-
# Limit the number of suggestions to 4
|
| 695 |
if len(suggestions) > 4:
|
| 696 |
suggestions = suggestions[:4]
|
| 697 |
|
|
@@ -712,7 +710,6 @@ def cart():
|
|
| 712 |
print(f"Error fetching cart items: {e}")
|
| 713 |
return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[], suggestions=[])
|
| 714 |
|
| 715 |
-
|
| 716 |
@app.route("/cart/add_suggestion_to_cart", methods=["POST"])
|
| 717 |
def add_suggestion_to_cart():
|
| 718 |
try:
|
|
|
|
| 4 |
from salesforce import get_salesforce_connection
|
| 5 |
from datetime import timedelta
|
| 6 |
import os
|
| 7 |
+
from flask import Flask, render_template, session, redirect, url_for
|
| 8 |
+
from views.cart_page import cart_page # Import the cart_page function from the views module
|
| 9 |
+
|
| 10 |
+
app = Flask(__name__)
|
| 11 |
|
| 12 |
# Initialize Flask app and Salesforce connection
|
| 13 |
print("Starting app...")
|
|
|
|
| 615 |
)
|
| 616 |
|
| 617 |
|
| 618 |
+
def cart_page():
|
|
|
|
| 619 |
email = session.get('user_email')
|
| 620 |
if not email:
|
| 621 |
return redirect(url_for("login"))
|
| 622 |
|
| 623 |
try:
|
| 624 |
# Fetch cart items with Category and Section
|
| 625 |
+
result = salesforce.sf.query(f"""
|
| 626 |
SELECT Name, Price__c, Quantity__c, Add_Ons__c, Add_Ons_Price__c, Image1__c, Instructions__c, Category__c, Section__c
|
| 627 |
FROM Cart_Item__c
|
| 628 |
WHERE Customer_Email__c = '{email}'
|
|
|
|
| 632 |
subtotal = sum(item['Price__c'] for item in cart_items)
|
| 633 |
|
| 634 |
# Fetch reward points
|
| 635 |
+
customer_result = salesforce.sf.query(f"""
|
| 636 |
SELECT Reward_Points__c
|
| 637 |
FROM Customer_Login__c
|
| 638 |
WHERE Email__c = '{email}'
|
|
|
|
| 640 |
reward_points = customer_result['records'][0].get('Reward_Points__c', 0) if customer_result['records'] else 0
|
| 641 |
|
| 642 |
# Fetch coupons for the user
|
| 643 |
+
coupon_result = salesforce.sf.query(f"""
|
| 644 |
SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'
|
| 645 |
""")
|
| 646 |
+
coupons = []
|
| 647 |
if coupon_result["records"]:
|
| 648 |
raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
|
| 649 |
coupons = raw_coupons.split("\n") if raw_coupons else []
|
|
|
|
|
|
|
| 650 |
|
| 651 |
# Initialize suggestions as an empty list
|
| 652 |
suggestions = []
|
| 653 |
|
| 654 |
# If there are items in the cart, fetch suggestions
|
| 655 |
if cart_items:
|
|
|
|
| 656 |
first_item = cart_items[0]
|
| 657 |
item_category = first_item.get('Category__c', 'All') # Default to 'All' if not found
|
| 658 |
item_section = first_item.get('Section__c', 'Biryanis') # Default to 'Biryanis' if not found
|
|
|
|
| 667 |
'Soft Drinks': ['Starters', 'Biryanis', 'Curries']
|
| 668 |
}
|
| 669 |
|
|
|
|
| 670 |
suggested_sections = complementary_sections.get(item_section, [])
|
| 671 |
|
|
|
|
| 672 |
try:
|
| 673 |
for suggested_section in suggested_sections:
|
| 674 |
if item_category == "All":
|
|
|
|
| 687 |
AND Veg_NonVeg__c = '{item_category}'
|
| 688 |
LIMIT 4
|
| 689 |
"""
|
| 690 |
+
suggestion_result = salesforce.sf.query(query)
|
| 691 |
+
suggestions.extend(suggestion_result.get("records", []))
|
| 692 |
|
|
|
|
| 693 |
if len(suggestions) > 4:
|
| 694 |
suggestions = suggestions[:4]
|
| 695 |
|
|
|
|
| 710 |
print(f"Error fetching cart items: {e}")
|
| 711 |
return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[], suggestions=[])
|
| 712 |
|
|
|
|
| 713 |
@app.route("/cart/add_suggestion_to_cart", methods=["POST"])
|
| 714 |
def add_suggestion_to_cart():
|
| 715 |
try:
|