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 に答える