ref #92092 Added currency validation (#219)

This commit is contained in:
Uryvskiy Dima 2023-09-27 17:05:31 +03:00 committed by GitHub
parent 31aafde3e5
commit 2d2708adbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 14 deletions

View File

@ -1,3 +1,6 @@
## v3.6.2
* Добавлена валидация валют при настройке модуля
## v3.6.1
* Добавлены тесты для новых версий PrestaShop

View File

@ -1 +1 @@
3.6.1
3.6.2

View File

@ -83,14 +83,12 @@ class RetailcrmSettingsValidator
public function validate($validateFromRequestOnly = false)
{
// check url and apiKey
$crmUrl = $this->settings->getValueWithStored('url');
$crmApiKey = $this->settings->getValueWithStored('apiKey');
if (!$validateFromRequestOnly || $this->settings->issetValue('url') || $this->settings->issetValue('apiKey')) {
if ($this->validateCrmAddress($this->settings->getValueWithStored('url'))
&& $this->validateCrmApiKey($this->settings->getValueWithStored('apiKey'))
) {
$this->validateApiCredentials(
$this->settings->getValueWithStored('url'),
$this->settings->getValueWithStored('apiKey')
);
if ($this->validateCrmAddress($crmUrl) && $this->validateCrmApiKey($crmApiKey)) {
$this->validateApiCredentials($crmUrl, $crmApiKey);
}
}
@ -304,12 +302,31 @@ class RetailcrmSettingsValidator
public function validateApiCredentials($url, $apiKey)
{
/** @var RetailcrmProxy|RetailcrmApiClientV5 $api */
$api = new RetailcrmProxy(
$url,
$apiKey
$api = new RetailcrmProxy($url, $apiKey);
return $this->validateApiVersion($api) && $this->validateApiAccess($api) && $this->validateCurrency($api);
}
private function validateCurrency($api)
{
$response = $api->sitesList();
if ($response instanceof RetailcrmApiResponse && $response->isSuccessful() && isset($response['sites'])) {
$site = current($response['sites']);
}
$currencyId = (int) Configuration::get('PS_CURRENCY_DEFAULT');
$isoCode = Db::getInstance()->getValue(
'SELECT `iso_code` FROM ' . _DB_PREFIX_ . 'currency WHERE `id_currency` = ' . $currencyId
);
return $this->validateApiVersion($api) && $this->validateApiAccess($api);
if (isset($site['currency']) && $site['currency'] !== $isoCode) {
$this->addError('apiKey', 'errors.currency');
return false;
}
return true;
}
/**

View File

@ -48,7 +48,7 @@ require_once dirname(__FILE__) . '/bootstrap.php';
class RetailCRM extends Module
{
const VERSION = '3.6.1';
const VERSION = '3.6.2';
const API_URL = 'RETAILCRM_ADDRESS';
const API_KEY = 'RETAILCRM_API_TOKEN';

File diff suppressed because one or more lines are too long