Pergunta

i.e.

Eu tenho o seguinte categoria:categoria principal (!= raiz)

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

A minha navegação,

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

Agora renderiza

Main category

Como posso obtê-lo para processar apenas as sub-categorias, como

Subcategory 1
Subcategory 2
Subcategory 3

(A razão de eu colocar todos os meus categorias em uma principal é ser capaz de vincular a mysite.com/shop para todos os produtos.Categoria principal, portanto, é /loja )

Foi útil?

Solução

Você pode, provavelmente, fazer o que, substituindo o arquivo 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>

Visão Global dos arquivos para cria: aplicação código local Empresa Catálogo Bloco A navegação.php etc config.xml etc módulos YourCompany_Catalog.xml

Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top