开发者

How to show All (product) Categories List in admin side: Magento

I want to show All Product Categories in admin side of My module in System.xml as a multiselect.

开发者_开发问答
$_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();
    } 
} 

But it will not show what i am want, i want only product categories.... Can some one idea about it... Thanx.


To show Category selection in system configuration,i have find a solution for it by extending a Mage Model class and method.

Mage_Adminhtml_Model_System_Config_Source_Category

and remove the line.

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

Now it display multiselect option in system configuration. Where you can select multi categories from the list..


I was working on Magento 1.7 and I didn't see a line that contains ->addPathFilter('^1/[0-9]+$')

But, removing a following line worked for me. ->addRootLevelFilter()


?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; ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