Magento Forum

Category id’s in Search results
 
maykk
Jr. Member
 
Total Posts:  16
Joined:  2008-07-07
 

I’m trying to echo/output category id’s in my search results using this:

<?php 
$Product 
Mage::getModel('catalog/product');
echo 
$Product->getCategoryId();
 
?>

I can render the category id’s in my grid/list view using this code. The Grid/list view template is used to display search results. However, the search results go blank.

Where are the functions that control what can be rendered in search results.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tzyganu
Mentor
 
Avatar
Total Posts:  2205
Joined:  2009-11-18
Bucharest, Romania
 

The piece of code you posted here works only because the method getCategoryId() looks like this:

if ($category Mage::registry('current_category')) {
            
return $category->getId();
        
}
        
return false;
In a category page (grid/list) this works because there is a category registered.
It’s logic that all products in one category (because you are listing a category) to belong to that category smile
In the search results page there is no category registered and getCategoryId returns null
 
Magento Community Magento Community
Magento Community
Magento Community
 
rickahontas
Member
 
Total Posts:  64
Joined:  2009-09-11
oakland, ca
 

Thanks for the tip Tzyganu… I’m having sort of a similar issue.

Currently I have a custom left.phtml navigation template for our store at the top of the file I have:

<?php
    $_base_url 
$this->helper('core/url')->getHomeUrl();
    
$category Mage::registry('current_category')->getId();
?>

I then have a ul/li sprite with different hover states that I set as active if a user is on a specific category page:

<ul id="storeNav">
    <
li id="fr">
        <
class="<?php if($category == 35) echo "on"; ?>" href="<?php echo Mage::getModel("catalog/category")->load(35)->getUrl() ?>" title="<?php echo $this->__('Link Title')?>"><span>Category 35</span></a>
    </
li>
</
ul>

I noticed that the catalog search results were breaking due to the lack of catalog being set. This is also happening on my product view pages. I’d like it to show the product’s parent category as class="on" to show an active state for my li button, but don’t know what php coding is needed to find the product’s category id.

Thanks for any help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Mirasvit
Guru
 
Avatar
Total Posts:  639
Joined:  2009-08-22
 

Hi
Check out these extension. They greatly improve the quality and relevance of search results Advanced Sphinx Search Pro http://mirasvit.com/magento-extensions/magento-sphinx-search.html

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