0

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

问题示例:

如果我想搜索名为 John Smith 的客户,搜索“john smith”不会返回任何结果。分别搜索“john”或“smith”可以工作,但它会显示任何包含“john”或“smith”的名称,类似于 SQL 查询,LIKE %john%LIKE %smith%.

4

1 回答 1

1

看起来您使用的是 Magento 1.6 版

这是一个错误,已在 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;
    }
于 2012-07-29T10:45:53.800 回答