Add substitution

This commit is contained in:
Michaël Espeche
2014-06-25 16:43:06 +02:00
parent d7a55257d5
commit ed464db6fd
4 changed files with 46 additions and 0 deletions

View File

@@ -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
*/

View File

@@ -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
*/