Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

How do I find out what Category I’m in? 
 
rzazueta
Member
 
Total Posts:  34
Joined:  2008-07-21
 

I;ve created a special side menu that is supposed to do something special with the subcategories of the current category it’s in. I call $this->getCurrentCategory() and it returns a Category object COMPLETELY DIFFERENT than the category I’m in, a complete different hierarchy altogether. Is this function not supposed to work this way?

How do I get the Category object for the category I’m currently in when browsing my store?

Rob Z.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

post the block you are referencing - or just check it out yourself - what is the code in the function “getCurrentCategory” in that block?

That function is usually created and/or overridden (rather than inherited) for each Block

 
Magento Community Magento Community
Magento Community
Magento Community
 
rzazueta
Member
 
Total Posts:  34
Joined:  2008-07-21
 

Here’s the block of code in the Navigation block - I’m very solid in my PHP and have traversed this code tree WAY too many times now and I still can’t grasp how it tries to figure out what category the page is currently in:

public function getCurrentCategory()
    
{
        
if (Mage::getSingleton('catalog/layer')) {
            
return Mage::getSingleton('catalog/layer')->getCurrentCategory();
        
}
        
return false;
    
}

This returns a valid category that is in no way related to the current category. What is its purpose if it doesn’t actually return the current category?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rzazueta
Member
 
Total Posts:  34
Joined:  2008-07-21
 

I should note - that comes frrom Mage->Catalog->Block->Navigation.php under the app code.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top