2011-06-27 41 views
2

我想顯示所有產品類別在我的模塊的管理端在System.xml作爲多選。如何顯示所有(產品)類別在管理端列表:Magento

$_category = Mage::getModel('catalog/category')->load(); 
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id); 
$helper = Mage::helper('catalog/category'); 

foreach($collection as $cat){ 
    if($_category->getIsActive()){ 
     $cur_category = Mage::getModel('catalog/category')->load($cat->getId());      
     $helper->getCategoryUrl($cat); 
     echo $cat->getName(); 
    } 
} 

但是,這並不表明我所想要的,我想要的只是產品類別....能有人的想法吧......感謝名單。

回答

2

要顯示系統配置中的分類選擇,我已經通過擴展Mage模型類和方法找到了解決方案。

Mage_Adminhtml_Model_System_Config_Source_Category

和刪除行。

->addPathFilter('^1/[0-9]+$') 

現在它在系統配置中顯示多選選項。在這裏您可以從列表中選擇多類..

1
?php $_helper = Mage::helper('catalog/category') ?> 
<?php $_categories = $_helper->getStoreCategories() ?> 
<?php $currentCategory = Mage::registry('current_category') ?> 

<?php if (count($_categories) > 0): ?> 
    <ul> 
     <?php foreach($_categories as $_category): ?> 
      <li> 
       <a href="<?php echo $_helper->getCategoryUrl($_category) ?>"> 
        <?php echo "<b>".$_category->getName(). $_category->getId()."</b>" ?> 
       </a> 
       <?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?> 
       <?php $_subcategories = $_category->getChildrenCategories() ?> 
       <?php if (count($_subcategories) > 0): ?> 
        <ul> 
         <?php foreach($_subcategories as $_subcategory): ?> 
          <li> 
           <a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>"> 
            <?php echo "--".$_subcategory->getName() ?> 
           </a> 
          </li> 
         <?php endforeach; ?> 
        </ul> 
       <?php endif; ?> 
      </li> 
     <?php endforeach; ?> 
    </ul> 
<?php endif; ?> 
2

我工作Magento的1.7,我沒有看到一個包含一行 - > addPathFilter('^ 1/[0-9] + $ ')

但是,刪除以下行爲我工作。 - > addRootLevelFilter()

+0

看起來他們在1.7中將正則表達式更改爲實際函數。這個功能可以做同樣的事情,所以只要做一下Nahid做的事情,然後發表評論。 – Adad64

相關問題