Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Add query_name parameter to facets (#30)
Browse files Browse the repository at this point in the history
* DOOF-5

* limit attr groups on query

* Fix pagination problem on newer PrestaShop themes

* Add query_name parameter to facets
  • Loading branch information
danidomen authored and ecoslado committed May 29, 2017
1 parent 0ab1f96 commit 910cdf5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
24 changes: 15 additions & 9 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ public function getDoofinderTermsOptions($only_facets=true){
}

public function searchOnApi($string,$page=1,$page_size=12,$timeout=8000,$filters = null,$return_facets = false){
$query_name = Tools::getValue('df_query_name',false);
$debug = Configuration::get('DF_DEBUG', null);
if (isset($debug) && $debug){
$this->debug('Search On API Start');
Expand All @@ -783,11 +784,15 @@ public function searchOnApi($string,$page=1,$page_size=12,$timeout=8000,$filters
include_once dirname(__FILE__) . '/lib/doofinder_api.php';
}
$df = new DoofinderApi($hash_id, $api_key,false,array('apiVersion'=>'5'));
$dfResults = $df->query($string, $page, array('rpp' => $page_size, // results per page
$queryParams = array('rpp' => $page_size, // results per page
'timeout' => $timeout, // timeout in milisecs
'types' => array( // types of item
'product',
), 'transformer'=>'dflayer', 'filter' => $filters));
), 'transformer'=>'dflayer', 'filter' => $filters);
if($query_name){
$queryParams['query_name'] = $query_name;
}
$dfResults = $df->query($string, $page, $queryParams);
}
catch(Exception $e){
$fail = true;
Expand Down Expand Up @@ -899,9 +904,9 @@ function cb($entry){
}

if($return_facets){
return array('total' => $dfResults->getProperty('total'),'result' => $result_properties, 'facets' => $dfResults->getFacets(), 'filters'=> $df->getFilters());
return array('total' => $dfResults->getProperty('total'),'result' => $result_properties, 'facets' => $dfResults->getFacets(), 'filters'=> $df->getFilters(),'df_query_name' => $dfResults->getProperty('query_name'));
}
return array('total' => $dfResults->getProperty('total'),'result' => $result_properties);
return array('total' => $dfResults->getProperty('total'),'result' => $result_properties,'df_query_name' => $dfResults->getProperty('query_name'));
}else{
return false;
}
Expand Down Expand Up @@ -949,16 +954,16 @@ public function generateSearch($returnToSearchController=false){
return $search;
}

return $this->generateFiltersBlock($search['facets'],$search['filters']);
return $this->generateFiltersBlock($search['facets'],$search['filters'],$search['df_query_name']);
}else{
return false;
}
}
}

public function generateFiltersBlock($facets,$filters){
public function generateFiltersBlock($facets,$filters,$query_name=false){
global $smarty;
if ($filter_block = $this->getFilterBlock($facets,$filters)) {
if ($filter_block = $this->getFilterBlock($facets,$filters,$query_name)) {
if ($filter_block['nbr_filterBlocks'] == 0)
return false;

Expand All @@ -977,7 +982,7 @@ public function generateFiltersBlock($facets,$filters){
return false;
}

public function getFilterBlock($facets,$filters){
public function getFilterBlock($facets,$filters,$query_name){
$cacheOptionsDoofinderFileName = _PS_CACHE_DIR_.'smarty/compile/OptionsDoofinderFileName-'.Context::getContext()->shop->id.'-'.Context::getContext()->language->id.'-'.hash_hmac('sha256', 'OptionsDoofinderFileName', 'cache').'-'.date('Ymd').'.html';
$optionsDoofinder = '';
if(file_exists($cacheOptionsDoofinderFileName)){
Expand Down Expand Up @@ -1028,7 +1033,8 @@ public function getFilterBlock($facets,$filters){
return array('options'=>$r_facets,
'facets'=>$facets,
'filters'=>$filters,
'nbr_filterBlocks' => 1);
'nbr_filterBlocks' => 1,
'df_query_name' => $query_name);


return false;
Expand Down
3 changes: 3 additions & 0 deletions js/doofinder_facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,9 @@ function reloadContent(params_plus)
n = '&n=' + option.value;
});
}
if(df_query_name != undefined){
data+= '&df_query_name='+df_query_name;
}
ajaxQuery = $.ajax(
{
type: 'POST',
Expand Down
1 change: 1 addition & 0 deletions views/templates/front/doofinder_facets.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<script type="text/javascript">
var current_friendly_url = '#';
var param_product_url = '';
var df_query_name = '{$df_query_name}';
</script>
<div id="layered_block_left" class="block">
<div class="block_content">
Expand Down

0 comments on commit 910cdf5

Please sign in to comment.