From 7da688af2b070d44f1a9de90a8fba328bcbf2caf Mon Sep 17 00:00:00 2001
From: Henning <leutz@pcsg.de>
Date: Thu, 20 Mar 2025 13:18:44 +0100
Subject: [PATCH] fix: update profile bar categories logic

Updated the logic for the "Go to profile" button in the profile bar categories. Now it checks for
the 'showToProfile' setting and if the user category exists before inserting the 'toprofile'
button. Also, exceptions are now properly being caught and logged.

Related: quiqqer/order-guestorder#10
---
 .../profile/getProfileBarCategories.php       | 42 ++++++++++---------
 1 file changed, 23 insertions(+), 19 deletions(-)

diff --git a/ajax/frontend/profile/getProfileBarCategories.php b/ajax/frontend/profile/getProfileBarCategories.php
index 68ca283..586fa5b 100644
--- a/ajax/frontend/profile/getProfileBarCategories.php
+++ b/ajax/frontend/profile/getProfileBarCategories.php
@@ -32,26 +32,30 @@ function () {
         $categories = utils::setUrlsToCategorySettings($categories);
 
         // Check if "go to profile" button is added
-        try {
-            $profileBarSettings = Handler::getInstance()->getProfileBarSettings();
-
-            if (!empty($profileBarSettings['showToProfile']) && !empty($categories['user'])) {
-                \array_unshift($categories['user']['items'], [
-                    'name' => 'toprofile',
-                    'title' => QUI::getLocale()->get(
-                        'quiqqer/frontend-users',
-                        'profilebar.to_profile'
-                    ),
-                    'index' => 0,
-                    'icon' => 'fa fa-user',
-                    'control' => false,
-                    'showinprofilebar' => true,
-                    'content' => false,
-                    'url' => $ProfileSite->getUrlRewritten()
-                ]);
+        $User = QUI::getUserBySession();
+
+        if (QUI::getUsers()->isUser($User) && !($User instanceof QUI\Users\Nobody)) {
+            try {
+                $profileBarSettings = Handler::getInstance()->getProfileBarSettings();
+
+                if (!empty($profileBarSettings['showToProfile']) && !empty($categories['user'])) {
+                    \array_unshift($categories['user']['items'], [
+                        'name' => 'toprofile',
+                        'title' => QUI::getLocale()->get(
+                            'quiqqer/frontend-users',
+                            'profilebar.to_profile'
+                        ),
+                        'index' => 0,
+                        'icon' => 'fa fa-user',
+                        'control' => false,
+                        'showinprofilebar' => true,
+                        'content' => false,
+                        'url' => $ProfileSite->getUrlRewritten()
+                    ]);
+                }
+            } catch (\Exception $Exception) {
+                QUI\System\Log::writeException($Exception);
             }
-        } catch (\Exception $Exception) {
-            QUI\System\Log::writeException($Exception);
         }
 
         return $categories;
-- 
GitLab