I am trying to get at a categories image from within PHP / a .phtml file.
Here is my code:
$_category = $this->getCurrentCategory();
$_children = $_category->getChildrenCategories();
foreach( $_children as $child ){
if( $child->getIsActive() ){
echo "<p>" . $child->getImageUrl() . "</p>";
This last line results in an empty string. When I var_dump
it, I get the following:
bool(false)
Upon further investigation, this getImageUrl
function is defined in /vendor/magento/module-catalog/Model/Category.php
on line 656, like so:
public function getImageUrl(){
$url = false;
$image = $this->getImage();
if ($image) {
The problem here is that $this->getImage()
returns NULL
. Nowhere in Category.php
can I find the function getImage
, and all of this makes me think that there is no getImage
function in the Category class.
Is this correct? Do we need to add a getImage
method to the class to make getImageUrl
work?
Or is getImage
inherited from elsewhere? And in this case, why is it returning NULL
?
Disclaimers:
This is Magento 2.0.2.
I am not about to alter core code, I already have a theme of my own, and if I was to add a new function to the Category class I would extend the core code in my theme.
I have re-indexed, I have cleared caches, I have re-deployed.