无法在Magento Admin Sales上按客户全名搜索


Unable to search by customer full name on Magento Admin Sales

我要去Magento->Sales->Orders,并尝试在"Bill to"输入中搜索全名(name Surname),但没有结果。但如果我只搜索名称,我会得到结果。如果我去Magento->客户->管理客户并尝试使用全名进行搜索,一切都会正常工作。

这种搜索是在哪里实现的?怎么了?

我以前发现过这种情况。

如果您尝试在收货方/收货方订单网格中搜索姓名+姓氏,则需要在名字和姓氏之间加一个双空格,即:

非:

John Smith

试试这个:

John  Smith

唯一的区别是名字之间有两个空格。我还没有看,但我想象Magento用一个双空格连接网格中的名称,或者它寻找一个中间名称,如果不存在,则输出一个空格。

奇怪,我知道!

以下是更新DB:中现有记录的正确重写和脚本的解决方案

https://magento.stackexchange.com/questions/80196/magento-1-9-2-0-table-sales-flat-order-grid-contains-extra-space-in-customer

这只适用于网格,但它似乎可以满足我的要求。

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;
}

如果有空格输入,则创建两个查询,一个按原样创建,另一个用双空格代替单空格。最后从两个查询中获得结果。

另外,不要忘记在列中添加这段代码

'filter_condition_callback' => array($this, 'searchWithDoubleSpace')