0
如何将数据库字段添加到Magento全局搜索?我想在客户中创建一个自定义“业务名称”字段,然后使用管理面板上的全局搜索栏进行搜索。添加到Magento管理员端全局搜索
如何将数据库字段添加到Magento全局搜索?我想在客户中创建一个自定义“业务名称”字段,然后使用管理面板上的全局搜索栏进行搜索。添加到Magento管理员端全局搜索
经过一番搜索,我发现它在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