0

I am trying to get the page_title (custom category attribute) in Navigation.php (menu build up) to use as the html title attribute.

For example this is were we would use the extra attribute in an html ahref title attribute: https://github.com/OpenMage/magento-lts/blob/1.9.3.x/app/code/core/Mage/Catalog/Block/Navigation.php#L308

We added this code, but it is not retrieving the page_title custom attribute

        $page_title = $this->escapeHtml($category->getPageTitle());
        if (empty($page_title)) {
            $page_title = $this->escapeHtml($category->getName());
        } 

But $category->getPageTitle() is not returning anything

$category->getPageTitle():

How can we get the page_title attribute directly?

0
0

The category collection doesn't load all attributes of a category by default. That would be a performance issue as well as loading each category separately in the navigation loop.

I think the best way to get a custom attribute of a category for using it in the navigation is to overwrite the category ressource model Mage_Catalog_Model_Resource_Category and add your custom attribute to the the fields returned by the collection in getChildrenCategories($category) method:

public function getChildrenCategories($category)
{
    $collection = $this->_getChildrenCategoriesBase($category);
    $collection->addAttributeToFilter('is_active', 1)
        ->addIdFilter($category->getChildren())
        ->addAttributeToSelect('page_title')
        ->load();

    return $collection;
}
0

Not tested ... but it shoud work to add custom attributes here: https://github.com/OpenMage/magento-lts/blob/1.9.3.x/app/code/core/Mage/Catalog/etc/config.xml#L776-L784

    <category>
        <collection>
            <attributes>
                <name/>
                <url_key/>
                <is_active/>
            </attributes>
        </collection>
    </category>

(put it into own module of course ;) )

2
  • Thx! I fixed it adding the data as below "addAttributeToSelect" in getChildrenCategories ... but would this solution have the same result?
    – snh_nl
    Sep 3 '20 at 14:31
  • @snh_nl yes, it should have the same result. As said, i've not tested it. Can you give it a try?
    – sv3n
    Sep 3 '20 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.