I want to get the category name of Parent Category as well as Child Category. For this, I am checking if Category == Parent Category and storing Category name into an array. And If Category is a Sub or Child category I want to store its name as ParentCategoryName / ChildCategoryName.
For example: If Parent Category = Engine and Sub Category = Engine Pump so Category Name = Engine / Engine Pump
Below is my code:
foreach ($categories as $category){
$thAttribute = $category->getThNewAttribute();
if(($category->getParentId($category))==2){
$categoryName[$category->getThNewAttribute()] = $category->getName();
}else{
$categoryName[$category->getThNewAttribute()] = $category->getParentCategory($category)->getName()."/".$category->getName();
}
}
I am getting the correct Category Name for Parent Category but for Sub or Child Category I am getting below error.
No such entity with id = 0
Which step I am doing wrong?