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.
|
* 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)
|
* Local hotel data provides name and address while CMS provides images
|
||||||
* for both local hotel lookup and CMS image retrieval. Local hotel data provides
|
* as a nice-to-have enhancement.
|
||||||
* 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
|
* Data is cached for 1 hour. This method can be called early in the booking
|
||||||
* flow to warm the cache.
|
* flow to warm the cache.
|
||||||
*/
|
*/
|
||||||
public function getCmsDataForProduct(?string $productCode, ?string $hotelCode): ?array
|
public function getCmsDataForProduct(?string $productCode, ?string $hotelCode): ?array
|
||||||
{
|
{
|
||||||
$normalizedHotelCode = $this->cmsDataService->normalizeCode($hotelCode);
|
if (null === $hotelCode) {
|
||||||
|
|
||||||
if (null === $normalizedHotelCode) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$cacheKey = sprintf('cms_data.%s.%s', $normalizedHotelCode, $normalizedHotelCode);
|
$cacheKey = sprintf('cms_data.%s.%s', $productCode, $hotelCode);
|
||||||
|
|
||||||
try {
|
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
|
$item->expiresAfter(3600); // 1 hour
|
||||||
|
|
||||||
// Fetch base hotel from local BusProNet data
|
// Fetch base hotel from local BusProNet data
|
||||||
$baseHotel = $this->hotelLoader->loadByCode($normalizedHotelCode);
|
$baseHotel = $this->hotelLoader->loadByCode($hotelCode);
|
||||||
|
|
||||||
// Fetch CMS images (nice to have)
|
// Fetch CMS images (nice to have)
|
||||||
$images = $this->cmsDataService->getProductImages($productCode, $hotelCode);
|
$images = $this->cmsDataService->getProductImages($productCode, $hotelCode);
|
||||||
@@ -175,7 +172,6 @@ class BookingSummaryDataService
|
|||||||
$this->logger->error('Failed to fetch hotel display data', [
|
$this->logger->error('Failed to fetch hotel display data', [
|
||||||
'product_code' => $productCode,
|
'product_code' => $productCode,
|
||||||
'hotel_code' => $hotelCode,
|
'hotel_code' => $hotelCode,
|
||||||
'normalized_hotel_code' => $normalizedHotelCode,
|
|
||||||
'exception' => $e->getMessage(),
|
'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.
|
* 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
|
* @return array<string, mixed>|null The images array or null if unavailable
|
||||||
*/
|
*/
|
||||||
public function getProductImages(string $productCode, ?string $hotelCode = null): ?array
|
public function getProductImages(string $productCode, ?string $hotelCode = null): ?array
|
||||||
{
|
{
|
||||||
$normalizedProduct = $this->normalizeCode($productCode);
|
$result = $this->getProductDetails($productCode, $hotelCode);
|
||||||
|
|
||||||
if (null === $normalizedProduct) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$result = $this->getProductDetails($normalizedProduct, $hotelCode);
|
|
||||||
|
|
||||||
if (true === isset($result['success']) && false === $result['success']) {
|
if (true === isset($result['success']) && false === $result['success']) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user