-1

Can I get the sorted children categories? For example, I need sorted categories by the category name in the object $subcats in below code:

$subcategory = $objectManager->create('Magento\Catalog\Model\Category')->load($catId);
$subcats = $subcategory->getChildrenCategories();
  • Does children category on same level? – Dhiren Vasoya Aug 9 at 12:19
  • you want to sort it alphabetically? – ASQ Aug 9 at 12:22
  • yes, need alphabetically sorted, and on same level. – Kamlesh Yaduwanshi Aug 9 at 12:23
  • Dhiren!, Abdus! is it possible? – Kamlesh Yaduwanshi Aug 9 at 12:33
  • yes it is possible – ASQ Aug 9 at 12:41
0

Try to use: \Magento\Catalog\Model\ResourceModel\Category\CollectionFactory

    $test = $this->categoryCollection
        ->create()
        ->addAttributeToSelect('parent_id')
        ->addAttributeToSelect('name')
        ->addAttributeToFilter('parent_id', 'your_id')
        ->setOrder('name', 'ASC')
        ->load();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.