From d14316e24947fafd845576a9ad184ed2be2582f1 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Thu, 4 Sep 2025 14:50:39 +0200 Subject: [PATCH] Improve vehicle type determination in xlvask_parser_stor_bil - Integrated `customer_vehicles_o` to validate vehicle type using customer-based data. - Added fallback logic in `selectByPlate` to handle exceptions gracefully. - Enhanced `checkMotorAPI` error handling by returning `false` instead of throwing exceptions. --- .../xlvask/helpers/xlvask_parser_stor_bil.php | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/services/nginx/app/modules/xlvask/helpers/xlvask_parser_stor_bil.php b/services/nginx/app/modules/xlvask/helpers/xlvask_parser_stor_bil.php index 7639df01..97ac1fa2 100644 --- a/services/nginx/app/modules/xlvask/helpers/xlvask_parser_stor_bil.php +++ b/services/nginx/app/modules/xlvask/helpers/xlvask_parser_stor_bil.php @@ -3,6 +3,7 @@ namespace helpers; use classes\motorapi; +use objects\customer_vehicles_o; use objects\products_o; class xlvask_parser_stor_bil extends xlvask_product_parser @@ -197,7 +198,23 @@ class xlvask_parser_stor_bil extends xlvask_product_parser // Check if the vehicle type matches any of the defined vehicle types $isValidVehicleType = false; $productId = null; // Initialize product_id to null + // Check if the vehicle is present in the customer vehicles + $customer_vehicles = new customer_vehicles_o(); + try { + $customer_vehicle = $customer_vehicles->selectByPlate($registrationNumber); + // If the vehicle type is above 0, we can assume it's that exact type + if (isset($customer_vehicle->id) && (int)$customer_vehicle->type->value() > 0) { + $isValidVehicleType = true; // Set to true to indicate a valid vehicle type + $productId = (int)$customer_vehicle->type->value(); + } + } catch (\Exception $e) { + // If the vehicle is not found, we can still proceed with the vehicle type validation + } foreach ( $vehicleTypes as $product_id => $conditions ) { + if ($isValidVehicleType) { + // If we have already determined a valid vehicle type from customer vehicles, skip further checks + break; + } if (isset($conditions['MotorAPI match']) && is_array($conditions['MotorAPI match'])) { if (!$this->checkMotorAPI($registrationNumber, $conditions['MotorAPI match'])) { // If the MotorAPI check fails, skip to the next vehicle type @@ -249,8 +266,8 @@ class xlvask_parser_stor_bil extends xlvask_product_parser try { $motorAPI_result = $motorAPI->getLicensePlateInformation($registrationNumber, false); } catch (\Exception $e) { - - throw new \Exception('Error fetching data from MotorAPI: ' . $e->getMessage()); + return false; + // throw new \Exception('Error fetching data from MotorAPI: ' . $e->getMessage()); } foreach ($motorAPIMatch as $key => $value) { if (isset($motorAPI_result->$key)) {