2012-06-12 79 views
1

製作了我自己的骨架模板。我想將分類列表從標題移動到名爲'left_container'的div。我怎樣才能做到這一點?我正在使用Magento 1.7。Magento - 側欄中的類別

這種類型的問題已經被問過好幾次了,但是對於每一個Magento更新似乎都是如此,實現這個目標的舊方法是行不通的。

+0

我也有同樣的問題,如果你得到解決,那麼請給你的問題的正確答案。 – Jalpesh

回答

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); 
} 
相關問題