Spaces:
				
			
			
	
			
			
		Runtime error
		
	
	
	
			
			
	
	
	
	
		
		
		Runtime error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -1092,10 +1092,13 @@ def checkout(): | |
| 1092 | 
             
                    }
         | 
| 1093 |  | 
| 1094 | 
             
                    sf.Order__c.create(order_data)
         | 
|  | |
| 1095 |  | 
| 1096 | 
             
                    # β
 Delete cart items after order is placed
         | 
| 1097 | 
             
                    for item in cart_items:
         | 
| 1098 | 
             
                        sf.Cart_Item__c.delete(item["Id"])
         | 
|  | |
|  | |
| 1099 |  | 
| 1100 | 
             
                    return jsonify({"success": True, "message": "Order placed successfully!"})
         | 
| 1101 |  | 
| @@ -1126,6 +1129,97 @@ def order_summary(): | |
| 1126 | 
             
                except Exception as e:
         | 
| 1127 | 
             
                    print(f"Error fetching order details: {str(e)}")
         | 
| 1128 | 
             
                    return render_template("order.html", order=None, error=str(e))
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 1129 |  | 
| 1130 | 
             
            if __name__ == "__main__":
         | 
| 1131 | 
             
                app.run(debug=True, host="0.0.0.0", port=7860)
         | 
|  | |
| 1092 | 
             
                    }
         | 
| 1093 |  | 
| 1094 | 
             
                    sf.Order__c.create(order_data)
         | 
| 1095 | 
            +
                    
         | 
| 1096 |  | 
| 1097 | 
             
                    # β
 Delete cart items after order is placed
         | 
| 1098 | 
             
                    for item in cart_items:
         | 
| 1099 | 
             
                        sf.Cart_Item__c.delete(item["Id"])
         | 
| 1100 | 
            +
                    send_order_email(email, order_data)
         | 
| 1101 | 
            +
             | 
| 1102 |  | 
| 1103 | 
             
                    return jsonify({"success": True, "message": "Order placed successfully!"})
         | 
| 1104 |  | 
|  | |
| 1129 | 
             
                except Exception as e:
         | 
| 1130 | 
             
                    print(f"Error fetching order details: {str(e)}")
         | 
| 1131 | 
             
                    return render_template("order.html", order=None, error=str(e))
         | 
| 1132 | 
            +
            import smtplib
         | 
| 1133 | 
            +
            from email.mime.multipart import MIMEMultipart
         | 
| 1134 | 
            +
            from email.mime.text import MIMEText
         | 
| 1135 | 
            +
             | 
| 1136 | 
            +
            def send_order_email(email, order):
         | 
| 1137 | 
            +
                restaurant_name = "Your Restaurant Name"
         | 
| 1138 | 
            +
                subject = f"Your Order Confirmation from {restaurant_name}"
         | 
| 1139 | 
            +
             | 
| 1140 | 
            +
                # Email content
         | 
| 1141 | 
            +
                message = f"""
         | 
| 1142 | 
            +
                <html>
         | 
| 1143 | 
            +
                <body>
         | 
| 1144 | 
            +
                    <h2>Hello {order['Customer_Name__c']},</h2>
         | 
| 1145 | 
            +
                    <p>Thank you for placing your order with <b>{restaurant_name}!</b> Below are the details of your order:</p>
         | 
| 1146 | 
            +
             | 
| 1147 | 
            +
                    <h3>π Order Summary</h3>
         | 
| 1148 | 
            +
                    <p><b>Order ID:</b> {order['Id']}<br>
         | 
| 1149 | 
            +
                    <b>Customer Name:</b> {order['Customer_Name__c']}<br>
         | 
| 1150 | 
            +
                    <b>Email:</b> {order['Customer_Email__c']}<br>
         | 
| 1151 | 
            +
                    <b>Order Status:</b> {order['Order_Status__c']}</p>
         | 
| 1152 | 
            +
             | 
| 1153 | 
            +
                    <h3>π½οΈ Items Ordered</h3>
         | 
| 1154 | 
            +
                    <table border="1" cellpadding="5" cellspacing="0">
         | 
| 1155 | 
            +
                        <tr>
         | 
| 1156 | 
            +
                            <th>Item Name</th>
         | 
| 1157 | 
            +
                            <th>Quantity</th>
         | 
| 1158 | 
            +
                            <th>Add-Ons</th>
         | 
| 1159 | 
            +
                            <th>Instructions</th>
         | 
| 1160 | 
            +
                            <th>Price</th>
         | 
| 1161 | 
            +
                        </tr>
         | 
| 1162 | 
            +
                """
         | 
