1
votes

I have a Magento website with the following category structure (CAPITALS letters are CATEGORIES and small letters are products):

ROOT CATEGORY
     APPARELS
          SHOP BY SIZE
               product1
               product2
               product3
          SHOP BY COLLECTION
               product4
               product5
          SHOP BY DESIGN
               product6
               product7
               product8
               product9

I want to show my navigation menu as SHOP BY SIZE, SHOP BY COLLECTION and SHOP BY DESIGN. I don't want the navigation to start with APPARELS level. Is there any way to do this?

Note: As per Magento design, ROOT CATEGORY cannot be shown in navigation menu. The navigation menu starts from categories in 2nd level i.e. APPARELS in this case.

2
Is APPARELS the only category at that level?Ian

2 Answers

2
votes

Take a look at navigation.php, you could alter the core functionality but by using a module with rewrite (never directly alter a corefile!). I always start there when i need custom navigation functionality.

http://freegento.com/doc/db/d56/_catalog_2_block_2_navigation_8php-source.html

edit, alltough i often use this method, i would advise to avoid rewriting as much as possible, I don't think its possible in this case tough because we are talking about displaying lvl 2 categories as main nav

2
votes

IF you truly want to use the design Root -> Apparels -> Shop By * you can do this with a single override and modification

config.xml - this is obviously a heavily simplified file, you'll need to provide a helper rewrite for the file.

<?xml version="1.0"?>
<config>
    <helpers>
        <catalog>
            <rewrite>
                <category>Namespace_Module_Helper_Catalog_Category</category>
            </rewrite>
        </catalog>
    </helpers>
</config>

Category.php This assumes you want to use the first child category under your site's root category. In your case it would be "Apparels". This modification takes into account the use of flat or non-flat category tables. There are other options for selecting the ID, one would be a system configuration with the category list as a source thus allowing you to choose your navigations root category directly.

The crux of this file is getting the Parent ID to be the "root category" you want to base the navigation on. Again, for your case the parent ID would be set to that of the "apparels" category.

class Namespace_Module_Helper_Catalog_Category extends Mage_Catalog_Helper_Category {
    public function getStoreCategories($sorted=false, $asCollection=false, $toLoad=true)
    {
        $parent     = Mage::app()->getStore()->getRootCategoryId();
        $cacheKey   = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad);
        if (isset($this->_storeCategories[$cacheKey])) {
            return $this->_storeCategories[$cacheKey];
        }

        /**
         * Check if parent node of the store still exists
         */
        $category = Mage::getModel('catalog/category');
        /* @var $category Mage_Catalog_Model_Category */
        if (!$category->checkId($parent)) {
            if ($asCollection) {
                return new Varien_Data_Collection();
            }
            return array();
        }

        /* Change ian on 1/4/13 at 11:16 AM - Description: Here we capture the id of first child for use as the 'root' */
        $category->load($parent);
        /** @var $collection Mage_Catalog_Model_Resource_Category_Collection */
        $collection = $category->getChildrenCategories();
        if (is_array($collection)) {
            $category = array_shift($collection); //get the first category in the array.  Unknown key.
            $parent = $category->getId();
        } else {
            $parent = $collection->getFirstItem()->getId();
        }

        $recursionLevel  = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth'));
        $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad);

        $this->_storeCategories[$cacheKey] = $storeCategories;
        return $storeCategories;
    }
}