From cfd346d5dffeddcfbb5ed66e67c64a70e0f2c728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Tue, 28 Oct 2025 16:13:07 +0100 Subject: [PATCH] wip: integrate with typo3 to fetch product and hotel data --- .ddev/docker-compose.communicate.yaml | 4 ++ .env | 3 +- config/packages/framework.yaml | 7 ++++ config/services.yaml | 4 ++ src/Service/CmsDataService.php | 60 +++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 .ddev/docker-compose.communicate.yaml create mode 100644 src/Service/CmsDataService.php diff --git a/.ddev/docker-compose.communicate.yaml b/.ddev/docker-compose.communicate.yaml new file mode 100644 index 0000000..c6bb46e --- /dev/null +++ b/.ddev/docker-compose.communicate.yaml @@ -0,0 +1,4 @@ +services: + web: + external_links: + - "ddev-router:ep-reisen.ddev.site" diff --git a/.env b/.env index b5c4ed5..2d683e2 100644 --- a/.env +++ b/.env @@ -46,7 +46,8 @@ APP_BPN_IP= APP_BPN_PORT= APP_BPN_DEBUG=false -APP_TRAVEL_INFO_BASE_URL=https://www.ep-reisen.de/reiseinformationen/ +APP_TRAVEL_INFO_BASE_URL="https://www.ep-reisen.de/reiseinformationen/" +APP_CMS_API_BASE_URL="https://www.ep-reisen.de/" # Travel Data Service Configuration APP_TRAVEL_PREFER_REMOTE=false diff --git a/config/packages/framework.yaml b/config/packages/framework.yaml index 28dc777..6e7cd0b 100644 --- a/config/packages/framework.yaml +++ b/config/packages/framework.yaml @@ -18,6 +18,13 @@ framework: php_errors: log: true + http_client: + scoped_clients: + typo3.client: + base_uri: '%env(resolve:APP_CMS_API_BASE_URL)%' + headers: + accept: 'text/json' + when@test: framework: test: true diff --git a/config/services.yaml b/config/services.yaml index b5f933c..0a1540a 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -96,3 +96,7 @@ services: - '@App\Form\Service\ParticipantTransportationDiscountReplacementFieldHandler' - '@App\Form\Service\ParticipantBulkInsuranceFieldHandler' - '@App\Form\Service\ParticipantInsuranceFieldHandler' + + App\Service\CmsDataService: + arguments: + $httpClient: '@typo3.client' diff --git a/src/Service/CmsDataService.php b/src/Service/CmsDataService.php new file mode 100644 index 0000000..18fd708 --- /dev/null +++ b/src/Service/CmsDataService.php @@ -0,0 +1,60 @@ +makeApiCall(static::MODE_PRODUCT, $code); + } + + public function getHotelDetails(string $code): array + { + return $this->makeApiCall(static::MODE_HOTEL, $code); + } + + public function makeApiCall(string $mode, string $code): array + { + if (false === in_array($mode, [self::MODE_PRODUCT, self::MODE_HOTEL])) { + throw new \InvalidArgumentException('Invalid mode provided'); + } + + try { + $request = $this->httpClient->request('GET', '/', [ + 'query' => [ + 'type' => 1720, + 'tx_epproducts_api[code]' => $code, + 'tx_epproducts_api[action]' => $mode, + 'tx_epproducts_api[controller]' => 'Api', + ] + ]); + } catch (ExceptionInterface $e) { + return [ + 'success' => false, + 'message' => $e->getMessage(), + ]; + } + + try { + $data = $request->toArray(); + } catch (ExceptionInterface $e) { + return [ + 'success' => false, + 'message' => $e->getMessage(), + ]; + } + + return $data; + } +}