Показывать категорию в левой навигации


Я попытался реализовать код в своей навигации/слева.phtml

Код выглядит следующим образом

    <!-- subcategory code -->

    <?php

    $category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
    if(!$category->getChildren()){
     //$parentcat_id = $category->getParentCategory()->getId();
     //$category = Mage::getSingleton('catalog/category')->load($parentcat_id);
     $category = $category->getParentCategory();
    }
    $categories = $category->getCollection()
            ->addAttributeToSelect(array('name', 'thumbnail'))
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren());
     ?>
     <div class="block">

     <div class="block-title">
        <span><?php echo $category->getName() ?></span>

        </div>
        <div class="block-content clearfix">
    <ul class="subcategories">
        <?php foreach ($categories as $category): ?>
            <li>
                <a href="<?php echo $category->getUrl() ?>"><!--<img src="<?php echo Mage::getBaseUrl('media') . 'catalog' . DS . 'category' . DS . $category->getThumbnail() ?>" alt="<?php echo $this->htmlEscape($category->getName()) ?>" />-->
                    <span><?php echo $category->getName() ?>
                   <?php $collection = Mage::getModel('catalog/product')->getCollection()->addCategoryFilter($category);

    echo "(".count($collection).")"; ?></span>
                    </a>
            </li>
        <?php endforeach; ?>
    </ul></div>
    </div>
    <!-- subcategory code -->

    <!-- List all categories and their second level subcategories -->
    <div class="block block-list block-categories">
        <div id="block-categories" class="block-title active">
            <strong><span>Categories </span></strong>
        </div>

    <div id="leftnav" class="block-content" style="display:block">
        <?php $helper = $this->helper('catalog/category') ?>
        <?php $categories = $this->getStoreCategories() ?>
        <?php if (count($categories) > 0): ?>
            <ul id="leftnav-tree" class="level0">
                <?php foreach($categories as $category): ?>
                    <li class="level0<?php if ($this->isCategoryActive($category)): ?> active<?php endif; ?>">

                        <?php //if ($this->isCategoryActive($category)): ?>
                            <?php $subcategories = $category->getChildren() ?>
                            <?php if (count($subcategories) > 0): ?>
                                <ul id="leftnav-tree-<?php echo $category->getId() ?>" class="level1">
                                    <?php foreach($subcategories as $subcategory): ?>
                                        <li class="level1<?php if ($this->isCategoryActive($subcategory)): ?> active<?php endif; ?>">
                                            <a href="<?php echo $helper->getCategoryUrl($subcategory) ?>"><?php echo $this->escapeHtml(trim($subcategory->getName(), '- ')) ?></a>
                                             <?php $secondLevelSubcategories = $subcategory->getChildren() ?>
                                             <?php if (count($secondLevelSubcategories ) > 0): ?>
                                <ul id="leftnav-tree-<?php echo $subcategory->getId() ?>" class="level2">
                                    <?php foreach($secondLevelSubcategories as $secondLevelSubcategory ): ?>
                                        <li class="level2<?php if ($this->isCategoryActive($secondLevelSubcategory )): ?> active<?php endif; ?>">
                                            <a href="<?php echo $helper->getCategoryUrl($secondLevelSubcategory ) ?>"><?php echo $this->escapeHtml(trim($secondLevelSubcategory ->getName(), '- ')) ?></a>
                                        </li>
                                        <?php endforeach; ?>
                                </ul>
                                <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
                            <?php endif; ?>
                                    <?php endforeach; ?>
                                </ul>
                                <script type="text/javascript">decorateList('leftnav-tree-<?php echo $category->getId() ?>', 'recursive')</script>
                            <?php endif; ?>
                        <?php //endif; ?>
                    </li>
                <?php endforeach; ?>
            </ul>
            <script type="text/javascript">decorateList('leftnav-tree', 'recursive')</script>
        <?php endif; ?>
    </div>
    </div>

Но когда я устанавливаю "Включить" в меню навигации на "Нет", оно также исчезает отсюда.

Могу ли я каким-либо образом скрыть из верхнего меню и отобразить в боковом меню? Я хочу показать все категории в левой навигации, используя приведенный выше код, и только несколько категорий в верхней навигации.

Я также устал использовать пользовательский атрибут категории, но не могу создать атрибут значение с опцией "да" или "нет". сценарий для создания этого атрибута

            <?php
            $installer = $this;
            $installer->startSetup();
            $installer->addAttribute('catalog_category', 'topnav', array(
                'group'         => 'General Information',
                'type'     => 'int',
                'label'    => 'Top navigation',
                'input'    => 'boolean',
                'global'   => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
                'visible'           => true,
                'required'          => false,
                'user_defined'      => false,   
                'default' => '',
                'option' => 
              array (
                'values' => 
                array (
                  0 => 'Please select',
                  1 => 'Yes',
                  2 => 'No',
                ),
              ),
                'source' => 'eav/entity_attribute_source_boolean'
            )); 
            $installer->endSetup();
            ?> 

