0

Hy! I am trying to load in top menu only 4 subcategories and in left sidebar all categories and subcategories. I managed to load only 4 subcategories, but the same is loaded and in left sidebar. I can share the code and any help will be appreciated. Thanks! This is my code and it is located in app/code/Magiccart/Magicmenu/Block/Menu.php:

public function getTreeCategoriesExt($parentId) // include Magic_Label
{ 
    $categories = $this->_categoryInstance->getCollection()
                    ->addAttributeToSelect(array('name','magic_label','url_path'))
                    ->addAttributeToFilter('include_in_menu', 1)
                    ->addAttributeToFilter('parent_id', $parentId)
                    ->addIsActiveFilter()
                    ->addAttributeToSort('position', 'asc'); 
    $html = '';
    $counter = 0;
    $allCateg = 'Toate categoriile';
    $categoryObj = $this->categoryRepository->get($parentId);

    foreach($categories as $category)
    {
        $level = $category->getLevel();
        $childHtml = ( $this->_recursionLevel == 0 || ($level -1 < $this->_recursionLevel) ) ? $this->getTreeCategoriesExt($category->getId()) : '';
        $childClass = $childHtml ? ' hasChild parent' : '';
        $childClass .= $this->isCategoryActive($category->getId()) ? ' active' : '';
        $html .= '<li class="level' . ($level -2) . $childClass . '"><a href="' . $category->getUrl() . '"><span>' . $category->getName() . $this->getCatLabel($category) . "</span></a>\n" . $childHtml . '</li>';

        if($counter == 3 && count($categories) > 4) {
            $html .= '<li class="all-cat"><a href="' . $categoryObj->getUrl() . '"><span>' . $allCateg . '</span></a></li>';
        }

        if(++$counter > 3) break; 

    }
    if($html) $html = '<ul class="level'.($level -3).' submenu">' .$html. '</ul>';

    return $html;
}

1 Answer 1

1

I made this in template/catalog/navigation/left.phtml:

first line:

<?php $ct = Mage::registry('current_category')->getID(); ?>

in the end of the file(before endif;)

<?php elseif( $ct == 92 || $ct == 85 || $ct == 224): ?>
<?php
$currentcategory = Mage::registry('current_category');
$subcategorys = explode(',' , $currentcategory->getChildren());


?>

<div class="block block-layered-nav">
    <div class="block-title">
        <strong><span><?php echo $this->__('Browse By') ?></span></strong>
    </div>
    <div class="block-content">
        <dl id="narrow-by-list2">
            <dt><?php echo $this->__('Category') ?></dt>
            <dd>
                <ol>
                <?php foreach($subcategorys as $cat): ?>
                     <?php $cate =  Mage::getModel('catalog/category')->load($cat); ?>
                    <li>

                        <a href="<?php echo $cate->getUrl()?>" <?php if ($this->isCategoryActive($cate)): ?> class="current"<?php endif; ?>><?php echo $this->escapeHtml($cate->getName()) ?>(<?php echo $cate->getProductCount() ?>) </a>                  
                    </li>
                <?php endforeach; ?>
                </ol>
            </dd>
        </dl>
        <script type="text/javascript">decorateDataList('narrow-by-list2')</script>
    </div>
</div>

<?php endif; ?>
1
  • Thanks for your answer, but not this is the problem. A printscreen will help you to understand my problem?
    – OvidiuC
    Jun 27, 2018 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.