- 13 Out 2014, 09:34
#54848
Bom dia galera, o XML(free) abaixo utiliza VQmod e estou usando o opencart 1.5.6.4 o modulo(autocomplete) funciona perfeitamente, busca por nome do produto, modelo, só que eu queria buscar tb por palavras chaves, ou seja pelo campo TAG, já tentei de varias formas editar o XML abaixo para fazer um autocomplete da busca de produtos pela loja e não consegui, alguem poderia dar uma força ai?
Código: Selecionar todos
<?xml version="1.0" encoding="UTF-8"?>
<modification>
<id>Opencart Live Search</id>
<version>1.1.0</version>
<author>Kardos Sándor / sandor.kardos@cantinart.hu</author>
<file name="catalog/controller/product/search.php">
<operation>
<search position="replace" offset="1"><![CDATA[
$this->response->setOutput($this->render());
]]></search>
<add><![CDATA[
$this->response->setOutput($this->render());}
function livesearch() {
$search = $this->request->get['search'];
$this->load->model('catalog/product');
$this->load->model('tool/image');
$this->load->model('setting/setting');
$limit = $this->config->get('ls_limit_results');
$more = $this->config->get('ls_more');
if ($more=="") $more = "...";
$noresults = $this->config->get('ls_noresults');
if ($noresults=="") $noresults = "No results";
$images = $this->config->get('ls_images');
$prices = $this->config->get('ls_prices');
$model = $this->config->get('ls_model');
$searchindesc = ( $this->config->get('ls_searchindesc') ) ? 1 : 0;
$data = array(
'filter_name' => $search,
'filter_description' => $searchindesc,
'start' => 0,
'limit' => $limit
);
$products = $this->model_catalog_product->getProducts($data);
$i = 0;
foreach ($products as $product) {
$results[$i]["name"] = $product["name"];
if ($model) {
$results["$i"]["model"] = $product["model"];
}
$results[$i]["img"] = "";
if ($product['image'] && $images==1) {
$results[$i]["img"] = $this->model_tool_image->resize(
$product['image'],
$this->config->get('config_image_product_width'),
$this->config->get('config_image_product_height')
);
}
if ($prices) {
$results[$i]["price"] = $this->currency->format( $this->tax->calculate( $product['price'], $product['tax_class_id'], $this->config->get('config_tax') ) );
if ($product['special']) {
$results[$i]["price"] = '<strike>' . $results[$i]["price"] . '</strike> ' . $this->currency->format( $this->tax->calculate( $product['special'], $product['tax_class_id'], $this->config->get('config_tax') ) );
}
}
$results[$i]["href"] = $this->url->link('product/product', 'product_id=' . $product['product_id']);
$i++;
}
if (!isset($results)) {
$results = array();
$results[] = array(
"img" => "",
"name" => '<p class="more">' . $noresults . '</p>',
"href" => '#'
);
} else {
if (count($results) >= $limit) {
$results[] = array(
"img" => "",
"name" => '<p class="more">'.htmlentities($more, ENT_QUOTES, 'UTF-8').'</p>',
"href" => $this->url->link('product/search', 'description=' . $searchindesc . '&search=' . $search)
);
}
}
echo json_encode($results);
}
]]></add>
</operation>
</file>
<file name="catalog/view/theme/default/template/common/footer.tpl">
<operation>
<search position="replace"><![CDATA[
</body></html>
]]></search>
<add><![CDATA[
<script>
$(function(){
var i = (!!$("#livesearch").length ? $("#livesearch") : $("<ul id='livesearch'></ul>") ), s = $("#header [name=search]");
function repositionLivesearch() { i.css({ top: (s.offset().top+s.outerHeight()), left:s.offset().left, width: s.outerWidth() }); }
$(window).resize(function(){ repositionLivesearch(); });
s.keyup(function(e){
switch (e.keyCode) {
case 13:
$(".active", i).length && (window.location = $(".active a", i).attr("href"));
return false;
break;
case 40:
($(".active", i).length ? $(".active", i).removeClass("active").next().addClass("active") : $("li:first", i).addClass("active"))
return false;
break;
case 38:
($(".active", i).length ? $(".active", i).removeClass("active").prev().addClass("active") : $("li:last", i).addClass("active"))
return false;
break;
default:
var query = s.val();
if (query.length > 2) {
$.getJSON(
"<?php echo HTTP_SERVER; ?>?route=product/search/livesearch&search=" + query,
function(data) {
i.empty();
$.each(data, function( k, v ) { i.append("<li><a href='"+v.href+"'><img src='"+v.img+"' alt='"+v.name+"'><span>"+v.name+(v.model ? "<small>"+v.model+"</small>" : '')+"</span><em>"+(v.price ? v.price : '')+"</em></a></li>") });
i.remove(); $("body").prepend(i); repositionLivesearch();
}
);
} else {
i.empty();
}
}
}).blur(function(){ setTimeout(function(){ i.hide() },500); }).focus(function(){ repositionLivesearch(); i.show(); });
});
</script>
</body></html>
]]></add>
</operation>
</file>
<file name="admin/view/template/setting/setting.tpl">
<operation>
<search position="replace"><![CDATA[<?php echo $tab_server; ?>]]></search>
<add><![CDATA[<?php echo $tab_server; ?></a><a href="#tab-livesearch">Live Search</a>]]></add>
</operation>
<operation>
<search position="replace"><![CDATA[
</form>
]]></search>
<add><![CDATA[
<div id="tab-livesearch">
<table class="form">
<tr>
<td>Limit results:</td>
<td><input type="text" name="ls_limit_results" value="<?php echo $ls_limit_results; ?>" /></td>
</tr>
<tr>
<td>Text for link to more results:</td>
<td><input type="text" name="ls_more" value="<?php echo $ls_more; ?>" /></td>
</tr>
<tr>
<td>Display images:</td>
<td>
<?php
if ($ls_images==1) {
?>
<input type="radio" name="ls_images" value="1" checked="checked" /> Yes
<input type="radio" name="ls_images" value="0" /> No
<?php
} else {
?>
<input type="radio" name="ls_images" value="1" /> Yes
<input type="radio" name="ls_images" value="0" checked="checked" /> No
<?php
}
?>
</td>
</tr>
<tr>
<td>Display prices:</td>
<td>
<?php
if ($ls_prices==1) {
?>
<input type="radio" name="ls_prices" value="1" checked="checked" /> Yes
<input type="radio" name="ls_prices" value="0" /> No
<?php
} else {
?>
<input type="radio" name="ls_prices" value="1" /> Yes
<input type="radio" name="ls_prices" value="0" checked="checked" /> No
<?php
}
?>
</td>
</tr>
<tr>
<td>Display model:</td>
<td>
<?php
if ($ls_model==1) {
?>
<input type="radio" name="ls_model" value="1" checked="checked" /> Yes
<input type="radio" name="ls_model" value="0" /> No
<?php
} else {
?>
<input type="radio" name="ls_model" value="1" /> Yes
<input type="radio" name="ls_model" value="0" checked="checked" /> No
<?php
}
?>
</td>
</tr>
<tr>
<td>Search in description:</td>
<td>
<?php
if ($ls_searchindesc==1) {
?>
<input type="radio" name="ls_searchindesc" value="1" checked="checked" /> Yes
<input type="radio" name="ls_searchindesc" value="0" /> No
<?php
} else {
?>
<input type="radio" name="ls_searchindesc" value="1" /> Yes
<input type="radio" name="ls_searchindesc" value="0" checked="checked" /> No
<?php
}
?>
</td>
</tr>
<tr>
<td>Text for no results:</td>
<td><input type="text" name="ls_noresults" value="<?php echo $ls_noresults; ?>" /></td>
</tr>
</table>
</div>
</form>
]]></add>
</operation>
</file>
<file name="admin/controller/setting/setting.php">
<operation>
<search position="replace"><![CDATA[
$this->template = 'setting/setting.tpl';
]]></search>
<add><![CDATA[
if (isset($this->request->post['ls_limit_results'])) {
$this->data['ls_limit_results'] = $this->request->post['ls_limit_results'];
} else {
$this->data['ls_limit_results'] = $this->config->get('ls_limit_results');
}
if (isset($this->request->post['ls_more'])) {
$this->data['ls_more'] = $this->request->post['ls_more'];
} else {
$this->data['ls_more'] = $this->config->get('ls_more');
}
if (isset($this->request->post['ls_images'])) {
$this->data['ls_images'] = $this->request->post['ls_images'];
} else {
$this->data['ls_images'] = $this->config->get('ls_images');
}
if (isset($this->request->post['ls_prices'])) {
$this->data['ls_prices'] = $this->request->post['ls_prices'];
} else {
$this->data['ls_prices'] = $this->config->get('ls_prices');
}
if (isset($this->request->post['ls_noresults'])) {
$this->data['ls_noresults'] = $this->request->post['ls_noresults'];
} else {
$this->data['ls_noresults'] = $this->config->get('ls_noresults');
}
if (isset($this->request->post['ls_searchindesc'])) {
$this->data['ls_searchindesc'] = $this->request->post['ls_searchindesc'];
} else {
$this->data['ls_searchindesc'] = $this->config->get('ls_searchindesc');
}
if (isset($this->request->post['ls_model'])) {
$this->data['ls_model'] = $this->request->post['ls_model'];
} else {
$this->data['ls_model'] = $this->config->get('ls_model');
}
$this->template = 'setting/setting.tpl';
]]></add>
</operation>
</file>
</modification>