From e563cd22c1d12cb6bdb8e1ab68a51d3092bcad29 Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Wed, 17 Jul 2024 18:03:26 +0200 Subject: [PATCH 1/2] fix #279: add class FeUserMarkerApi --- Classes/Api/FeUserMarkerApi.php | 143 ++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 Classes/Api/FeUserMarkerApi.php diff --git a/Classes/Api/FeUserMarkerApi.php b/Classes/Api/FeUserMarkerApi.php new file mode 100644 index 000000000..a74e24227 --- /dev/null +++ b/Classes/Api/FeUserMarkerApi.php @@ -0,0 +1,143 @@ + + * + * @package TYPO3 + * @subpackage tt_products + */ +use TYPO3\CMS\Core\SingletonInterface; +use JambageCom\Div2007\Api\Frontend; +use TYPO3\CMS\Core\Context\Context; +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Core\Utility\MathUtility; + +class FeUserMarkerApi implements SingletonInterface +{ + public function getWrappedSubpartArray( + $modelObj, + $viewTagArray, + array &$subpartArray, + array &$wrappedSubpartArray + ): void { + // debug ($viewTagArray, 'getWrappedSubpartArray $viewTagArray'); + $api = + GeneralUtility::makeInstance(Frontend::class); + $context = GeneralUtility::makeInstance(Context::class); + + $typoScriptFrontendController = $api->getTypoScriptFrontendController(); + $marker = 'FE_GROUP'; + $markerLogin = 'LOGIN'; + $markerNologin = 'NOLOGIN'; + foreach ($viewTagArray as $tag => $value) { + if (strpos($tag, $marker . '_') === 0) { + $tagPart1 = substr($tag, strlen($marker . '_')); + $offset = strpos($tagPart1, '_TEMPLATE'); + if ($offset > 0) { + $groupNumber = substr($tagPart1, 0, $offset); + + if (MathUtility::canBeInterpretedAsInteger($groupNumber)) { + $comparatorNumber = $groupNumber; + if (!$comparatorNumber) { + $comparatorNumber = -1; // Also a logged in Front End User has group 0! + } + + if ( + GeneralUtility::inList( + implode( + ',', + GeneralUtility::makeInstance( + Context::class + )->getPropertyFromAspect('frontend.user', 'groupIds')), + $comparatorNumber + ) + ) { + $wrappedSubpartArray['###FE_GROUP_' . $groupNumber . '_TEMPLATE###'] = ['', '']; + } else { + $subpartArray['###FE_GROUP_' . $groupNumber . '_TEMPLATE###'] = ''; + } + } + } + } elseif (strpos($tag, $markerLogin . '_') === 0) { + if ( + $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') + ) { + $wrappedSubpartArray['###LOGIN_TEMPLATE###'] = ['', '']; + } else { + $subpartArray['###LOGIN_TEMPLATE###'] = ''; + } + } elseif (strpos($tag, $markerNologin . '_') === 0) { + if ( + $context->getPropertyFromAspect('frontend.user', 'isLoggedIn') + ) { + $subpartArray['###NOLOGIN_TEMPLATE###'] = ''; + } else { + $wrappedSubpartArray['###NOLOGIN_TEMPLATE###'] = ['', '']; + } + } + } + + if ( + isset($viewTagArray['FE_CONDITION1_TRUE_TEMPLATE']) || + isset($viewTagArray['FE_CONDITION1_FALSE_TEMPLATE']) + ) { + if ( + method_exists($modelObj, 'getCondition') && + $modelObj->getCondition() || + method_exists($modelObj, 'getConditionRecord') && + !$modelObj->getConditionRecord() + ) { + $wrappedSubpartArray['###FE_CONDITION1_TRUE_TEMPLATE###'] = ['', '']; + $subpartArray['###FE_CONDITION1_FALSE_TEMPLATE###'] = ''; + } else { + $wrappedSubpartArray['###FE_CONDITION1_FALSE_TEMPLATE###'] = ['', '']; + $subpartArray['###FE_CONDITION1_TRUE_TEMPLATE###'] = ''; + } + } + + if (isset($viewTagArray['FEUSER_HAS_DISCOUNT'])) { + $discountApi = GeneralUtility::makeInstance(DiscountApi::class); + $discountArray = $discountApi->getFeuserDiscounts(); + $hasDiscount = is_array($discountArray) && (count($discountArray) > 0); + + if ( + $hasDiscount + ) { + $wrappedSubpartArray['###FEUSER_HAS_DISCOUNT###'] = ['', '']; + $subpartArray['###FEUSER_HAS_NO_DISCOUNT###'] = ''; + } else { + $subpartArray['###FEUSER_HAS_DISCOUNT###'] = ''; + $wrappedSubpartArray['###FEUSER_HAS_NO_DISCOUNT###'] = ['', '']; + } + } + } + + public function getGlobalMarkerArray( + &$markerArray + ): void { + $discountApi = GeneralUtility::makeInstance(DiscountApi::class); + $discountValue = $discountApi->getMaximumFeuserDiscount(); + $markerArray['###FEUSER_TOTAL_DISCOUNT###'] = $discountValue; + $markerArray['###FE_USER_TT_PRODUCTS_DISCOUNT###'] = $discountValue; // deprecated -> 2025 + } +} From afcb2fb2a47b676761b82534ce92bc8e4296b7dc Mon Sep 17 00:00:00 2001 From: Franz Holzinger Date: Wed, 17 Jul 2024 18:35:16 +0200 Subject: [PATCH 2/2] - --- Classes/Api/FeUserMarkerApi.php | 1 - 1 file changed, 1 deletion(-) diff --git a/Classes/Api/FeUserMarkerApi.php b/Classes/Api/FeUserMarkerApi.php index a74e24227..659e46329 100644 --- a/Classes/Api/FeUserMarkerApi.php +++ b/Classes/Api/FeUserMarkerApi.php @@ -40,7 +40,6 @@ public function getWrappedSubpartArray( array &$subpartArray, array &$wrappedSubpartArray ): void { - // debug ($viewTagArray, 'getWrappedSubpartArray $viewTagArray'); $api = GeneralUtility::makeInstance(Frontend::class); $context = GeneralUtility::makeInstance(Context::class);