I am getting one category id in code but it can be the id of either category or subcategory. And by the following code i am able to fetch the parent category chain.
$Jcategories = JCategories::getInstance('Content');
$cat = $Jcategories->get($category->id);
print_r($cat->getParent()); //gives me all the parent details including the main category but it is under [_parent:protected] => JCategoryNode Object( ) so not able to access this.
Otherwise, I will have to write multiple queries to find parent of parent id. Now, I want to know the main parent id of this category. Example the chain is -
SHOES
- Sports
- Running
- basketball
- Casual
- Sneakers
here, if the $category->id
is of running(subcategory)
then I want it's main category i.e. SHOES . If the $category->id
is of Casual(category)
then also, I should get the main category SHOES.