Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get specific category level

Tags:

magento

How can I get a specific category level from Magento, my category setup looks like this now.

root_catalog
    |-Shop
        |-Shoes
        |-T-shirts
    |-Brands
        |-Nike
           |-Womens
           |-Mens
        |-Adidas
        |-Asics

<?php if( $category = Mage::getModel('catalog/category')->load( $categories[1]) ): ?>
    <?php echo $category->getName(); ?>
<?php endif ?>

When calling $category->getName(); I would like to only display the Brand Name, is that possible?

like image 837
andkjaer Avatar asked Mar 31 '13 16:03

andkjaer


People also ask

How to get category level in Magento 2?

You can get category level from $category = Mage::getModel('catalog/category')->load( $categories[1]) )->getLevel() and then check with your brand name category level, if match then display name.


1 Answers

You can get category level from $category = Mage::getModel('catalog/category')->load( $categories[1]) )->getLevel() and then check with your brand name category level, if match then display name.

e.g. suppose brand category level is 3

<?php if( $category = Mage::getModel('catalog/category')->load( $categories[1]) ): ?>
    <?php if($category->getLevel() == 3)
        echo $category->getName(); ?>
    <?php endif ?>
<?php endif ?>
like image 66
ANKIT Avatar answered Sep 21 '22 18:09

ANKIT