Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,21 +48,46 @@ def generate_coupon_code(length=10):
|
|
| 48 |
"""Generates a random alphanumeric coupon code"""
|
| 49 |
characters = string.ascii_uppercase + string.digits # A-Z, 0-9
|
| 50 |
return ''.join(random.choice(characters) for _ in range(length))
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
def previous_orders():
|
| 53 |
-
|
| 54 |
-
sf = SalesforceConnection()
|
| 55 |
|
| 56 |
-
# Query to fetch
|
| 57 |
-
query = f""
|
| 58 |
-
SELECT Name, Order_Details__c
|
| 59 |
-
FROM Order__c
|
| 60 |
-
WHERE Customer_Email__c = '{user_email}'
|
| 61 |
-
ORDER BY CreatedDate DESC
|
| 62 |
-
"""
|
| 63 |
orders = sf.query(query)
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
@app.route("/signup", methods=["GET", "POST"])
|
| 68 |
def signup():
|
|
|
|
| 48 |
"""Generates a random alphanumeric coupon code"""
|
| 49 |
characters = string.ascii_uppercase + string.digits # A-Z, 0-9
|
| 50 |
return ''.join(random.choice(characters) for _ in range(length))
|
| 51 |
+
from flask import render_template
|
| 52 |
+
from simple_salesforce import Salesforce
|
| 53 |
+
import json
|
| 54 |
+
|
| 55 |
+
# Connect to Salesforce
|
| 56 |
+
sf = Salesforce(username='your_username', password='your_password', security_token='your_security_token')
|
| 57 |
+
|
| 58 |
+
@app.route('/previous_orders')
|
| 59 |
def previous_orders():
|
| 60 |
+
email = 'customer_email@example.com' # Get the email dynamically (e.g., from session or request)
|
|
|
|
| 61 |
|
| 62 |
+
# Query Salesforce to fetch previous orders based on the email
|
| 63 |
+
query = f"SELECT Order_Details__c, Total_Amount__c, Order_Date__c FROM Order__c WHERE Customer_Email__c = '{email}'"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
orders = sf.query(query)
|
| 65 |
|
| 66 |
+
# Process each order and extract details
|
| 67 |
+
processed_orders = []
|
| 68 |
+
for order in orders['records']:
|
| 69 |
+
order_details = order['Order_Details__c']
|
| 70 |
+
items = order_details.split('\n')
|
| 71 |
+
order_items = []
|
| 72 |
+
|
| 73 |
+
for item in items:
|
| 74 |
+
item_parts = item.split('|')
|
| 75 |
+
order_items.append({
|
| 76 |
+
'name': item_parts[0].strip(),
|
| 77 |
+
'addons': item_parts[1].strip().replace('Add-Ons:', ''),
|
| 78 |
+
'instructions': item_parts[2].strip().replace('Instructions:', ''),
|
| 79 |
+
'price': item_parts[3].strip().replace('Price:', ''),
|
| 80 |
+
'image': item_parts[4].strip().replace('Image:', ''),
|
| 81 |
+
})
|
| 82 |
+
|
| 83 |
+
processed_orders.append({
|
| 84 |
+
'items': order_items,
|
| 85 |
+
'total_amount': order['Total_Amount__c'],
|
| 86 |
+
'order_date': order['Order_Date__c']
|
| 87 |
+
})
|
| 88 |
+
|
| 89 |
+
return render_template('previous_orders.html', orders=processed_orders)
|
| 90 |
+
|
| 91 |
|
| 92 |
@app.route("/signup", methods=["GET", "POST"])
|
| 93 |
def signup():
|