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.

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

Get Category

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

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

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.