Skip to content

Commit

Permalink
fix: Added more checks to cover some special cases (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmolinacano authored Apr 22, 2024
1 parent 335ddad commit 79b7904
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
3 changes: 2 additions & 1 deletion controllers/front/landing.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ private function getLandingData($name, $id_shop, $id_lang, $id_currency)

private function getApiCall($name, $hashid)
{
$apikey = explode('-', Configuration::get('DF_API_KEY'))[1];
$apikey = explode('-', Configuration::get('DF_API_KEY'));
$apikey = end($apikey);
$region = Configuration::get('DF_REGION');

$api = new DoofinderApiLanding($hashid, $apikey, $region);
Expand Down
14 changes: 9 additions & 5 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class Doofinder extends Module
const DOOMANAGER_URL = 'https://admin.doofinder.com';
const GS_SHORT_DESCRIPTION = 1;
const GS_LONG_DESCRIPTION = 2;
const VERSION = '4.7.27';
const VERSION = '4.7.28';
const YES = 1;
const NO = 0;

public function __construct()
{
$this->name = 'doofinder';
$this->tab = 'search_filter';
$this->version = '4.7.27';
$this->version = '4.7.28';
$this->author = 'Doofinder (http://www.doofinder.com)';
$this->ps_versions_compliancy = ['min' => '1.5', 'max' => _PS_VERSION_];
$this->module_key = 'd1504fe6432199c7f56829be4bd16347';
Expand Down Expand Up @@ -1402,7 +1402,8 @@ public function searchOnApi(
$product_pool_attributes = [];
$product_pool_ids = [];
foreach ($dfResultsArray as $entry) {
if ($entry['type'] == 'product') {
// For unknown reasons, it can sometimes be defined as 'products' in plural
if (in_array($entry['type'], ['product', 'products'])) {
if (strpos($entry['id'], 'VAR-') === false) {
$product_pool_ids[] = (int) pSQL($entry['id']);
} else {
Expand Down Expand Up @@ -1840,11 +1841,14 @@ public function getLanguageByHashid($hashid)
*/
public function getLanguageIdByLocale($locale)
{
$sanitized_locale = pSQL(strtolower($locale));

return Db::getInstance()
->getValue(
'SELECT `id_lang` FROM `' . _DB_PREFIX_ . 'lang`
WHERE `locale` = \'' . pSQL(strtolower($locale)) . '\'
OR `language_code` = \'' . pSQL(strtolower($locale)) . '\''
WHERE `locale` = \'' . $sanitized_locale . '\'
OR `language_code` = \'' . $sanitized_locale . '\'
OR `iso_code` = \'' . $sanitized_locale . '\''
);
}

Expand Down
13 changes: 3 additions & 10 deletions lib/doofinder_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,13 @@ class DoofinderApi
* -'apiVersion' (default: '4')=> the api of the search server to query
* -'restrictedRequest'(default: $_REQUEST): =>restrict request object
* to look for params when unserializing. either 'get' or 'post'
*
* @throws DoofinderException if $hashid is not a md5 hash or api is no 4, 3.0 or 1.0
*/
public function __construct($hashid, $api_key, $fromParams = false, $init_options = [])
{
$zone_key_array = explode('-', $api_key);

if (2 === count($zone_key_array)) {
$this->api_key = $zone_key_array[1];
$this->zone = $zone_key_array[0];
$this->url = 'https://' . $this->zone . self::URL_SUFFIX;
} else {
throw new DoofinderException('API Key is no properly set.');
}
$this->api_key = end($zone_key_array);
$this->zone = Configuration::get('DF_REGION');
$this->url = 'https://' . $this->zone . self::URL_SUFFIX;

if (array_key_exists('prefix', $init_options)) {
$this->paramsPrefix = $init_options['prefix'];
Expand Down

0 comments on commit 79b7904

Please sign in to comment.