0

我们有 opencart 1.5.5.1。以杂志 IV 为主题。我们修改了搜索框功能,可以搜索产品型号和产品名称。我们无法理解的是如何让产品型号出现在下拉搜索结果建议列表中。

感激地收到任何建议,我们都会为此发疯。我不能提供任何代码片段,因为我什至还没有找到我应该在哪里编辑代码:)

编辑解决:journal.js 引用了这个控制器:- serviceUrl: 'index.php?route=module/journal_cp/search_products'

所以我尝试替换:

'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),

'name'       => strip_tags(html_entity_decode($result['model'], ENT_QUOTES, 'UTF-8')).' - ' .strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),

好的,它很脏,但这是一个开始:)

module/journal_cp/search_products 中的原始代码供那些想要查看的人使用:

public function search_products() {
    $json = array();

    if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_model']) || isset($this->request->get['filter_category_id'])) {
        $this->load->model('catalog/product');
        // $this->load->model('catalog/option');

        if (isset($this->request->get['filter_name'])) {
            $filter_name = $this->request->get['filter_name'];
        } else {
            $filter_name = '';
        }

        if (isset($this->request->get['filter_model'])) {
            $filter_model = $this->request->get['filter_model'];
        } else {
            $filter_model = '';
        }

        if (isset($this->request->get['limit'])) {
            $limit = $this->request->get['limit'];
        } else {
            $limit = 20;
        }

        $data = array(
            'filter_name'  => $filter_name,
            'filter_model' => $filter_model,
            'start'        => 0,
            'limit'        => $limit
        );

        $results = $this->model_catalog_product->getProducts($data);

        foreach ($results as $result) {
            $option_data = array();

        $json[] = array(
                'product_id' => $result['product_id'],
                'name'       => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')),
                'model'      => $result['model'],
                'option'     => $option_data,
                'price'      => $result['price'],
                'href'       => html_entity_decode($this->url->link('product/product', '&product_id=' . $result['product_id']), ENT_QUOTES, 'UTF-8')
            );
        }
    }

    $this->response->setOutput(json_encode($json));
}
4

1 回答 1

0

Opencart 搜索基于 jquery,因此您需要在主题 custom.js 或类似内容中进行搜索,然后从那里开始。好吧,这是最常见的设置,但不一定是您的主题设置,尽管我可以保证在 opencart 中的搜索是基于 jquery 函数的。如果您可以确认这是您的设置,我还可以在需要时为您提供进一步的帮助。

于 2014-02-08T18:01:11.433 回答