MAGENTO gets descriptions from a subcategory

Hi I am new to magento and am trying to set up a static block that displays a list of subcategories in a category. I was successfully captured by images and subcategory names, but for some reason I am unable to show descriptions to show.

Here the code cannot explain why it is not working and how can I fix it?

I commented out several lines because I was trying to use different things to get it to work.

helper ('directory / exit'); $ category = $ this-> getCurrentCategory (); getCurrentChildCategories () ;? >
<?php foreach ($_categories as $_category): ?> <?php  echo 

      

$ this-> htmlEscape ($ _ category-> getCategoryDescription ()) ;? >

        <?php if($_category->getIsActive()): ?>

            <div class="subcategory-image">

                        <a href="<?php echo $_category->getURL()

      

? > "title =" htmlEscape ($ _ category-> getName ())? > ">
                        </a>
                            <?php /* echo "Find this item->" */ ?>

                    </div> <div class="sub-category-container">
                    <h2><a href="<?php echo $_category->getURL()

      

? > "title =" htmlEscape ($ _ category-> getName ())? > "> HtmlEscape ($ _ category-> GetName ())?> GetURL ()?>" Class = "moreLink"> [More ...] getDescription ()? > → getDescription ()) :? > categoryAttribute ($ _ category, $ _description, 'description') ;? > ->

    

+2


source to share


2 answers


This is one of those cases where Varien decided that they should call the "load" on the data collection before returning it when it really isn't needed, and makes the utility function completely useless. If you trace the code down for Mage_Catalog_Block_Navigation->getChildrenCategories()

you eventually find it in Mage_Catalog_Model_Resource_Eav_Mysql4_Category

:

public function getChildrenCategories($category)
{
    $collection = $category->getCollection();
    /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
    $collection->addAttributeToSelect('url_key')
        ->addAttributeToSelect('name')
        ->addAttributeToSelect('all_children')
        ->addAttributeToSelect('is_anchor')
        ->addAttributeToFilter('is_active', 1)
        ->addIdFilter($category->getChildren())
        ->setOrder('position', 'ASC')
        ->joinUrlRewrite()
        ->load();
    return $collection;
}

      

Closest to the last line ->load();

means the request is running and the collection has been loaded, so it is too late to modify the request. So what you want to do is copy and paste that instead of calling getChildrenCategories

, and then add additional attributes that you want to use like so:

$_categories = $category->getCollection()
    ->addAttributeToSelect(
        array('url_key','name','all_children','is_anchor','description')
    )
    ->addAttributeToFilter('is_active', 1)
    ->addIdFilter($category->getChildren())
    ->setOrder('position', 'ASC')
    ->joinUrlRewrite()
;

      



The collection will now include a description attribute for getDescription () to work. Note that you don't need to call load()

, this happens automatically when you start using the iterator (the foreach loop runs this). So it's pointless for the call to be load()

included in this function, because otherwise you could just add one line below the function call:

$categories->addAttributeToSelect('description');

      

Instead, you need to copy the content of the function to customize the request.

+10


source


Edit:

$ _ category-> getCategoryDescription ()



For this:

$ _ category-> getDescription ()

0


source







All Articles