Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref #92092 Added currency validation #219

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## v3.6.2
* Добавлена валидация валют при настройке модуля

## v3.6.1
* Добавлены тесты для новых версий PrestaShop

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.1
3.6.2
39 changes: 28 additions & 11 deletions retailcrm/lib/settings/RetailcrmSettingsValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,12 @@ public function getSuccess()
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);
}
}

Expand Down Expand Up @@ -304,12 +302,31 @@ private function validateMappingSelected($values)
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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion retailcrm/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

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';
Expand Down
2 changes: 1 addition & 1 deletion retailcrm/views/js/app.js

Large diffs are not rendered by default.

Loading