无法在 Magento Admin Sales 上按客户全名搜索
Unable to search by customer full name on Magento Admin Sales
我要去 Magento->Sales->Orders 并尝试在 'Bill to' 输入中搜索全名(名字姓氏)但没有得到任何结果。但是,如果我只搜索名称 (Name),我会得到结果。如果我转到 Magento->Customers->Manage Customers 并尝试使用全名进行搜索,一切正常。
此搜索在哪里实施?有什么问题?
我以前发现过这个。
如果您尝试在 Bill to / Ship to order 网格中搜索姓名 + 姓氏,您需要在名字和姓氏之间放置双 space,即:
不是:
John Smith
试试这个:
John Smith
唯一的区别是名字之间的双 space。我没看过,但我想 Magento 会用双 space 连接网格中的名称,或者它会查找中间名,如果不存在,则输出 space。
很奇怪,我知道!
这是用于更新数据库中现有记录的正确重写和脚本的解决方案:
这仅适用于网格,但它似乎符合我的要求。
protected function searchWithDoubleSpace($collection, $column)
{
if(!$value = trim($column->getFilter()->getValue()))
{
return $this;
}
//if there was a space input
elseif(preg_match('/ /', $value))
{
$revisedValue = str_replace(' ', ' ', $value); // replace a space with double space
$this->getCollection()->addAttributeToFilter($column->getData('index'), array(
array('like' => '%' . $value . '%'),
array('like' => '%' . $revisedValue.'%'))
); // search with both queries and includes results from both queries (OR)
}
else
{
$this->getCollection()->addAttributeToFilter($column->getData('index'), array('like' => '%'.$value.'%'));
}
return $this;
}
如果有 space 输入,则创建两个查询,一个按原样创建,另一个用双 space 代替单 space。最终得到两个查询的结果。
还有,别忘了在专栏中加入这段代码
'filter_condition_callback' => array($this, 'searchWithDoubleSpace')
我要去 Magento->Sales->Orders 并尝试在 'Bill to' 输入中搜索全名(名字姓氏)但没有得到任何结果。但是,如果我只搜索名称 (Name),我会得到结果。如果我转到 Magento->Customers->Manage Customers 并尝试使用全名进行搜索,一切正常。
此搜索在哪里实施?有什么问题?
我以前发现过这个。
如果您尝试在 Bill to / Ship to order 网格中搜索姓名 + 姓氏,您需要在名字和姓氏之间放置双 space,即:
不是:
John Smith
试试这个:
John Smith
唯一的区别是名字之间的双 space。我没看过,但我想 Magento 会用双 space 连接网格中的名称,或者它会查找中间名,如果不存在,则输出 space。
很奇怪,我知道!
这是用于更新数据库中现有记录的正确重写和脚本的解决方案:
这仅适用于网格,但它似乎符合我的要求。
protected function searchWithDoubleSpace($collection, $column)
{
if(!$value = trim($column->getFilter()->getValue()))
{
return $this;
}
//if there was a space input
elseif(preg_match('/ /', $value))
{
$revisedValue = str_replace(' ', ' ', $value); // replace a space with double space
$this->getCollection()->addAttributeToFilter($column->getData('index'), array(
array('like' => '%' . $value . '%'),
array('like' => '%' . $revisedValue.'%'))
); // search with both queries and includes results from both queries (OR)
}
else
{
$this->getCollection()->addAttributeToFilter($column->getData('index'), array('like' => '%'.$value.'%'));
}
return $this;
}
如果有 space 输入,则创建两个查询,一个按原样创建,另一个用双 space 代替单 space。最终得到两个查询的结果。
还有,别忘了在专栏中加入这段代码
'filter_condition_callback' => array($this, 'searchWithDoubleSpace')