Monday, November 23, 2009

Remove category from navigation. (Linking to non active category? for HyekiM)

This is a response for
For versions >= 1.4 this is included in the core (not this, but something similar)
Problem: Linking to a non-active category. Turned into "removing a category from navigation".
Why don't you trey an other approach. Set the category as active and remove it from the navigation.
If you are using drawItem method from 'Mage_Catalog_Block_Navigation' class to list your categories you can do this. Replace
if (!$category->getIsActive()) {
            return $html;
if (!$category->getIsActive() || $category->getId() == YOUR CATEGORY ID) {
            return $html;
This is the quick and dirty way to do it.
The clean way is to add a new 'yes/no' attribute on the category object "Show in Navigation (show_in_navigation)", and you can change the code above to:
if (!$category->getIsActive() || !$category->getShowInNavigation()) {
            return $html;

To add a new attribute to the category do this:
Run this sql script on your database
INSERT INTO `eav_attribute` (`attribute_id`, `entity_type_id`, `attribute_code`, `attribute_model`, `backend_model`, `backend_type`, `backend_table`, `frontend_model`, `frontend_input`, `frontend_label`, `frontend_class`, `source_model`, `is_global`, `is_visible`, `is_required`, `is_user_defined`, `default_value`, `is_searchable`, `is_filterable`, `is_comparable`, `is_visible_on_front`, `is_unique`, `is_configurable`, `apply_to`, `position`, `note`, `is_visible_in_advanced_search`, `is_used_for_price_rules`) VALUES
(NULL, 3, 'is_anchor', NULL, '', 'int', '', '', 'select', 'Show in Navigation', NULL, 'eav/entity_attribute_source_boolean', 1, 1, 0, 0, '', 0, 0, 0, 0, 0, 1, '', 1, '', 0, 1);

The second value to insert (3) is the entity_type id for the category object. You can check if this is correct in this table:eav_entity_type.
Take the entity_type_id for entity_type_code 'catalog_category'.

After you run the sql clear the cache (var/cache).
Now you should have the "Show in Navigation" attribute for each category.

No comments:

Post a Comment