I'm trying to create a list of child categories with links to those categories and their image.
I'm having an issue with getting the image, but all the other functions seem to be working properly. Here is my custom block inside a custom module. (By the way if theres already a better way to do this, do tell!)
# File ChildCategoryBlock.php
public function getChildCategories(){
// $this->_catalogLayer is an instance of Magento\Catalog\Block\Navigation
$children = $this->_catalogLayer->getCurrentCategory()->getChildrenCategories();
foreach($children as $child){
if( $imgsrc = $child->getImageUrl() ) {
echo "<img src='" . $imgsrc . "' alt='' class='' />";
} // above does nothing
var_dump( $child->getId() ); //-> (int) 9
var_dump( $child->getName() ); //-> (str) Fitness
var_dump( $child->getImage() ); //-> (bool) false
}
}
I think I'm doing this correctly. In Magento I have a test image set for category ID 9 (Fitness):