, А затем вызов

  if (!$category->getTopnav()) {
         continue;
         }

В observer.php

Author: Bhargav Mehta, 2015-01-02

2 answers

Вы можете добиться этого с помощью static blocks. Собрав все категории в статический блок и отобразив их в левой навигации. Для получения категорий в статический блок следуйте процедуре, описанной здесь.После завершения этого процесса вызовите свой статический блок с помощью <reference name="left"> и позже для скрытия категорий из top nav goto app/design/frontend/your_theme/default/template/page/html и откройте файл topmenu.phtml и поместите этот код в комментарии

<?php if($_menu): ?>
    <nav id="nav">
        <ol class="nav-primary">
            <?php echo $_menu ?>
        </ol>
    </nav>
<?php endif ?>
 1
Author: dh47, 2017-04-13 12:54:58

Я решил эту проблему, удалив средство визуализации для второго дочернего элемента в моем файле заголовка phtml. Теперь мой файл визуализации.phtml выглядит так:-

                <?php
                /**
                 * Magento
                 *
                 * NOTICE OF LICENSE
                 *
                 * This source file is subject to the Academic Free License (AFL 3.0)
                 * that is bundled with this package in the file LICENSE_AFL.txt.
                 * It is also available through the world-wide-web at this URL:
                 * http://opensource.org/licenses/afl-3.0.php
                 * If you did not receive a copy of the license and are unable to
                 * obtain it through the world-wide-web, please send an email
                 * to [email protected] so we can send you a copy immediately.
                 *
                 * DISCLAIMER
                 *
                 * Do not edit or add to this file if you wish to upgrade Magento to newer
                 * versions in the future. If you wish to customize Magento for your
                 * needs please refer to http://www.magentocommerce.com for more information.
                 *
                 * @category    design
                 * @package     rwd_default
                 * @copyright   Copyright (c) 2014 Magento Inc. (http://www.magentocommerce.com)
                 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
                 */

                /** @var Mage_Page_Block_Html_Topmenu_Renderer $this */
                /** @var Varien_Data_Tree_Node $menuTree */
                /** @var string $childrenWrapClass */

                $html = '';

                $children = $menuTree->getChildren();
                $parentLevel = $menuTree->getLevel();
                $childLevel = is_null($parentLevel) ? 0 : $parentLevel + 1;

                $counter = 1;
                $childrenCount = $children->count();

                $parentPositionClass = $menuTree->getPositionClass();
                $itemPositionClassPrefix = $parentPositionClass ? $parentPositionClass . '-' : 'nav-';

                foreach ($children as $child) {
                    $child->setLevel($childLevel);
                    $child->setIsFirst($counter == 1);
                    $child->setIsLast($counter == $childrenCount);
                    $child->setPositionClass($itemPositionClassPrefix . $counter);
                    if ($childLevel==1) {
                        $outermostClassCode = 'level'. $childLevel;
                    $_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

                    $html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';
                    $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '.'">'.'<img src="'.$this->escapeHtml($this->__($child->getThumbnail())).'" alt=""/>'. $this->escapeHtml($this->__($child->getName())).'</a>';

                    if (!empty($childrenWrapClass)) {
                        $html .= '<div class="'.'">';
                    }

                    $nextChildLevel = $childLevel + 1;

                             if (!empty($_hasChildren)) {
                        $html .= '<ul class="level'. $childLevel .'">';
                        $html .=     $this->render($child, $childrenWrapClass);
                        $html .= '</ul>';
                    }    



                    if (!empty($childrenWrapClass)) {
                        $html .= '</div>';
                    }

                    $html .= '</li>';


                    }

                    elseif ($childLevel!=2) {
                        $outermostClassCode = 'level'. $childLevel;
                    $_hasChildren = ($child->hasChildren()) ? 'has-children' : '';

                    $html .= '<li '. $this->_getRenderedMenuItemAttributes($child) .'>';
                    $html .= '<a href="'. $child->getUrl() .'" class="'. $outermostClassCode .' '. $_hasChildren .'">'.'<img src="'.$this->escapeHtml($this->__($child->getThumbnail())).'" alt=""/>'. $this->escapeHtml($this->__($child->getName())).'</a>';

                    if (!empty($childrenWrapClass)) {
                        $html .= '<div class="'. $childrenWrapClass .'">';
                    }

                    $nextChildLevel = $childLevel + 1;

                             if (!empty($_hasChildren)) {
                        $html .= '<ul class="level'. $childLevel .'">';
                        $html .=     $this->render($child, $childrenWrapClass);
                        $html .= '</ul>';
                    }    



                    if (!empty($childrenWrapClass)) {
                        $html .= '</div>';
                    }

                    $html .= '</li>';


                    }


                    $counter++;    
                }

                return $html;

Надеюсь, это кому-то поможет.

 0
Author: Bhargav Mehta, 2015-01-02 11:30:52