I am working with display all categories on a custom page, either it is enabled or disabled.
When I try to get child categories with "getChildrenCategories()", but it is returning only enabled child categories it is not returning the disabled child categories. I need both types of child categories.
How can I get the all child categories which are disabled/enabled?
please check the code as below.
protected $_categoryFactory;
public function __construct(
\Magento\Backend\App\Action\Context $context,
\Magento\Catalog\Model\CategoryFactory $categoryFactory
){
parent::__construct($context);
$this->_categoryFactory = $categoryFactory;
}
public function getAllChildCategories($categoryId)
{
$categoryObj = $this->_categoryFactory->create()->load($categoryId);
if($categoryObj->hasChildren()) {
return $categoryObj->getChildrenCategories();
}
}