Iam using this extension for displaying left menu category sidebar https://github.com/Sebwite/magento2-category-sidebar. For main categories its working fine , i enabled flat category as well but its not showing sub categories .this function returns empty array $childCategories = $this->getSubcategories($category);
public function getChildCategoryView($category, $html = '', $level = 1)
{
// Check if category has children
if ( $category->hasChildren() )
{
$childCategories = $this->getSubcategories($category);
if ( count($childCategories) > 0 )
{
$html .= '<ul class="o-list o-list--unstyled">';
// Loop through children categories
foreach ( $childCategories as $childCategory )
{
$html .= '<li class="level' . $level . ($this->isActive($childCategory) ? ' active' : '') . '">';
$html .= '<a href="' . $this->getCategoryUrl($childCategory) . '" title="' . $childCategory->getName() . '" class="' . ($this->isActive($childCategory) ? 'is-active' : '') . '">' . $childCategory->getName() . '</a>';
if ( $childCategory->hasChildren() )
{
if ( $this->isActive($childCategory) )
{
$html .= '<span class="expanded"><i class="fa fa-minus"></i></span>';
}
else
{
$html .= '<span class="expand"><i class="fa fa-plus"></i></span>';
}
}
if ( $childCategory->hasChildren() )
{
$html .= $this->getChildCategoryView($childCategory, '', ($level + 1));
}
$html .= '</li>';
}
$html .= '</ul>';
}
}
return $html;
}
/**
* Retrieve subcategories
*
* @param $category
*
* @return array
*/
public function getSubcategories($category)
{
if ( $this->categoryFlatConfig->isFlatEnabled() && $category->getUseFlatResource() )
{
return (array)$category->getChildrenNodes();
}
return $category->getChildren();
}
can anyone help me
Best Answer
you have to just create block and inside template file call function,
Inside phtml file,