Question

i.e.

I have the following category: main category (!= root)

Main category
|
|- sub category 1
|
|- sub category 2
|
|- sub category 3

My navigation,

  <ul>
    <?php echo $_menu ?>
  </ul>

Now renders

Main category

How can I get it to render just the sub categories, like

Subcategory 1
Subcategory 2
Subcategory 3

(The reason I put all my categories in one main is to be able to link to mysite.com/shop for all products. Main category therefore is /shop )

Was it helpful?

Solution

You can probably do that by overwriting the file app/core/Mage/Catalog/Block/Navigation.php

app/code/local/YourCompany/Catalog/etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_Catalog>
            <version>1.0</version>
        </YourCompany_Catalog>
    </modules>
    <global>
        <blocks>
            <catalog>
                <rewrite>
                  <navigation>YourCompany_Catalog_Block_Navigation</navigation>
               </rewrite>
           </catalog>
       </blocks>       
    </global>
</config>

app/code/local/YourCompany/Catalog/Block/Navigation.php:

class YourCompany_Catalog_Block_Navigation extends Mage_Catalog_Block_Navigation {
    public function renderCategoriesMenuHtml($level = 0, $outermostItemClass = '', $childrenWrapClass = '')
{
    $activeCategories = array();
    foreach ($this->getStoreCategories() as $child) {
        if ($child->getIsActive()) {
            $activeCategories[] = $child;
        }
    }

    $activeCategoriesCount = count($activeCategories);
    $hasActiveCategoriesCount = ($activeCategoriesCount > 0);

    if (!$hasActiveCategoriesCount) {
        return '';
    }

    $html = '';
    $j = 0;
    foreach ($activeCategories as $category) {
        foreach ($category->getChildren() as $child) { // Added this loop to bypass the first top categories
            $html .= $this->_renderCategoryMenuItemHtml(
                $child,
                $level,
                ($j == $activeCategoriesCount - 1),
                ($j == 0),
                true,
                $outermostItemClass,
                $childrenWrapClass,
                true
            );
            $j++;
        }
    }

    return $html;
}
}

app/etc/modules/YourCompany.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <YourCompany_Catalog>
            <active>true</active>
            <codePool>local</codePool>
        </YourCompany_Catalog>
    </modules>
</config>

Global overview of the files to creates: app code local YourCompany Catalog Block Navigation.php etc config.xml etc modules YourCompany_Catalog.xml

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top