Spaces:
				
			
			
	
			
			
		Build error
		
	
	
	
			
			
	
	
	
	
		
		
		Build error
		
	Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -256,21 +256,21 @@ def get_addons(): | |
| 256 | 
             
                except Exception as e:
         | 
| 257 | 
             
                    print(f"Error fetching add-ons: {e}")
         | 
| 258 | 
             
                    return jsonify({"success": False, "error": "Unable to fetch add-ons. Please try again later."})
         | 
| 259 | 
            -
            @app.route("/cart/update_quantity", methods=["POST"])
         | 
| 260 | 
             
            def update_quantity():
         | 
| 261 | 
            -
                data = request.json
         | 
| 262 | 
            -
                 | 
| 263 | 
            -
             | 
| 264 | 
            -
                 | 
| 265 | 
            -
             | 
| 266 | 
            -
             | 
|  | |
|  | |
| 267 |  | 
|  | |
| 268 | 
             
                if not email or not item_name or quantity is None:
         | 
| 269 | 
             
                    return jsonify({"success": False, "error": "Email, item name, and quantity are required."}), 400
         | 
| 270 |  | 
| 271 | 
            -
                # The rest of the logic remains the same
         | 
| 272 | 
            -
             | 
| 273 | 
            -
             | 
| 274 | 
             
                try:
         | 
| 275 | 
             
                    # Query the cart item in Salesforce
         | 
| 276 | 
             
                    cart_items = sf.query(
         | 
| @@ -289,9 +289,12 @@ def update_quantity(): | |
| 289 | 
             
                    # Calculate the add-ons price
         | 
| 290 | 
             
                    addons_price = 0
         | 
| 291 | 
             
                    if addons_string and addons_string != "None":
         | 
| 292 | 
            -
                         | 
| 293 | 
            -
                             | 
| 294 | 
            -
             | 
|  | |
|  | |
|  | |
| 295 |  | 
| 296 | 
             
                    # Calculate the new price
         | 
| 297 | 
             
                    new_price = (base_price + addons_price) * quantity
         | 
| @@ -307,7 +310,7 @@ def update_quantity(): | |
| 307 | 
             
                    print(f"Error updating quantity: {str(e)}")
         | 
| 308 | 
             
                    return jsonify({"success": False, "error": str(e)}), 500
         | 
| 309 |  | 
| 310 | 
            -
             | 
| 311 |  | 
| 312 | 
             
            @app.route("/checkout", methods=["POST"])
         | 
| 313 | 
             
            def checkout():
         | 
|  | |
| 256 | 
             
                except Exception as e:
         | 
| 257 | 
             
                    print(f"Error fetching add-ons: {e}")
         | 
| 258 | 
             
                    return jsonify({"success": False, "error": "Unable to fetch add-ons. Please try again later."})
         | 
| 259 | 
            +
                    @app.route("/cart/update_quantity", methods=["POST"])
         | 
| 260 | 
             
            def update_quantity():
         | 
| 261 | 
            +
                data = request.json  # Extract JSON data from the request
         | 
| 262 | 
            +
                email = data.get('email')
         | 
| 263 | 
            +
                item_name = data.get('item_name')
         | 
| 264 | 
            +
                try:
         | 
| 265 | 
            +
                    # Convert quantity to an integer
         | 
| 266 | 
            +
                    quantity = int(data.get('quantity'))
         | 
| 267 | 
            +
                except (ValueError, TypeError):
         | 
| 268 | 
            +
                    return jsonify({"success": False, "error": "Invalid quantity provided."}), 400
         | 
| 269 |  | 
| 270 | 
            +
                # Validate inputs
         | 
| 271 | 
             
                if not email or not item_name or quantity is None:
         | 
| 272 | 
             
                    return jsonify({"success": False, "error": "Email, item name, and quantity are required."}), 400
         | 
| 273 |  | 
|  | |
|  | |
|  | |
| 274 | 
             
                try:
         | 
| 275 | 
             
                    # Query the cart item in Salesforce
         | 
| 276 | 
             
                    cart_items = sf.query(
         | 
|  | |
| 289 | 
             
                    # Calculate the add-ons price
         | 
| 290 | 
             
                    addons_price = 0
         | 
| 291 | 
             
                    if addons_string and addons_string != "None":
         | 
| 292 | 
            +
                        try:
         | 
| 293 | 
            +
                            addons_price = sum(
         | 
| 294 | 
            +
                                [float(price.strip()) for price in addons_string.split("$")[1::2] if price.strip().replace('.', '', 1).isdigit()]
         | 
| 295 | 
            +
                            )
         | 
| 296 | 
            +
                        except ValueError:
         | 
| 297 | 
            +
                            addons_price = 0  # Default to 0 if parsing fails
         | 
| 298 |  | 
| 299 | 
             
                    # Calculate the new price
         | 
| 300 | 
             
                    new_price = (base_price + addons_price) * quantity
         | 
|  | |
| 310 | 
             
                    print(f"Error updating quantity: {str(e)}")
         | 
| 311 | 
             
                    return jsonify({"success": False, "error": str(e)}), 500
         | 
| 312 |  | 
| 313 | 
            +
             | 
| 314 |  | 
| 315 | 
             
            @app.route("/checkout", methods=["POST"])
         | 
| 316 | 
             
            def checkout():
         | 
