From 6172cbcbd8999fa77c476f6b313080e07017f705 Mon Sep 17 00:00:00 2001 From: MaxBuhe01 Date: Wed, 19 Mar 2025 08:39:10 +0100 Subject: [PATCH] [Fixed] over-engineered Getter-methods - the methods would semi-automatic search and set/ save params - I removed those and set it back to its base functionality: -- saving happens ONLY at the save() function if triggered by the user in the admin-frontend -- only one Getter who checks for a value in the DB ? give the value : no value given yet --- .../Admin/GA4AdminUserInterface_main.php | 14 ++--- Application/Model/ManagerHandler.php | 56 ++----------------- Modules/Core/ViewConfig.php | 2 +- 3 files changed, 12 insertions(+), 60 deletions(-) diff --git a/Application/Controller/Admin/GA4AdminUserInterface_main.php b/Application/Controller/Admin/GA4AdminUserInterface_main.php index e0701de..2782469 100644 --- a/Application/Controller/Admin/GA4AdminUserInterface_main.php +++ b/Application/Controller/Admin/GA4AdminUserInterface_main.php @@ -21,7 +21,7 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle $this->addTplParam('d3ViewObject', $this); $this->addTplParam('d3ViewConfObject', Registry::get(ViewConfig::class)); $this->addTplParam('d3ManagerTypeArray', oxNew(ManagerTypes::class)->getManagerList()); - $this->addTplParam('d3CurrentCMP', oxNew(ManagerHandler::class)->getCurrManager()); + $this->addTplParam('d3CurrentCMP', oxNew(ManagerHandler::class)->getActManager()); return $return; } @@ -41,10 +41,10 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle '_blEnableUsercentricsConsentModeApi', ]; - foreach ($aCheckBoxParams as $checkBoxName) { - if (isset($aParams['bool'][$checkBoxName])) { + foreach ($aCheckBoxParams as $checkBoxName){ + if (isset($aParams['bool'][$checkBoxName])){ $aParams['bool'][$checkBoxName] = true; - } else { + }else{ $aParams['bool'][$checkBoxName] = false; } } @@ -60,8 +60,8 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle { $oConfig = Registry::getConfig(); foreach ($aParams as $sConfigType => $aConfigParams) { - foreach ($aConfigParams as $sParamName => $sParamValue) { - if ($this->d3GetModuleConfigParam($sParamName) !== $sParamValue) { + foreach ($aConfigParams as $sParamName => $sParamValue){ + if($this->d3GetModuleConfigParam($sParamName) !== $sParamValue){ $oConfig->saveShopConfVar( $sConfigType, Constants::OXID_MODULE_ID.$sParamName, @@ -82,4 +82,4 @@ class GA4AdminUserInterface_main extends \OxidEsales\Eshop\Application\Controlle { return Registry::get(ViewConfig::class)->d3GetModuleConfigParam($configParamName); } -} +} \ No newline at end of file diff --git a/Application/Model/ManagerHandler.php b/Application/Model/ManagerHandler.php index 4c5f1e7..6e3d02d 100644 --- a/Application/Model/ManagerHandler.php +++ b/Application/Model/ManagerHandler.php @@ -7,41 +7,11 @@ use OxidEsales\Eshop\Core\ViewConfig; class ManagerHandler { - /** - * Gets current chosen Manager - * - * @return string - */ - public function getCurrManager(): string - { - /** @var ManagerTypes $oManagerTypes */ - $oManagerTypes = oxNew(ManagerTypes::class); - - /** @var ViewConfig|\D3\GoogleAnalytics4\Modules\Core\ViewConfig $oViewConfig */ - $oViewConfig = oxNew(ViewConfig::class); - - $aManagerList = $oManagerTypes->getManagerList(); - - if ($this->getModuleSettingExplicitManagerSelectValue()) { - return $this->getExplicitManager(); - } - - foreach ($aManagerList as $shopModuleId => $publicCMPName) { - if ($oViewConfig->d3IsModuleActive($shopModuleId)) { - $this->d3SaveShopConfVar($shopModuleId); - return $shopModuleId; - } - } - - return ""; - } - /** * @param string $sParam * @return void */ - public function d3SaveShopConfVar(string $sParam) - { + public function d3SaveShopConfVar(string $sParam){ Registry::getConfig()->saveShopConfVar( 'select', Constants::OXID_MODULE_ID."_HAS_STD_MANAGER", @@ -54,26 +24,8 @@ class ManagerHandler /** * @return string */ - public function getModuleSettingExplicitManagerSelectValue(): string + public function getActManager() :string { - return Registry::get(ViewConfig::class)->d3GetModuleConfigParam('_HAS_STD_MANAGER') ?: ""; + return Registry::get(ViewConfig::class)->d3GetModuleConfigParam('_HAS_STD_MANAGER')?:""; } - - /** - * @return string - */ - public function getExplicitManager(): string - { - $sPotentialManagerName = $this->getModuleSettingExplicitManagerSelectValue(); - - /** @var ManagerTypes $oManagerTypes */ - $oManagerTypes = oxNew(ManagerTypes::class); - $sCMPName = $oManagerTypes->isManagerInList($sPotentialManagerName) - ? $sPotentialManagerName - : "NONE"; - - $this->d3SaveShopConfVar($sCMPName); - - return $sCMPName; - } -} +} \ No newline at end of file diff --git a/Modules/Core/ViewConfig.php b/Modules/Core/ViewConfig.php index 9b07e56..be32ccb 100644 --- a/Modules/Core/ViewConfig.php +++ b/Modules/Core/ViewConfig.php @@ -54,7 +54,7 @@ class ViewConfig extends ViewConfig_parent if ($this->sCookieManagerType === null) { /** @var ManagerHandler $oManagerHandler */ $oManagerHandler = oxNew(ManagerHandler::class); - $this->sCookieManagerType = $oManagerHandler->getCurrManager(); + $this->sCookieManagerType = $oManagerHandler->getActManager(); } }