1
votes

I'm trying to display brands on my store. I sell both men and women clothing so I have two separate brand categories.

My category structure looks like this:

Men Brands x-brand Women Brands y-brand

I would like to display the brand of the product.

I found this code:

$children = Mage::getModel('catalog/category')->getCategories(10);
foreach ($children as $category) {
    echo $category->getName();
}

However, it works for only one category and displays all subcategories in the parent category not the one owned by the product.

How can I modify this to show the subcategory of the current brand category.

I hope this made sense and I appreciate any help!

2
What place on your store you need it figure out??Guerra
If you're trying to do it on product page, try this one $_category_detail=Mage::registry('current_category'); echo $_category_detail->getName();Sergei Guk
Hey, I'm trying to do this on the catalog viewing page. Thanks for your input!Anthony

2 Answers

1
votes

To display sub-category listing for a give category

$_category = Mage::registry('current_category');

$subcategories = Mage::getModel('catalog/category')->getCategories($_category->getId());

foreach ($subcategories as $subcategory){
     print_r($subcategory->getData()
}

See more @ Magento: Display sub-category list

0
votes

Old question is old, but figured I'd chime in as the question went unanswered and someone else might find this useful..

So, first of all, this code relies on being inside a products list loop, i.e.:

$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product) {
    *... your product list output here ...*
}

Second, this code is dependent on a setup using "BRANDS" as a sub-category of your Magento root category (whatever it happens to be called) and each brand name being set as a sub-category of the "BRANDS" sub-cat. You may need to augment that cat name in the code below or change your category structure to match mine.

So, within the "ProductCollection" loop already set in app/design/frontend/your-package/your-theme/template/catalog/product/list.phtml, you can put this snippet to echo the name of the brand name.

$categories = $_product->getCategoryCollection()
                       ->addAttributeToSelect('name')
                       ->addAttributeToFilter('is_active', array('eq' => 1));

foreach($categories as $category) {
    $catID = $category->getId();
    $catParent = Mage::getModel('catalog/category')->load($catID)
                                                   ->getParentCategory();
    if ( $catParent->getName() == 'BRANDS' ) {
        echo '<a href="'.$category->getUrl().'">'.$category->getName().'</a>';
    }
}

Bonus edit: Added code to wrap brand name in link to brand category page.