Etendre la recherche
2 messages
• Page 1 sur 1
Etendre la recherche
Bonjour,
J'utilise le module Auto-Suggestion Search box v1.0 ( module qui utilise JQuery UI autocomplete ) sous licence GNU GPL.
Ca marche très bien mais j'aimerais pouvoir étendre la recherche un peu comme expliqué dans ce sujet
http://forum.opencart-france.com/post1954.html?hilit=etendre#p1954.
Idéalement, il faudrait que lorsque l'utilisateur tape un mot-clé, la recherche se fasse sur le nom du produit, le modèle, la catégorie, le fabricant, etc.
Je ne sais pas comment m'y prendre.
Voici le catalog/controller/module/search_suggestion.php :
le catalog/controller/product/search_json.php
et le fichier search_json.tpl dans catalog/view :
Je pense que je doit modifier la fonction getProductByKeywords dans le fichier catalog/model/catalog/product.php mais je ne suis pas sûr. Quelqu'un peut-il m'aider, svp ?
Pour info, le modèle et la description sont bien pris en compte dans a recherche et c'est seulement dans la liste auto du champs de recherche que les produits correspondants n'apparaissent pas.
Par contre, le nom d'un faricant, etc ne donnent pas de résultat.
J'utilise le module Auto-Suggestion Search box v1.0 ( module qui utilise JQuery UI autocomplete ) sous licence GNU GPL.
Ca marche très bien mais j'aimerais pouvoir étendre la recherche un peu comme expliqué dans ce sujet
http://forum.opencart-france.com/post1954.html?hilit=etendre#p1954.
Idéalement, il faudrait que lorsque l'utilisateur tape un mot-clé, la recherche se fasse sur le nom du produit, le modèle, la catégorie, le fabricant, etc.
Je ne sais pas comment m'y prendre.
Voici le catalog/controller/module/search_suggestion.php :
- Code: Tout sélectionner
<?php
class ControllerModuleSearchSuggestion extends Controller {
protected function index() {
//########################################################################
// Module: Search Autocomplete
//########################################################################
$this->data['search_json'] = HTTP_SERVER . 'index.php?route=product/search_json';
//########################################################################
// Module: Search Autocomplete
//########################################################################
$this->id = 'search_suggestion';
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/search_suggestion.tpl')) {
$this->template = $this->config->get('config_template') . '/template/module/search_suggestion.tpl';
} else {
$this->template = 'default/template/module/search_suggestion.tpl';
}
$this->render();
}
}
?>
le catalog/controller/product/search_json.php
- Code: Tout sélectionner
<?php
class ControllerProductSearchJson extends Controller {
public function index() {
$this->language->load('product/search_json');
$url = '';
if (isset($this->request->get['keyword'])) {
$url .= '&keyword=' . $this->request->get['keyword'];
}
if (isset($this->request->get['category3_id'])) {
$url .= '&category3_id=' . $this->request->get['category3_id'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['model'])) {
$url .= '&model=' . $this->request->get['model'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
if (isset($this->request->get['sort'])) {
$sort = $this->request->get['sort'];
} else {
$sort = 'p.sort_order';
}
if (isset($this->request->get['order'])) {
$order = $this->request->get['order'];
} else {
$order = 'ASC';
}
if (isset($this->request->get['keyword'])) {
$this->data['keyword'] = $this->request->get['keyword'];
} else {
$this->data['keyword'] = '';
}
if (isset($this->request->get['category3_id'])) {
$this->data['category3_id'] = $this->request->get['category3_id'];
} else {
$this->data['category3_id'] = '';
}
$this->load->model('catalog/category3');
$this->data['categories3'] = $this->getCategories3(0);
if (isset($this->request->get['description'])) {
$this->data['description'] = $this->request->get['description'];
} else {
$this->data['description'] = '';
}
if (isset($this->request->get['model'])) {
$this->data['model'] = $this->request->get['model'];
} else {
$this->data['model'] = '';
}
$json = array();
$this->data['products'] = array();
if (isset($this->request->get['keyword'])) {
$this->load->model('catalog/product');
$product_total = $this->model_catalog_product->getTotalProductsByKeyword($this->request->get['keyword'], isset($this->request->get['category3_id']) ? $this->request->get['category3_id'] : '', isset($this->request->get['description']) ? $this->request->get['description'] : '', isset($this->request->get['model']) ? $this->request->get['model'] : '');
$product_tag_total = $this->model_catalog_product->getTotalProductsByTag($this->request->get['keyword'], isset($this->request->get['category3_id']) ? $this->request->get['category3_id'] : '');
$product_total = max($product_total, $product_tag_total);
$json['total_products'] = $product_total;
if ($product_total) {
$url = '';
if (isset($this->request->get['category3_id'])) {
$url .= '&category3_id=' . $this->request->get['category3_id'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['model'])) {
$url .= '&model=' . $this->request->get['model'];
}
$this->load->model('catalog/review');
$this->load->model('tool/seo_url');
$this->load->model('tool/image');
$this->data['button_add_to_cart'] = $this->language->get('button_add_to_cart');
$results = $this->model_catalog_product->getProductsByKeyword($this->request->get['keyword'], isset($this->request->get['category3_id']) ? $this->request->get['category3_id'] : '', isset($this->request->get['description']) ? $this->request->get['description'] : '', isset($this->request->get['model']) ? $this->request->get['model'] : '', $sort, $order, 0, 5);
$tag_results = $this->model_catalog_product->getProductsByTag($this->request->get['keyword'], isset($this->request->get['category3_id']) ? $this->request->get['category3_id'] : '', $sort, $order, 0, 5);
foreach ($results as $key => $value) {
$tag_results[$value['product_id']] = $results[$key];
}
//$product_total = count($tag_results);
foreach ($tag_results as $result) {
if ($this->config->get('config_review')) {
$rating = $this->model_catalog_review->getAverageRating($result['product_id']);
} else {
$rating = false;
}
$special = FALSE;
$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
if ($discount) {
$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
if ($special) {
$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
}
}
$this->data['products'][] = array(
'name' => $result['name'],
'model' => $result['model'],
'price' => $price,
'href' => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&keyword=' . $this->request->get['keyword'] . $url . '&product_id=' . $result['product_id']),
);
}
$url = '';
if (isset($this->request->get['keyword'])) {
$url .= '&keyword=' . $this->request->get['keyword'];
}
if (isset($this->request->get['category3_id'])) {
$url .= '&category3_id=' . $this->request->get['category3_id'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['model'])) {
$url .= '&model=' . $this->request->get['model'];
}
if (isset($this->request->get['page'])) {
$url .= '&page=' . $this->request->get['page'];
}
$this->data['sorts'] = array();
$this->data['sorts'][] = array(
'text' => $this->language->get('text_default'),
'value' => 'p.sort_order-ASC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=p.sort_order&order=ASC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_name_asc'),
'value' => 'pd.name-ASC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=pd.name&order=ASC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_name_desc'),
'value' => 'pd.name-DESC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=pd.name&order=DESC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_price_asc'),
'value' => 'p.price-ASC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=p.price&order=ASC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_price_desc'),
'value' => 'p.price-DESC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=p.price&order=DESC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_rating_desc'),
'value' => 'rating-DESC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=rating&order=DESC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_rating_asc'),
'value' => 'rating-ASC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=rating&order=ASC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_model_asc'),
'value' => 'p.model-ASC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=p.model&order=ASC'
);
$this->data['sorts'][] = array(
'text' => $this->language->get('text_model_desc'),
'value' => 'p.model-DESC',
'href' => HTTP_SERVER . 'index.php?route=product/search' . $url . '&sort=p.model&order=DESC'
);
$url = '';
if (isset($this->request->get['keyword'])) {
$url .= '&keyword=' . $this->request->get['keyword'];
}
if (isset($this->request->get['category3_id'])) {
$url .= '&category3_id=' . $this->request->get['category3_id'];
}
if (isset($this->request->get['description'])) {
$url .= '&description=' . $this->request->get['description'];
}
if (isset($this->request->get['model'])) {
$url .= '&model=' . $this->request->get['model'];
}
if (isset($this->request->get['sort'])) {
$url .= '&sort=' . $this->request->get['sort'];
}
if (isset($this->request->get['order'])) {
$url .= '&order=' . $this->request->get['order'];
}
$this->data['sort'] = $sort;
$this->data['order'] = $order;
}
}
if(empty($this->data['products']))
{
$this->data['products'][] = array(
'name' => $this->language->get('text_no_result'),
'model' => '',
'price' => '',
'href' => ''
);
}
elseif($json['total_products'] > count($this->data['products']))
{
$remainder_cnt = $json['total_products'] - count($this->data['products']);
if($remainder_cnt > 0)
{
$this->data['products'][] = array(
'name' => $remainder_cnt. ' more results',
'model' => '',
'price' => '',
'href' => HTTP_SERVER . 'index.php?route=product/search&keyword='.$this->request->get['keyword'].'&category3_id='.$this->request->get['category3_id']
);
}
}
$json['result'] = $this->data['products'];
$this->load->library('json');
$this->response->setOutput($this->request->get['callback'].'('. Json::encode($json).')');
}
private function getCategories3($parent_id, $level = 0) {
$level++;
$data = array();
$results = $this->model_catalog_category3->getCategories3($parent_id);
foreach ($results as $result) {
$data[] = array(
'category3_id' => $result['category3_id'],
'name' => str_repeat(' ', $level) . $result['name']
);
$children = $this->getCategories3($result['category3_id'], $level);
if ($children) {
$data = array_merge($data, $children);
}
}
return $data;
}
}
?>
et le fichier search_json.tpl dans catalog/view :
- Code: Tout sélectionner
<style type="text/css">
.ui-menu-item{
text-align:left;
}
</style>
<script type="text/javascript"><!--
//########################################################################
// Module: Search Autocomplete
//########################################################################
$(document).ready(function(){
$( "#filter_keyword" ).autocomplete({
source: function(request, response){
$.ajax({
url: "<?php echo $search_json;?>",
dataType: "jsonp",
data: {
keyword: request.term,
category3_id: $("#filter_category3_id").val()
},
success: function(data) {
response( $.map( data.result, function(item){
return {
label: item.name,
desc: item.price,
value: item.href
}
}));
}
});
},
focus: function(event, ui){
return false;
},
select: function(event, ui){
if(ui.item.value == ""){
return false;
}else{
location.href=ui.item.value;
return false;
}
},
open: function() {
$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
},
close: function() {
$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
}
}).data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" )
.data( "item.autocomplete", item )
.append( "<a>" + item.label + "<br>" + item.desc + "</a>" )
.appendTo( ul );
};
})
//########################################################################
// Module: Search Autocomplete
//########################################################################
//--></script>
Je pense que je doit modifier la fonction getProductByKeywords dans le fichier catalog/model/catalog/product.php mais je ne suis pas sûr. Quelqu'un peut-il m'aider, svp ?
Pour info, le modèle et la description sont bien pris en compte dans a recherche et c'est seulement dans la liste auto du champs de recherche que les produits correspondants n'apparaissent pas.
Par contre, le nom d'un faricant, etc ne donnent pas de résultat.
Version 1.4.9fr
Template Green-store modifié
Hébergeur 1and1.fr
Template Green-store modifié
Hébergeur 1and1.fr
-
jeromec - Messages: 52
- Inscrit le: 21 Oct 2010, 21:31
Re: Etendre la recherche
Bonjour,
Je n'arrive pas à m'en sortir avec ce problème.
Quelqu'un pourrait-il expliquer dans ce sujet comment fonctionne le champs de recherche dans le header dans la version 1.4.9 d'OpenCart (sans "search suggestion", etc).
Merci
Je n'arrive pas à m'en sortir avec ce problème.
Quelqu'un pourrait-il expliquer dans ce sujet comment fonctionne le champs de recherche dans le header dans la version 1.4.9 d'OpenCart (sans "search suggestion", etc).
Merci
Version 1.4.9fr
Template Green-store modifié
Hébergeur 1and1.fr
Template Green-store modifié
Hébergeur 1and1.fr
-
jeromec - Messages: 52
- Inscrit le: 21 Oct 2010, 21:31
2 messages
• Page 1 sur 1
Qui est en ligne ?
Utilisateur(s) parcourant actuellement ce forum : Aucun utilisateur inscrit et 1 invité