1

I have this function in my block.

public function getSubcategoryByUrlkey($url_key)
{   

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

    echo $categoryCollection->getSelect(); exit;

    return $childs = $categoryCollection->getChildrenCategories();

}

I cannot view anything from this collection. My Magento version is Magento ver. 2.2.2. What is the mistake I am doing here?

echo $categoryCollection->getSelect();

this also not retrieve the query

Update I am getting this error

Fatal error: Uncaught Error: Call to undefined method Magento\Catalog\Model\ResourceModel\Category\Collection::getChildrenCategories()

2

Remove ->getFirstItem() then it will show the query

$categoryCollection = $this->_categoryCollectionFactory->create()      
            ->addAttributeToFilter('url_key',$url_key); 

echo $categoryCollection->getSelect(); exit;

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.