cancel
Showing results for 
Search instead for 
Did you mean: 

custom url for navigation menu

   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

custom url for navigation menu

I am trying to create a module so that you can define a custom url for the navigation menu. I am trying to link to a non CMS page created by another extension. I was able to create the custom attribute for the category and it shows in admin but when I try to extend "Mage_Catalog_Model_Category" to overwrite the "getUrl" function, I am not able to access my new custom attribute. See below for code. I just want to use the "custom_category_url" if there is a value otherwise fallback to the parent getUrl function, but currently $this->getData('custom_category_url') is always returning NULL. I assume I need to do something so that the attribute is available at this point but I am not sure how. Full code is available at https://github.com/americanstationery/AmstatCustomUrl.

 

 

<?php
class Amstat_CustomUrl_Model_Category extends Mage_Catalog_Model_Category
{
    /**
     * Get category url
     *
     * @return string
     */
    public function getUrl()
    {
        $categoryRedirectUrl = $this->getData('custom_category_url');
 
        if(strlen($categoryRedirectUrl) > 0 && $categoryRedirectUrl != '0'){
            return $categoryRedirectUrl;
        }

        return parent::getUrl();
    }
}

 

1 REPLY 1

Re: custom url for navigation menu

I haven't tried the code but it could be because the attribute is marked to be "used_in_product_listing" => "true" and so isn't added to the flat table. If the category is being loaded from the flat category table without this setting then it wouldn't be available. 

----
If you've found one of my answers useful, please give "Kudos" or "Accept as Solution" as appropriate. Thanks!