Magento – Category Descriptions & Images

I hate it when you spend time trying to get something to work – then realised that you’ve already solved this same problem before and really should have remembered. Must blog more!!

Anyway this one relates to Magento Category descriptions and images. Using the method

echo $_category->getDescription()

Won’t work unless you amended the Mage_Catalog_Block_Navigation class. Take a local copy of Mage/Catalog/Block/Navigation.php and ensure that the getCurrentChildCategories() method works like below. Note there’s an interesting point on Stackoverflow about removing the load() call prior to returning it.

	
public function getCurrentChildCategories()
   {
        $layer = Mage::getSingleton('catalog/layer');
        $category   = $layer->getCurrentCategory();
        /* @var $category Mage_Catalog_Model_Category */
        $collection = Mage::getModel('catalog/category')->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        $collection->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('is_anchor')
            ->addAttributeToSelect('image')
            ->addAttributeToSelect('description')  
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren())
            ->setOrder('position', 'ASC')
            ->joinUrlRewrite()
            ->load();

        $productCollection = Mage::getResourceModel('catalog/product_collection');
        $layer->prepareProductCollection($productCollection);
        $productCollection->addCountToCategories($collection);
        return $collection;
    } 

Leave a Comment