Skip to main content
place comments inside comment block, or this code will not run.
Source Link
<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery();


        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()

         if(is_int($searchText)){
           /* search for int in product sku and custom attributes*/
            $collection->addFieldToFilter(
                array('field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }
         else{
            /* search product name and description  */
            $collection->addFieldToFilter(
                array('field_name','field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'),
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }

        $collection->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}
<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery();


        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()

         if(is_int($searchText)){
            search for int in product sku and custom attributes
            $collection->addFieldToFilter(
                array('field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }
         else{
            search product name and description
            $collection->addFieldToFilter(
                array('field_name','field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'),
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }

        $collection->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}
<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery();


        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()

         if(is_int($searchText)){
           /* search for int in product sku and custom */
            $collection->addFieldToFilter(
                array('field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }
         else{
            /* search product name and description  */
            $collection->addFieldToFilter(
                array('field_name','field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'),
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }

        $collection->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}
added 31 characters in body
Source Link
<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery(); 


        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()

         if(is_int($searchText)){
            search for int in product sku and custom attributes
         }   $collection->addFieldToFilter(
         else{       array('field_name'),
            search product name and descriptionarray(
         }           array('like'=>'%'.$searchText.'%'), 
                    )
        // move code above to your if statement and);
 do your db lookup accordingly    }
        $collection =else{
 Mage::getModel('module/name')->getCollection()           search product name and description
            $collection->addFieldToFilter(
                array('field_name','field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'),
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }

        $collection->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}

See http://blog.mattstephens.co.uk/post/27326981315/adding-custom-module-to-magentos-admin-global-search

You could also rewrite the global product search block.

<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery();

         if(is_int($searchText)){
            search for int in product sku and custom attributes
         }
         else{
            search product name and description
         }

        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()
            ->addFieldToFilter(
                array('field_name',),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                )
            ->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}

See http://blog.mattstephens.co.uk/post/27326981315/adding-custom-module-to-magentos-admin-global-search

<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery(); 


        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()

         if(is_int($searchText)){
            search for int in product sku and custom attributes
            $collection->addFieldToFilter(
                array('field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }
         else{
            search product name and description
            $collection->addFieldToFilter(
                array('field_name','field_name'),
                array(
                    array('like'=>'%'.$searchText.'%'),
                    array('like'=>'%'.$searchText.'%'), 
                    )
                );
         }

        $collection->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}

See http://blog.mattstephens.co.uk/post/27326981315/adding-custom-module-to-magentos-admin-global-search

You could also rewrite the global product search block.

added 31 characters in body
Source Link
<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery();

         if(is_int($searchText)){
            search for int in product db
sku and custom attributes
         }
          else{
              search other dbproduct table
name and description
         }

        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()
            ->addFieldToFilter(
                array('field_name',),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                )
            ->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}
<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery();

         if(is_int($searchText)){
            search for int in product db
          }
          else{
              search other db table
           }

        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()
            ->addFieldToFilter(
                array('field_name',),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                )
            ->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}
<?php
class MagePal_GlobalAttributesSearch_Model_Search_Customattributes extends Varien_Object
{
    /**
     * Load search results
     *
     */
    public function load() {
        $arr = array();
        $searchText = $this->getQuery();

         if(is_int($searchText)){
            search for int in product sku and custom attributes
         }
         else{
            search product name and description
         }

        // move code above to your if statement and do your db lookup accordingly 
        $collection = Mage::getModel('module/name')->getCollection()
            ->addFieldToFilter(
                array('field_name',),
                array(
                    array('like'=>'%'.$searchText.'%'), 
                    )
                )
            ->load();

        foreach ($collection as $model) {
            $arr[] = array(
                'id'            => 'path/1/'.$model->getId(),
                'type'          => Mage::helper('adminhtml')->__('Custom Attributes'),
                'name'          => $model->getId(),
                'description'   => Mage::helper('core/string')->truncate('desc', 35),
                'url' => Mage::helper('adminhtml')->getUrl('*/path/edit', array('id'=>$model->getId())),
            );
        }

        $this->setResults($arr);
        return $this;
    }
}
added 2 characters in body
Source Link
Loading
Source Link
Loading