feat: correct determination of inquiry status and conditional voucher field display
This commit is contained in:
@@ -88,6 +88,24 @@ class Step3Controller extends AbstractController
|
||||
}
|
||||
|
||||
if (false === $inquiryResponse->isInquiryValid()) {
|
||||
// Check if API suggests inquiry booking instead of showing error
|
||||
if ($this->shouldFallbackToInquiryMode($inquiryResponse)) {
|
||||
// Auto-switch to inquiry mode
|
||||
$bookingCreateDto->bookingStatus = 'A';
|
||||
$bookingCreateDto->currentStep = 4;
|
||||
$this->bookingService->saveBookingCreateDto($request, $bookingCreateDto);
|
||||
|
||||
$message = 'Buchung konnte nicht validiert werden.';
|
||||
if (null !== $inquiryResponse->message && '' !== trim($inquiryResponse->message)) {
|
||||
$message = $inquiryResponse->message;
|
||||
}
|
||||
|
||||
$this->addFlash('info', $message);
|
||||
|
||||
return $this->hxRedirect($request, $this->generateUrl('app_booking_create_step_4'));
|
||||
}
|
||||
|
||||
// Not a fallback scenario - show validation error
|
||||
$errorMessage = 'Buchung konnte nicht validiert werden.';
|
||||
if (null !== $inquiryResponse->message && '' !== trim($inquiryResponse->message)) {
|
||||
$errorMessage .= ' '.$inquiryResponse->message;
|
||||
@@ -199,4 +217,31 @@ class Step3Controller extends AbstractController
|
||||
'groupedSelectedRooms' => $groupedSelectedRooms,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if validation failure should trigger inquiry mode fallback.
|
||||
*
|
||||
* Checks if the API response indicates that the booking should proceed as
|
||||
* an inquiry rather than showing an error. This handles scenarios where
|
||||
* availability changes between booking initialization and validation.
|
||||
*
|
||||
* @param \App\BusProNet\Model\BookingResponse $response The API response
|
||||
*
|
||||
* @return bool True if should fallback to inquiry mode, false if should show error
|
||||
*/
|
||||
private function shouldFallbackToInquiryMode(\App\BusProNet\Model\BookingResponse $response): bool
|
||||
{
|
||||
// Check for "nicht möglich" status + inquiry suggestion in message
|
||||
if ('nicht möglich' !== $response->status) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$message = $response->message ?? '';
|
||||
if ('' === $message) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if message suggests inquiry booking (case-insensitive)
|
||||
return 1 === preg_match('/anfrage/i', $message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user