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

问题描述 投票:2回答:3

我要去Magento-> Sales-> Orders并尝试在'Bill to'输入中搜索全名(Name Surname)并且没有结果。但如果我只搜索姓名(姓名),我会得到结果。如果我去Magento->客户 - >管理客户并尝试使用全名搜索都能正常工作。

这个搜索实施的地方?有什么问题?

php magento search e-commerce enterprise
3个回答
2
投票

我以前发现过这个。

如果您尝试在Bill to / Ship to order网格中搜索name + surname,则需要在名字和姓氏之间加上一个双重空格,即:

不:

John Smith

试试这个:

John  Smith

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

很奇怪,我知道!


1
投票

0
投票

这只适用于网格,但它似乎做我想要的。

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')
© www.soinside.com 2019 - 2024. All rights reserved.