I need to get all category children of a specific category but disabled categories too.
I have this category tree:
+ Root (ID: 2) // enabled
| + Main 1 (ID: 3) // enabled
| | + Sub 1 (ID: 4) // enabled
| + Main 2 (ID: 5) // enabled
| | + Sub 2 (ID: 6) // enabled
| + Main 3 (ID: 7) // disabled
I need to get all childrens of category with ID 2 [Main1(3),Main2(5),Main3(7)].
I tried with:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$parentCategoryId = 2;
$parentCategory = $objectManager->get('Magento\Catalog\Model\Category')->load($parentCategoryId);
/*
Also tried with:
$parentCategory = $objectManager->get('Magento\Catalog\Model\Category')->getCollection()
->addIdFilter($parentCategoryId)
->addAttributeToFilter('is_active', false/0/null/2) // always return an empty array...
->getFirstItem();
*/
$parentCategory->getChildren(); // return [3,5]
$cats = [];
foreach($parentCategory->getChildrenCategories() as $cat)
$cats[] = $cat->getId();
print_r($cats); // return [3,5]