1

制作了自己的骨架模板。我想将类别列表从标题移动到名为“left_container”的 div。我怎样才能做到这一点?我正在使用 Magento 1.7。

这种问题已经被问过好几次了,但似乎每次 Magento 更新,实现这一点的旧方法都行不通。

4

1 回答 1

0

您需要创建一个针对所有类别的自定义菜单侧边栏,您可以下载下一个扩展程序以查看所有类别的示例。这个扩展有一个递归方法来获取所有子结构:

http://www.magentocommerce.com/magento-connect/vertical-navigation-with-css-classes.html

我使用这个扩展来制作按自定义属性排序的自定义导航顶部,对我非常有用,希望对你有所帮助。

在扩展中帮助我的代码是下一个:

 public function drawOpenCategoryItem($category, $level=0, array $levelClass=null)
{
    $html = array();

    if ($this->_checkLoginCatalog()) return '';
    if (! $category->getIsActive()) return '';

    if (! isset($levelClass)) $levelClass = array();
    $combineClasses = array();

    $combineClasses[] = 'level' . $level;
    if ($this->_isCurrentCategory($category))
    {
        $combineClasses[] = 'active';
    }
    else
    {
        $combineClasses[] = $this->isCategoryActive($category) ? 'parent' : 'inactive';
    }
    $levelClass[] = implode('-', $combineClasses);

    $levelClass = array_merge($levelClass, $combineClasses);

    $levelClass[] =  $this->_getClassNameFromCategoryName($category);

    $productCount = '';
    if ($this->displayProductCount())
    {
        $n = $this->_getProductCount($category);
        $productCount = '<span class="product-count"> (' . $n . ')</span>';
    }

    // indent HTML!
    $html[1] = str_pad ( "", (($level * 2 ) + 4), " " ).'<span class="vertnav-cat"><a href="'.$this->getCategoryUrl($category).'"><span>'.$this->htmlEscape($category->getName()).'</span></a>'.$productCount."</span>\n";

    $autoMaxDepth = Mage::getStoreConfig('catalog/vertnav/expand_all_max_depth');
    $autoExpand = Mage::getStoreConfig('catalog/vertnav/expand_all');

    if (in_array($category->getId(), $this->getCurrentCategoryPath())
        || ($autoExpand && $autoMaxDepth == 0)
        || ($autoExpand && $autoMaxDepth > $level+1)
    ) {
        $children = $this->_getCategoryCollection()
            ->addIdFilter($category->getChildren());

        $children = $this->toLinearArray($children);

        //usort($children, array($this, '_sortCategoryArrayByName'));

        $hasChildren = $children && ($childrenCount = count($children));
        if ($hasChildren)
        {
            $children = $this->toLinearArray($children);
            $htmlChildren = '';

            foreach ($children as $i => $child)
            {
                $class = array();
                if ($childrenCount == 1)
                {
                    $class[] = 'only';
                }
                else
                {
                    if (! $i) $class[] = 'first';
                    if ($i == $childrenCount-1) $class[] = 'last';
                }
                if (isset($children[$i+1]) && $this->isCategoryActive($children[$i+1])) $class[] = 'prev';
                if (isset($children[$i-1]) && $this->isCategoryActive($children[$i-1])) $class[] = 'next';
                $htmlChildren.= $this->drawOpenCategoryItem($child, $level+1, $class);
            }

            if (!empty($htmlChildren))
            {
                $levelClass[] = 'open';

                // indent HTML!
                $html[2] = str_pad ( "", ($level * 2 ) + 2, " " ).'<ul>'."\n"
                        .$htmlChildren."\n".
                        str_pad ( "", ($level * 2 ) + 2, " " ).'</ul>';
            }
        }
    }

    // indent HTML!
    $html[0] = str_pad ( "", ($level * 2 ) + 2, " " ).sprintf('<li class="%s">', implode(" ", $levelClass))."\n";

    // indent HTML!
    $html[3] = "\n".str_pad ( "", ($level * 2 ) + 2, " " ).'</li>'."\n";

    ksort($html);
    return implode('', $html);
}
于 2012-06-12T08:33:48.083 回答