From 79b79042ee39bd86cf4d1bfe320344be67dc0e37 Mon Sep 17 00:00:00 2001 From: David Molina Cano <128705267+davidmolinacano@users.noreply.github.com> Date: Mon, 22 Apr 2024 17:01:46 +0200 Subject: [PATCH] fix: Added more checks to cover some special cases (#204) --- controllers/front/landing.php | 3 ++- doofinder.php | 14 +++++++++----- lib/doofinder_api.php | 13 +++---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/controllers/front/landing.php b/controllers/front/landing.php index 8a6e6ce..b0c82ce 100644 --- a/controllers/front/landing.php +++ b/controllers/front/landing.php @@ -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); diff --git a/doofinder.php b/doofinder.php index 7e125b9..f41f2a1 100644 --- a/doofinder.php +++ b/doofinder.php @@ -32,7 +32,7 @@ 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; @@ -40,7 +40,7 @@ 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'; @@ -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 { @@ -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 . '\'' ); } diff --git a/lib/doofinder_api.php b/lib/doofinder_api.php index 632c4e6..80ce8dc 100644 --- a/lib/doofinder_api.php +++ b/lib/doofinder_api.php @@ -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'];