mirror of
https://github.com/retailcrm/prestashop-module.git
synced 2025-03-01 19:03:14 +03:00
parent
31aafde3e5
commit
2d2708adbe
@ -1,3 +1,6 @@
|
||||
## v3.6.2
|
||||
* Добавлена валидация валют при настройке модуля
|
||||
|
||||
## v3.6.1
|
||||
* Добавлены тесты для новых версий PrestaShop
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
Loading…
x
Reference in New Issue
Block a user