| 1163 | 
            +
             | 
| 1164 | 
            +
                # Adding items dynamically
         | 
| 1165 | 
            +
                for item in order["Order_Details__c"].split("\n"):
         | 
| 1166 | 
            +
                    parts = item.split("|")
         | 
| 1167 | 
            +
                    if len(parts) == 5:
         | 
| 1168 | 
            +
                        message += f"""
         | 
| 1169 | 
            +
                        <tr>
         | 
| 1170 | 
            +
                            <td>{parts[0]}</td>
         | 
| 1171 | 
            +
                            <td>{parts[1]}</td>
         | 
| 1172 | 
            +
                            <td>{parts[2]}</td>
         | 
| 1173 | 
            +
                            <td>{parts[3]}</td>
         | 
| 1174 | 
            +
                            <td>{parts[4]}</td>
         | 
| 1175 | 
            +
                        </tr>
         | 
| 1176 | 
            +
                        """
         | 
| 1177 | 
            +
             | 
| 1178 | 
            +
                message += f"""
         | 
| 1179 | 
            +
                    </table>
         | 
| 1180 | 
            +
             | 
| 1181 | 
            +
                    <h3>π° Billing Details</h3>
         | 
| 1182 | 
            +
                    <p><b>Total Amount:</b> ${order['Total_Amount__c']}<br>
         | 
| 1183 | 
            +
                    <b>Discount Applied:</b> ${order['Discount__c']}<br>
         | 
| 1184 | 
            +
                    <b>Final Bill:</b> <b>${order['Total_Bill__c']}</b></p>
         | 
| 1185 | 
            +
             | 
| 1186 | 
            +
                    <p>π <b>Your order is currently:</b> <i>{order['Order_Status__c']}</i><br>
         | 
| 1187 | 
            +
                    π <b>Estimated Delivery Time:</b> [Estimated_Delivery_Time]</p>
         | 
| 1188 | 
            +
             | 
| 1189 | 
            +
                    <hr>
         | 
| 1190 | 
            +
                    <p>If you have any questions regarding your order, feel free to contact us at <b>[Restaurant Support Email]</b>.</p>
         | 
| 1191 | 
            +
             | 
| 1192 | 
            +
                    <p>Looking forward to serving you!</p>
         | 
| 1193 | 
            +
             | 
| 1194 | 
            +
                    <h3>π΄ {restaurant_name}</h3>
         | 
| 1195 | 
            +
                    <p>π [Restaurant Address]<br>
         | 
| 1196 | 
            +
                    π [Restaurant Phone]</p>
         | 
| 1197 | 
            +
                </body>
         | 
| 1198 | 
            +
                </html>
         | 
| 1199 | 
            +
                """
         | 
| 1200 | 
            +
             | 
| 1201 | 
            +
                # Email sending configuration
         | 
| 1202 | 
            +
                sender_email = "yourrestaurant@example.com"
         | 
| 1203 | 
            +
                sender_password = "yourpassword"
         | 
| 1204 | 
            +
                recipient_email = email
         | 
| 1205 | 
            +
             | 
| 1206 | 
            +
                msg = MIMEMultipart()
         | 
| 1207 | 
            +
                msg["From"] = sender_email
         | 
| 1208 | 
            +
                msg["To"] = recipient_email
         | 
| 1209 | 
            +
                msg["Subject"] = subject
         | 
| 1210 | 
            +
             | 
| 1211 | 
            +
                msg.attach(MIMEText(message, "html"))
         | 
| 1212 | 
            +
             | 
| 1213 | 
            +
                try:
         | 
| 1214 | 
            +
                    server = smtplib.SMTP("smtp.gmail.com", 587)  # Change for your email provider
         | 
| 1215 | 
            +
                    server.starttls()
         | 
| 1216 | 
            +
                    server.login(sender_email, sender_password)
         | 
| 1217 | 
            +
                    server.sendmail(sender_email, recipient_email, msg.as_string())
         | 
| 1218 | 
            +
                    server.quit()
         | 
| 1219 | 
            +
                    print(f"Order email sent successfully to {email}")
         | 
| 1220 | 
            +
                except Exception as e:
         | 
| 1221 | 
            +
                    print(f"Error sending email: {str(e)}")
         | 
| 1222 | 
            +
             | 
| 1223 |  | 
| 1224 | 
             
            if __name__ == "__main__":
         | 
| 1225 | 
             
                app.run(debug=True, host="0.0.0.0", port=7860)
         |