0

I'm trying to display a sub category grid on the parent category's page. I've followed this tutorial and everything works fine, except for the fact that even though I have assigned images to each sub category, the page still shows the placeholder images instead of the actual ones.

I think there's a problem somewhere in the phtml code.

// Retrieve the current category and it's children
<?php
$_maincategorylisting=$this->getCurrentCategory();
$_categories=$this->getCurrentChildCategories();
if($_categories->count()):
    foreach ($_categories as $_category):
        if($_category->getIsActive()):
            $cur_category=Mage::getModel('catalog/category')->load($_category->getId());
            $layer = Mage::getSingleton('catalog/layer');
            $layer->setCurrentCategory($cur_category);
            $catName = $this->getCurrentCategory()->getName();
            $_imageUrl=$cur_category->getImageUrl();
            if (!$_imageUrl) : //if the image url is false set it to the placeholder 
                $_imageUrl = $this->getSkinUrl('images/catalog/product/placeholder/thumbnail.jpg');
            endif;
            /* output */ ?>
                <div class="category-box">
                    <a href="<?php echo $this->getCategoryUrl($_category)?>">
                        <img src="<?php echo $_imageUrl?>" height="80">
                    </a>
                    <p><a href="<?php echo $this->getCategoryUrl($_category)?>"> <?php echo $_category->getName()?></a></p>
                </div>
        <?php endif;
    endforeach;
    $layer->setCurrentCategory($_maincategorylisting);
endif; ?>

Notes:

I'm running Magento v 1.6.0.0

This is the category page I'm testing on.

Bogdan
  • 1,053
  • 5
  • 20
  • 41

1 Answers1

1

I noticed, that in foreach loop you use $this->getCurrentCategory() which always will return "Filtrare" category.

Basically in the foreach loop you need to replace everywhere $this->getCurrentCategory() with $cur_category

ceckoslab
  • 1,189
  • 1
  • 9
  • 19
  • I followed you suggestion, but nothing changed with the sub category images – Bogdan Aug 15 '12 at 10:37
  • @Bogdan Me and my teammate tried the code from the tutorial, that you've mentioned and worked for us. We noticed some bad php style like using some php code ?> instead of . Can you tell us, how many store views you have in your Magento installation? – ceckoslab Aug 15 '12 at 11:54
  • Also here the code is well formatted an some versions of php don't throw errors, because of this script style " ?>" https://gist.github.com/3359512 – ceckoslab Aug 15 '12 at 12:00
  • I have just one store view, good point about poor formatting, I'm replacing the `` with ` – Bogdan Aug 15 '12 at 12:36
  • Can you check what's the url of the image ... check this for reference: http://awesomescreenshot.com/0afd8bka2 – ceckoslab Aug 15 '12 at 12:42
  • The url of one of the subcategory images is: http://accesorii-acvariu.ro/media/catalog/category/filtru_intern_jp_092_093_094.jpg. So all the category images are in: `media/catalog/category` – Bogdan Aug 15 '12 at 12:44
  • Can you try to comment the condition if($_imageUrl=!$this->getCurrentCategory()->getImageUrl()) and all the code wrapped inside and to check the result. Did you clear the cache? You also can try to re-index. – ceckoslab Aug 15 '12 at 13:34
  • I've updated the code in the initial post to it's latest version (much more cleaner). I've tried removing the condition that test the `$_imageUrl` variable, but the the html output for the image is `` so that means that the variable is `NULL`. Of course on each change I refreshed the indexes and cleared the cache :) – Bogdan Aug 16 '12 at 09:13