fix: properly resolve myep urls per site by overriding in typoscript

This commit is contained in:
Björn Fromme
2026-03-23 18:17:06 +01:00
parent a12b7387b9
commit 50eba1e5e3
3 changed files with 41 additions and 19 deletions
@@ -5,35 +5,51 @@ namespace EP\EpProducts\Service;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManager;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
class MyEpUrlResolverService implements SingletonInterface
{
/** @var string */
private $productionUrl;
/** @var string */
private $stagingUrl;
public function __construct()
{
$config = GeneralUtility::makeInstance(ExtensionConfiguration::class);
$this->productionUrl = (string) $config->get('ep_products', 'myEpUrl');
$this->stagingUrl = (string) $config->get('ep_products', 'myEpStagingUrl');
}
/**
* Returns the staging URL when the `ep_myep_staging` cookie is set and a staging URL
* is configured. Falls back to the production URL in all other cases.
*
* Both URLs are read from the extension configuration (Extension Manager),
* bypassing TypoScript to avoid constant-override collisions.
*/
public function resolve(): string
{
if ('' !== $this->stagingUrl && !empty($_COOKIE['ep_myep_staging'])) {
return $this->stagingUrl;
$config = GeneralUtility::makeInstance(ExtensionConfiguration::class);
$settings = $this->getTypoScriptSettings();
$productionUrl = $this->resolveUrlSetting(
$settings,
'myEpUrl',
(string) $config->get('ep_products', 'myEpUrl')
);
$stagingUrl = $this->resolveUrlSetting(
$settings,
'myEpStagingUrl',
(string) $config->get('ep_products', 'myEpStagingUrl')
);
if ('' !== $stagingUrl && !empty($_COOKIE['ep_myep_staging'])) {
return $stagingUrl;
}
return $this->productionUrl;
return $productionUrl;
}
private function getTypoScriptSettings(): array
{
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
$settings = GeneralUtility::removeDotsFromTS(
$configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT)
);
return $settings['plugin']['tx_epproducts']['settings'] ?? [];
}
private function resolveUrlSetting(array $settings, string $key, string $fallback): string
{
$value = trim((string) ($settings[$key] ?? ''));
return $value !== '' ? $value : $fallback;
}
}
@@ -54,6 +54,10 @@ plugin.tx_epproducts {
searchLogIgnoreIps =
# cat=epproducts/140/120; type=string; label=Concept UIDs to trigger inquiry form on product detail page (CSV)
groupInquiryFormConceptUids =
# cat=epproducts/140/130; type=string; label=Per-site MyE&P booking URL override
myEpUrl =
# cat=epproducts/140/140; type=string; label=Per-site MyE&P staging booking URL override
myEpStagingUrl =
}
persistence {
# cat=epproducts/100/100; type=string; label=Default storage PID
@@ -38,6 +38,8 @@ plugin.tx_epproducts {
noInfoConceptUids = {$plugin.tx_epproducts.settings.noInfoConceptUids}
priceTableRoomTypes = {$plugin.tx_epproducts.settings.priceTableRoomTypes}
searchLogIgnoreIps = {$plugin.tx_epproducts.settings.searchLogIgnoreIps}
myEpUrl = {$plugin.tx_epproducts.settings.myEpUrl}
myEpStagingUrl = {$plugin.tx_epproducts.settings.myEpStagingUrl}
groupsPageUid = {$plugin.tx_eptheme.settings.groupsPageUid}
travelInfoPageUid = {$plugin.tx_eptheme.settings.travelInfoPageUid}
groupsContactFormPageUid = {$plugin.tx_eptheme.settings.groupsContactFormPageUid}