Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -217,22 +217,43 @@ def cart(): | |
| 217 | 
             
                        WHERE Customer_Email__c = '{email}'
         | 
| 218 | 
             
                    """)
         | 
| 219 | 
             
                    cart_items = result.get("records", [])
         | 
|  | |
| 220 | 
             
                    # Subtotal should be the sum of all item prices in the cart
         | 
| 221 | 
             
                    subtotal = sum(item['Price__c'] for item in cart_items)
         | 
|  | |
|  | |
| 222 | 
             
                    customer_result = sf.query(f"""
         | 
| 223 | 
             
                        SELECT Reward_Points__c 
         | 
| 224 | 
             
                        FROM Customer_Login__c
         | 
| 225 | 
             
                        WHERE Email__c = '{email}'
         | 
| 226 | 
             
                    """)
         | 
| 227 | 
            -
                    
         | 
| 228 | 
            -
                    # Extract the reward points (default to 0 if not found)
         | 
| 229 | 
             
                    reward_points = customer_result['records'][0].get('Reward_Points__c', 0) if customer_result['records'] else 0
         | 
| 230 | 
            -
                    return render_template("cart.html", cart_items=cart_items, subtotal=subtotal, reward_points=reward_points, customer_email=email)
         | 
| 231 |  | 
| 232 | 
            -
                    
         | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 233 | 
             
                except Exception as e:
         | 
| 234 | 
             
                    print(f"Error fetching cart items: {e}")
         | 
| 235 | 
            -
                    return render_template("cart.html", cart_items=[], subtotal=0)
         | 
|  | |
| 236 |  | 
| 237 |  | 
| 238 | 
             
            @app.route('/cart/add', methods=['POST'])
         | 
|  | |
| 217 | 
             
                        WHERE Customer_Email__c = '{email}'
         | 
| 218 | 
             
                    """)
         | 
| 219 | 
             
                    cart_items = result.get("records", [])
         | 
| 220 | 
            +
             | 
| 221 | 
             
                    # Subtotal should be the sum of all item prices in the cart
         | 
| 222 | 
             
                    subtotal = sum(item['Price__c'] for item in cart_items)
         | 
| 223 | 
            +
             | 
| 224 | 
            +
                    # Fetch reward points
         | 
| 225 | 
             
                    customer_result = sf.query(f"""
         | 
| 226 | 
             
                        SELECT Reward_Points__c 
         | 
| 227 | 
             
                        FROM Customer_Login__c
         | 
| 228 | 
             
                        WHERE Email__c = '{email}'
         | 
| 229 | 
             
                    """)
         | 
|  | |
|  | |
| 230 | 
             
                    reward_points = customer_result['records'][0].get('Reward_Points__c', 0) if customer_result['records'] else 0
         | 
|  | |
| 231 |  | 
| 232 | 
            +
                    # Fetch coupons for the user
         | 
| 233 | 
            +
                    coupon_result = sf.query(f"""
         | 
| 234 | 
            +
                        SELECT Coupon_Code__c FROM Referral_Coupon__c WHERE Referral_Email__c = '{email}'
         | 
| 235 | 
            +
                    """)
         | 
| 236 | 
            +
             | 
| 237 | 
            +
                    # Extract and split coupons into a list
         | 
| 238 | 
            +
                    if coupon_result["records"]:
         | 
| 239 | 
            +
                        raw_coupons = coupon_result["records"][0].get("Coupon_Code__c", "")
         | 
| 240 | 
            +
                        coupons = raw_coupons.split("\n") if raw_coupons else []
         | 
| 241 | 
            +
                    else:
         | 
| 242 | 
            +
                        coupons = []
         | 
| 243 | 
            +
             | 
| 244 | 
            +
                    return render_template(
         | 
| 245 | 
            +
                        "cart.html",
         | 
| 246 | 
            +
                        cart_items=cart_items,
         | 
| 247 | 
            +
                        subtotal=subtotal,
         | 
| 248 | 
            +
                        reward_points=reward_points,
         | 
| 249 | 
            +
                        customer_email=email,
         | 
| 250 | 
            +
                        coupons=coupons  # Send coupons to template
         | 
| 251 | 
            +
                    )
         | 
| 252 | 
            +
             | 
| 253 | 
             
                except Exception as e:
         | 
| 254 | 
             
                    print(f"Error fetching cart items: {e}")
         | 
| 255 | 
            +
                    return render_template("cart.html", cart_items=[], subtotal=0, reward_points=0, coupons=[])
         | 
| 256 | 
            +
             | 
| 257 |  | 
| 258 |  | 
| 259 | 
             
            @app.route('/cart/add', methods=['POST'])
         |