Magento:如何修复客户名称搜索

Magento:如何修复客户名称搜索,magento,Magento,在Magento admin菜单Customers->Manage Customers下,如果字符串包含多个单词,我们将无法使用其名称搜索客户。在哪里可以找到执行此任务的核心代码?我们没有这个部分的分机 问题的例子: 如果我想搜索名为John Smith的客户,搜索“John Smith”不会返回任何结果。单独搜索“john”或“smith”是可行的,但它会显示任何包含“john”或“smith”的名称,与SQL查询类似,如%john%或如%smith%看起来您正在使用Magento 1.6版

在Magento admin菜单Customers->Manage Customers下,如果字符串包含多个单词,我们将无法使用其名称搜索客户。在哪里可以找到执行此任务的核心代码?我们没有这个部分的分机

问题的例子:


如果我想搜索名为John Smith的客户,搜索“John Smith”不会返回任何结果。单独搜索“john”或“smith”是可行的,但它会显示任何包含“john”或“smith”的名称,与SQL查询类似,
如%john%
如%smith%

看起来您正在使用Magento 1.6版

这是一个bug,已在1.7中修复

下面是需要修改的代码:app/code/core/Mage/Customer/Model/Resource/Customer/Collection.php

我发布了取自1.7版的代码:

Mage_Customer_Model_Resource_Customer_Collection    

    public function addNameToSelect()
    {
        $fields = array();
        $customerAccount = Mage::getConfig()->getFieldset('customer_account');
        foreach ($customerAccount as $code => $node) {
            if ($node->is('name')) {
                $fields[$code] = $code;
            }
        }

        $adapter = $this->getConnection();
        $concatenate = array();
        if (isset($fields['prefix'])) {
            $concatenate[] = $adapter->getCheckSql(
                '{{prefix}} IS NOT NULL AND {{prefix}} != \'\'',
                $adapter->getConcatSql(array('LTRIM(RTRIM({{prefix}}))', '\' \'')),
                '\'\'');
        }
        $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
        $concatenate[] = '\' \'';
        if (isset($fields['middlename'])) {
            $concatenate[] = $adapter->getCheckSql(
                '{{middlename}} IS NOT NULL AND {{middlename}} != \'\'',
                $adapter->getConcatSql(array('LTRIM(RTRIM({{middlename}}))', '\' \'')),
                '\'\'');
        }
        $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
        if (isset($fields['suffix'])) {
            $concatenate[] = $adapter
                    ->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'',
                $adapter->getConcatSql(array('\' \'', 'LTRIM(RTRIM({{suffix}}))')),
                '\'\'');
        }

        $nameExpr = $adapter->getConcatSql($concatenate);

        $this->addExpressionAttributeToSelect('name', $nameExpr, $fields);

        return $this;
    }