2010-03-04 31 views

回答

1

經過一番搜索,我發現它在Mage_Adminhtml_Model_Search_Customer。此類有一個方法load(),您可以修改該方法以返回其他搜索結果並更改了潛臺詞。奇怪的是,Magento的實際上已經加載所有可能的搜索resutls的搜索,然後限制他們,但無論這裏的上添加自定義字段搜索代碼:

舊代碼:

$collection = Mage::getResourceModel('customer/customer_collection') 
     ->addNameToSelect() 
     ->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left') 
     ->addAttributeToFilter(array(
      array('attribute'=>'firstname', 'like'=>$this->getQuery().'%'), 
      array('attribute'=>'lastname', 'like'=>$this->getQuery().'%'), 
      array('attribute'=>'company', 'like'=>$this->getQuery().'%'), 
     )) 
     ->setPage(1, 10) 
     ->load(); 

我創建類的局部空間覆蓋此功能,並增加了以下內容:

$collection = Mage::getResourceModel('customer/customer_collection') 
     ->addNameToSelect() 
     ->joinAttribute('company', 'customer_address/company', 'default_billing', null, 'left') 
     ->joinAttribute('company_name', 'customer/company_name', 'entity_id', null, 'left') 
     ->addAttributeToFilter(array(
      array('attribute'=>'firstname', 'like'=>$this->getQuery().'%'), 
      array('attribute'=>'lastname', 'like'=>$this->getQuery().'%'), 
      array('attribute'=>'company', 'like'=>$this->getQuery().'%'), 
      array('attribute'=>'company_name', 'like'=>$this->getQuery().'%'), 
     )) 
     ->setPage(1, 10) 
     ->load(); 

現在我可以使用全局搜索我的自定義屬性!希望這會幫助別人。

謝謝, Joe