fix: don't normalize hotel and product codes when fetching cms data
This commit is contained in:
@@ -135,29 +135,26 @@ class BookingSummaryDataService
|
||||
/**
|
||||
* Fetches hotel display data combining local base hotel data with CMS images.
|
||||
*
|
||||
* Uses normalized codes (first 3 characters, or characters 4-6 for 'SER' codes)
|
||||
* for both local hotel lookup and CMS image retrieval. Local hotel data provides
|
||||
* name and address while CMS provides images as a nice-to-have enhancement.
|
||||
* Local hotel data provides name and address while CMS provides images
|
||||
* as a nice-to-have enhancement.
|
||||
*
|
||||
* Data is cached for 1 hour. This method can be called early in the booking
|
||||
* flow to warm the cache.
|
||||
*/
|
||||
public function getCmsDataForProduct(?string $productCode, ?string $hotelCode): ?array
|
||||
{
|
||||
$normalizedHotelCode = $this->cmsDataService->normalizeCode($hotelCode);
|
||||
|
||||
if (null === $normalizedHotelCode) {
|
||||
if (null === $hotelCode) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$cacheKey = sprintf('cms_data.%s.%s', $normalizedHotelCode, $normalizedHotelCode);
|
||||
$cacheKey = sprintf('cms_data.%s.%s', $productCode, $hotelCode);
|
||||
|
||||
try {
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($productCode, $hotelCode, $normalizedHotelCode) {
|
||||
return $this->cache->get($cacheKey, function (ItemInterface $item) use ($productCode, $hotelCode) {
|
||||
$item->expiresAfter(3600); // 1 hour
|
||||
|
||||
// Fetch base hotel from local BusProNet data
|
||||
$baseHotel = $this->hotelLoader->loadByCode($normalizedHotelCode);
|
||||
$baseHotel = $this->hotelLoader->loadByCode($hotelCode);
|
||||
|
||||
// Fetch CMS images (nice to have)
|
||||
$images = $this->cmsDataService->getProductImages($productCode, $hotelCode);
|
||||
@@ -175,7 +172,6 @@ class BookingSummaryDataService
|
||||
$this->logger->error('Failed to fetch hotel display data', [
|
||||
'product_code' => $productCode,
|
||||
'hotel_code' => $hotelCode,
|
||||
'normalized_hotel_code' => $normalizedHotelCode,
|
||||
'exception' => $e->getMessage(),
|
||||
]);
|
||||
|
||||
|
||||
@@ -11,42 +11,14 @@ class CmsDataService
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes a product or hotel code for CMS lookup.
|
||||
*
|
||||
* Returns the first 3 characters of the code, except for codes
|
||||
* starting with 'SER' where characters 4-6 are returned instead.
|
||||
*/
|
||||
public function normalizeCode(?string $code): ?string
|
||||
{
|
||||
if (null === $code || 3 > strlen($code)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (str_starts_with($code, 'SER') && 6 <= strlen($code)) {
|
||||
return substr($code, 3, 3);
|
||||
}
|
||||
|
||||
return substr($code, 0, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches only the hotel images from the CMS.
|
||||
*
|
||||
* The product code is normalized for CMS lookup while the hotel code
|
||||
* is passed as-is for better matching results.
|
||||
*
|
||||
* @return array<string, mixed>|null The images array or null if unavailable
|
||||
*/
|
||||
public function getProductImages(string $productCode, ?string $hotelCode = null): ?array
|
||||
{
|
||||
$normalizedProduct = $this->normalizeCode($productCode);
|
||||
|
||||
if (null === $normalizedProduct) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $this->getProductDetails($normalizedProduct, $hotelCode);
|
||||
$result = $this->getProductDetails($productCode, $hotelCode);
|
||||
|
||||
if (true === isset($result['success']) && false === $result['success']) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user