user1597438
user1597438

Reputation: 2221

getting the id of current subcategory in magento

I know we can get the id of the current/active categories in Magento. I have products in different subcategories and I'd like to display these products as related products. My question is, is it possible to get the id of the currently selected subcategory?

Upvotes: 1

Views: 2104

Answers (1)

Mufaddal
Mufaddal

Reputation: 5381

You can fetch current category children if any if you are on product list or product details page.

$_currentCategory = Mage::registry('current_category') ;
$_currentCategories->getChildrenCategories() will give you all children category.

You can then filter your product collection based on category.

$products = Mage::getModel('catalog/category')->load(cat_id)
->getProductCollection()
->addAttributeToSelect('*')

This will give you product collection of your subcategories

Upvotes: 1

Related Questions