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)) {