2013-01-04 60 views
1

我有一個Magento的網站具有以下類別結構(大寫字母類別和小寫字母是產品):Magento的類別導航

ROOT CATEGORY 
    APPARELS 
      SHOP BY SIZE 
       product1 
       product2 
       product3 
      SHOP BY COLLECTION 
       product4 
       product5 
      SHOP BY DESIGN 
       product6 
       product7 
       product8 
       product9 

我想告訴我的導航菜單SHOP按尺寸SHOP BY COLLECTION並通過設計購物。我不希望導航以APPARELS級別開始。有沒有辦法做到這一點?

注意:根據Magento設計,ROOT CATEGORY不能顯示在導航菜單中。導航菜單從第二級的類別開始,即在這種情況下爲服裝。

+0

是APPARELS在該級別唯一的類別? – Ian

回答

2

看看navigation.php,你可以改變核心功能,但通過使用重寫模塊(永遠不會直接改變核心文件!)。當我需要自定義導航功能時,我總是從那裏開始。

http://freegento.com/doc/db/d56/_catalog_2_block_2_navigation_8php-source.html

編輯,alltough我經常使用這種方法,我會建議避免重寫儘可能,因爲我們正在談論顯示拉特2類,我不認爲它有可能在這種情況下艱難作爲主要的資產淨值

2

如果你真的想使用設計的根 - >服裝 - >商店由*你可以做到這一點與單控和修改

config.xml中 - 這顯然是一個沉重簡化文件,你需要提供助手重寫爲文件。

<?xml version="1.0"?> 
<config> 
    <helpers> 
     <catalog> 
      <rewrite> 
       <category>Namespace_Module_Helper_Catalog_Category</category> 
      </rewrite> 
     </catalog> 
    </helpers> 
</config> 

Category.php 這是假設你要使用的第一個孩子類別網站根目錄類別。在你的情況下,這將是「服裝」。此修改考慮到使用平面或非平面類別表。還有其他的選擇ID的選項,其中一個是以類別列表作爲源的系統配置,從而允許您直接選擇導航根類別。

這個文件的癥結在於讓Parent ID成爲你想要導航的「根類別」。同樣,對於您的情況,家長ID將被設置爲「服裝」類別的ID。

class Namespace_Module_Helper_Catalog_Category extends Mage_Catalog_Helper_Category { 
    public function getStoreCategories($sorted=false, $asCollection=false, $toLoad=true) 
    { 
     $parent  = Mage::app()->getStore()->getRootCategoryId(); 
     $cacheKey = sprintf('%d-%d-%d-%d', $parent, $sorted, $asCollection, $toLoad); 
     if (isset($this->_storeCategories[$cacheKey])) { 
      return $this->_storeCategories[$cacheKey]; 
     } 

     /** 
     * Check if parent node of the store still exists 
     */ 
     $category = Mage::getModel('catalog/category'); 
     /* @var $category Mage_Catalog_Model_Category */ 
     if (!$category->checkId($parent)) { 
      if ($asCollection) { 
       return new Varien_Data_Collection(); 
      } 
      return array(); 
     } 

     /* Change ian on 1/4/13 at 11:16 AM - Description: Here we capture the id of first child for use as the 'root' */ 
     $category->load($parent); 
     /** @var $collection Mage_Catalog_Model_Resource_Category_Collection */ 
     $collection = $category->getChildrenCategories(); 
     if (is_array($collection)) { 
      $category = array_shift($collection); //get the first category in the array. Unknown key. 
      $parent = $category->getId(); 
     } else { 
      $parent = $collection->getFirstItem()->getId(); 
     } 

     $recursionLevel = max(0, (int) Mage::app()->getStore()->getConfig('catalog/navigation/max_depth')); 
     $storeCategories = $category->getCategories($parent, $recursionLevel, $sorted, $asCollection, $toLoad); 

     $this->_storeCategories[$cacheKey] = $storeCategories; 
     return $storeCategories; 
    } 
} 
+0

當他需要的是自定義導航時,爲什麼要調整類助手?這將改變對這個幫手的所有呼叫...... –

+0

他指定他希望導航離開第三級類別而不是第二級。這完成了。從這一點來說,現在的主題是呈現菜單,而不是根類別。 – Ian