From 10dae93cbafede8e5d95d06292856ba7cc4bf37b Mon Sep 17 00:00:00 2001 From: Steve Tentrop Date: Tue, 10 Aug 2021 09:22:32 +0200 Subject: [PATCH 1/2] restore old values --- src/Services/CategoryService.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Services/CategoryService.php b/src/Services/CategoryService.php index 4891a0133..6a1962c82 100644 --- a/src/Services/CategoryService.php +++ b/src/Services/CategoryService.php @@ -591,9 +591,14 @@ public function getNavigationList($type = CategoryType::ALL, string $lang = null * @param bool $filterCategories Filter categories * @return array The parents of the category */ - public function getHierarchy(int $catID = 0, bool $bottomUp = false, bool $filterCategories = false): array + public function getHierarchy(int $catID = 0, bool $bottomUp = false, bool $filterCategories = false, $restore = false): array { if ($catID > 0) { + + if ($restore) { + $oldCategory = $this->currentCategory; + $oldCategoryTree = $this->currentCategoryTree; + } $this->setCurrentCategoryID($catID); } @@ -620,6 +625,11 @@ public function getHierarchy(int $catID = 0, bool $bottomUp = false, bool $filte array_push($hierarchy, $this->currentItem['texts'][$lang]); } + if ($restore) { + $this->currentCategory = $oldCategory; + $this->currentCategoryTree = $oldCategoryTree; + } + return $hierarchy; } @@ -678,7 +688,7 @@ public function isHidden($categoryId) return false; } $isHidden = false; - foreach ($this->getHierarchy($categoryId) as $category) { + foreach ($this->getHierarchy($categoryId, false, false, true) as $category) { if ($category->right === 'customer') { $isHidden = true; break; From ad577a59ffe089a31ee6c4c67fa261215a93cb4c Mon Sep 17 00:00:00 2001 From: Steve Tentrop Date: Tue, 10 Aug 2021 13:07:59 +0200 Subject: [PATCH 2/2] add documntation --- src/Services/CategoryService.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Services/CategoryService.php b/src/Services/CategoryService.php index 6a1962c82..2917fdc68 100644 --- a/src/Services/CategoryService.php +++ b/src/Services/CategoryService.php @@ -589,13 +589,14 @@ public function getNavigationList($type = CategoryType::ALL, string $lang = null * @param int $catID The category id to get the parents for or 0 to use current category * @param bool $bottomUp Set true to order result from bottom (deepest category) to top (= level 1) * @param bool $filterCategories Filter categories + * @param bool $restoreOldValues Restore old category data and category tree after the method call. * @return array The parents of the category */ - public function getHierarchy(int $catID = 0, bool $bottomUp = false, bool $filterCategories = false, $restore = false): array + public function getHierarchy(int $catID = 0, bool $bottomUp = false, bool $filterCategories = false, $restoreOldValues = false): array { if ($catID > 0) { - if ($restore) { + if ($restoreOldValues) { $oldCategory = $this->currentCategory; $oldCategoryTree = $this->currentCategoryTree; } @@ -625,7 +626,7 @@ public function getHierarchy(int $catID = 0, bool $bottomUp = false, bool $filte array_push($hierarchy, $this->currentItem['texts'][$lang]); } - if ($restore) { + if ($restoreOldValues) { $this->currentCategory = $oldCategory; $this->currentCategoryTree = $oldCategoryTree; }