質問

We have opencart 1.5.5.1. With Journal IV Theme. We have modified the search box function to search on product model as well as product name. What we cannot understand is how to get the product model to appear in the dropdown search result suggestion list.

Any advice gratefully received, we are going insane over this. I can't offer any code snippets because I haven't even found where I'm supposed to edit the code for this yet :)

Edit Solved: journal.js references this controller :- serviceUrl: 'index.php?route=module/journal_cp/search_products'

so I tried replacing:

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

with

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

OK it's dirty but it's a start :)

original code in module/journal_cp/search_products for those that want to look:

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));
}
役に立ちましたか?

解決

Opencart search is based on jquery so as such you need to search in your themes custom.js or something like that and start from there. Well this is the most common setup but not necessarily your themes ones, although i can assure that search in opencart is based on jquery functions. If you can confirm that this is your setup also i can further assist you if needed.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top