I have this function in my block.

public function getSubcategoryByUrlkey($url_key)

    $categoryCollection = $this->_categoryCollectionFactory->create()      

    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()


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

$categoryCollection = $this->_categoryCollectionFactory->create()      

echo $categoryCollection->getSelect(); exit;
| 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.