diff --git a/core/lib/Thelia/Core/Template/Loop/Category.php b/core/lib/Thelia/Core/Template/Loop/Category.php index 9ecee9182..e416aa9a1 100644 --- a/core/lib/Thelia/Core/Template/Loop/Category.php +++ b/core/lib/Thelia/Core/Template/Loop/Category.php @@ -214,6 +214,7 @@ class Category extends BaseI18nLoop implements PropelSearchLoopInterface, Search ->set("DESCRIPTION" , $category->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM" , $category->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("PARENT" , $category->getParent()) + ->set("ROOT" , $category->getRoot($category->getId())) ->set("URL" , $category->getUrl($this->locale)) ->set("META_TITLE" , $category->getVirtualColumn('i18n_META_TITLE')) ->set("META_DESCRIPTION" , $category->getVirtualColumn('i18n_META_DESCRIPTION')) diff --git a/core/lib/Thelia/Core/Template/Loop/Folder.php b/core/lib/Thelia/Core/Template/Loop/Folder.php index ee4e0cbbe..73719a775 100644 --- a/core/lib/Thelia/Core/Template/Loop/Folder.php +++ b/core/lib/Thelia/Core/Template/Loop/Folder.php @@ -175,6 +175,7 @@ class Folder extends BaseI18nLoop implements PropelSearchLoopInterface, SearchLo ->set("DESCRIPTION" , $folder->getVirtualColumn('i18n_DESCRIPTION')) ->set("POSTSCRIPTUM" , $folder->getVirtualColumn('i18n_POSTSCRIPTUM')) ->set("PARENT" , $folder->getParent()) + ->set("ROOT" , $folder->getRoot($folder->getId())) ->set("URL" , $folder->getUrl($this->locale)) ->set("META_TITLE" , $folder->getVirtualColumn('i18n_META_TITLE')) ->set("META_DESCRIPTION" , $folder->getVirtualColumn('i18n_META_DESCRIPTION')) diff --git a/core/lib/Thelia/Model/Category.php b/core/lib/Thelia/Model/Category.php index c5ab471a5..1b4582fd0 100644 --- a/core/lib/Thelia/Model/Category.php +++ b/core/lib/Thelia/Model/Category.php @@ -56,6 +56,28 @@ class Category extends BaseCategory return $countProduct; } + /** + * Get the root category + * @param int $categoryId + * @return mixed + */ + public function getRoot($categoryId) + { + + $category = CategoryQuery::create()->findOneById($categoryId); + + if(0 !== $category->getParent()) { + $parentCategory = CategoryQuery::create()->findOneById($category->getParent()); + + if (null !== $parentCategory) { + $categoryId = $this->getRoot($parentCategory->getId()); + } + } + + return $categoryId; + + } + /** * Calculate next position relative to our parent */ diff --git a/core/lib/Thelia/Model/Folder.php b/core/lib/Thelia/Model/Folder.php index e8bc43498..c016aefe2 100644 --- a/core/lib/Thelia/Model/Folder.php +++ b/core/lib/Thelia/Model/Folder.php @@ -55,6 +55,28 @@ class Folder extends BaseFolder } + /** + * Get the root folder + * @param int $folderId + * @return mixed + */ + public function getRoot($folderId) + { + + $folder = FolderQuery::create()->findOneById($folderId); + + if(0 !== $folder->getParent()) { + $parentFolder = FolderQuery::create()->findOneById($folder->getParent()); + + if (null !== $parentFolder) { + $folderId = $this->getRoot($parentFolder->getId()); + } + } + + return $folderId; + + } + /** * Calculate next position relative to our parent */