Magento Forum

   
custom attributes on search result
 
Claudio Vargas
Jr. Member
 
Total Posts:  22
Joined:  2007-12-23
 

before 1.2.0.1 I had no problems getting my custom attributes on the search results product list, but since the new model was implemented I can’t get them to show

this is how i did it before 1.2.0.1

protected function _getProductCollection()

    
{

        
if (is_null($this->_productCollection)) {

            $this
->_productCollection $this->_getQuery()->getResultCollection()

                ->
addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());

                

                         
$this->_getProductCollection()->addAttributeToSelect("my_attribute");  


            
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);

            
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);

        
}



        
return $this->_productCollection;

    
}

but this is the new _getProductCollection() code in 1.2.0.1

protected function _getProductCollection()
    
{
        
if (is_null($this->_productCollection)) {
            $this
->_productCollection Mage::getSingleton('catalogsearch/layer')->getProductCollection();
/*
            $this->_productCollection = Mage::getResourceModel('catalogsearch/fulltext_collection')
                ->addSearchFilter($this->helper('catalogSearch')->getEscapedQueryText())
                ->setStore(Mage::app()->getStore())
                ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                ->addUrlRewrite();
      
            Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($this->_productCollection);
            Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($this->_productCollection);*/
        
}

        
return $this->_productCollection;
    
}

any ideas on getting the same result in 1.2.0.1?

 
Magento Community Magento Community
Magento Community
Magento Community
 
MageParts
Guru
 
Avatar
Total Posts:  415
Joined:  2007-11-18
 

Try this

protected function _getProductCollection()
    
{
        
if (is_null($this->_productCollection)) {
            $this
->_productCollection Mage::getSingleton('catalogsearch/layer')->getProductCollection()
                ->
addAttributeToSelect('my_attribute');
        
}

        
return $this->_productCollection;
    
}

Otherwise you might find some answers in this file: app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php. Sorry I can’t be of more assistance, I only got 1.2.0.1 installed for one client and I can’t really play around with those files.

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