feat: load hotel data locally for sidebar
This commit is contained in:
1 parent
5a47ca6053
commit
d6f2681c61
4 files changed
+101
-29
No files matched your search
@@ -11,6 +11,48 @@ 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 using normalized codes.
|
||||
*
|
||||
* @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);
|
||||
$normalizedHotel = $this->normalizeCode($hotelCode);
|
||||
|
||||
if (null === $normalizedProduct) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$result = $this->getProductDetails($normalizedProduct, $normalizedHotel);
|
||||
|
||||
if (true === isset($result['success']) && false === $result['success']) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $result['hotel']['images'] ?? null;
|
||||
}
|
||||
|
||||
public function getProductDetails(string $productCode, ?string $hotelCode = null): array
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user