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

Commit

Permalink
New doofinder-php lib and avoiding some notices.
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoslado committed May 3, 2016
1 parent 3c6fbbf commit 8f89922
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Binary file modified dist/doofinder-p1.5-latest.zip
Binary file not shown.
7 changes: 6 additions & 1 deletion doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ protected function _updateConfiguration()
// Cleaning script tags
if ('DOOFINDER_SCRIPT_' === $prefix){
$value = str_replace('<script type="text/javascript">', '', Tools::getValue($optname));
$value = str_replace("<script type='text/javascript'>", '', Tools::getValue($optname));
$value = str_replace('</script>', '', $value);
}
else{
Expand Down Expand Up @@ -1003,7 +1004,7 @@ public function ajaxCall() {
$title = '';
$keywords = '';

if (is_array($filter_block['title_values']))
if (isset($filter_block) && is_array($filter_block['title_values']))
foreach ($filter_block['title_values'] as $key => $val) {
$title .= ' > ' . $key . ' ' . implode('/', $val);
$keywords .= $key . ' ' . implode('/', $val) . ', ';
Expand Down Expand Up @@ -1058,6 +1059,10 @@ public function ajaxCall() {
else{
$product_list = $smarty->fetch(_PS_THEME_DIR_ . 'product-list.tpl');
}
// To avoid Notice
if (!isset($filter_block)){
$filter_block = array('current_friendly_url' => '');
}
$vars = array(
//'filtersBlock' => utf8_encode($this->generateFiltersBlock($search['facets'],$search['filters'])),
'productList' => utf8_encode($product_list),
Expand Down
23 changes: 9 additions & 14 deletions lib/doofinder_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class DoofinderApi{
const DEFAULT_RPP = 10;
const DEFAULT_PARAMS_PREFIX = 'dfParam_';
const DEFAULT_API_VERSION = '4';
const VERSION = '5.2.3';

private $api_key = null; // user API_KEY
private $hashid = null; // hashid of the doofinder account
Expand Down Expand Up @@ -70,7 +71,7 @@ function __construct($hashid, $api_key, $fromParams=false, $init_options = array
if(2 === count($zone_key_array)){
$this->api_key = $zone_key_array[1];
$this->zone = $zone_key_array[0];
$this->url = "http://" . $this->zone . self::URL_SUFFIX;
$this->url = "https://" . $this->zone . self::URL_SUFFIX;
} else {
throw new DoofinderException("API Key is no properly set.");
}
Expand Down Expand Up @@ -156,14 +157,11 @@ private function reqHeaders(){
return $headers;
}

private function apiCall($params,$method='search'){
private function apiCall($entry_point='search', $params=array()){
$params['hashid'] = $this->hashid;
$args = http_build_query($this->sanitize($params)); // remove any null value from the array
switch($method){
case 'search': $url = $this -> url . '/' . $this->apiVersion . '/search?' . $args;break;
case 'options': $url = $this -> url . '/' . $this->apiVersion . '/options/' . $this->hashid; break;
default: $url = $this -> url . '/' . $this->apiVersion . '/search?' . $args; break;
}

$url = $this->url.'/'.$this->apiVersion.'/'.$entry_point.'?'.$args;

$session = curl_init($url);
curl_setopt($session, CURLOPT_CUSTOMREQUEST, 'GET');
Expand All @@ -175,16 +173,13 @@ private function apiCall($params,$method='search'){
curl_close($session);

if (floor($httpCode / 100) == 2) {
if($method=='options'){
return $response;
}
return new DoofinderResults($response);
return $response;
}
throw new DoofinderException($httpCode.' - '.$response, $httpCode);
}

public function getOptions(){
return $this->apiCall('', 'options');
return $this->apiCall('options/'.$this->hashid);
}

/**
Expand Down Expand Up @@ -233,11 +228,11 @@ public function query($query=null, $page=null, $options = array()){
{
$filter = $params['filter'];
unset($params['filter']);
$dfResults = $this->apiCall($params);
$dfResults = new DoofinderResults($this->apiCall('search', $params));
$params['query_name'] = $dfResults->getProperty('query_name');
$params['filter'] = $filter;
}
$dfResults = $this->apiCall($params);
$dfResults = new DoofinderResults($this->apiCall('search', $params));
$this->page = $dfResults->getProperty('page');
$this->total = $dfResults->getProperty('total');
$this->search_options['query'] = $dfResults->getProperty('query');
Expand Down

0 comments on commit 8f89922

Please sign in to comment.