我们有 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));
}