1

I want to get the subcategories of a main category using main category url.

I tried in this way in a function in my block.

$category = $this->_categoryFactory->create()->getCollection()
    ->addAttributeToFilter('url_key',$url_key);

enter image description here but i cannot get any thing.

3
  • ensure your url-key is not a complete url, it should be something like 'furniture' and not example.com/furniture.html
    – Shireen N
    Commented Mar 21, 2018 at 9:37
  • please check the updated question again
    – Mujahidh
    Commented Mar 21, 2018 at 9:49
  • try this $category = $this->_categoryFactory->create()->getCollection() ->addAttributeToFilter('url_key',$url_key)->getFirstItem();
    – Shireen N
    Commented Mar 21, 2018 at 9:55

1 Answer 1

2

Get Category

$categoryCollection = $this->_categoryFactory->create()->getCollection()      
                    ->addAttributeToFilter('url_key',$url_key)->getFirstItem(); 

$childs = $categoryCollection->getChildrenCategories();
foreach ($childs as  $child) {
   echo $child->getUrlKey();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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