diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 5f962a4c..f1bb5339 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -1438,6 +1438,8 @@ class intaro_retailcrm extends CModule try { $result = $client->makeRequest('/reference/sites', 'GET'); + $bitrixSites = RCrmActions::getSitesList(); + $bitrixBaseCurrency = CCurrency::GetBaseCurrency(); } catch (CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::sitesList', @@ -1445,21 +1447,38 @@ class intaro_retailcrm extends CModule ); $res['errCode'] = 'ERR_' . $e->getCode(); - } - - if (!isset($result) || $result->getStatusCode() == 200) { - ConfigProvider::setApiVersion(self::V5); - - $res['sitesList'] = $APPLICATION->ConvertCharsetArray( - $result->sites, - 'utf-8', - SITE_CHARSET - ); return $res; } - $res['errCode'] = 'ERR_METHOD_NOT_FOUND'; + //Проверка, что был получен корректный ответ + if (isset($result) && $result->getStatusCode() == 200) { + //Проверка количества магазинов, доступных по апи + if (count($bitrixSites) < count($result->sites)) { + $res['errCode'] = 'ERR_COUNT_SITES'; + } + + //Проверка совпадения базовой валюты CMS + if (!isset($res)) { + foreach ($result->sites as $site) { + if ($site['currency'] !== $bitrixBaseCurrency) { + $res['errCode'] = 'ERR_CURRENCY_SITES'; + } + } + } + + if (!isset($res)) { + ConfigProvider::setApiVersion(self::V5); + + $res['sitesList'] = $APPLICATION->ConvertCharsetArray( + $result->sites, + 'utf-8', + SITE_CHARSET + ); + } + } else { + $res['errCode'] = 'ERR_METHOD_NOT_FOUND'; + } return $res; } diff --git a/intaro.retailcrm/lang/ru/install/step1.php b/intaro.retailcrm/lang/ru/install/step1.php index 9b88760e..fd7c8251 100644 --- a/intaro.retailcrm/lang/ru/install/step1.php +++ b/intaro.retailcrm/lang/ru/install/step1.php @@ -11,6 +11,8 @@ $MESS ['ERR_403'] = 'Неверный apiKey.'; $MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.'; $MESS ['ERR_FIELDS_API_HOST'] = 'Неверно заполнены поля.'; $MESS ['ERR_METHOD_NOT_FOUND'] = 'Проверьте доступность методов API по текущему ключу.'; +$MESS ['ERR_COUNT_SITES'] = 'По введенному ключу апи доступно больше магазинов, чем существует в cms'; +$MESS ['ERR_CURRENCY_SITES'] = 'Базовая валюта отличается от валюты магазина в CRM'; //$MESS ['URL_NOT_FOUND'] = 'В настройках одного или нескольких сайтов не заполнено поле "URL сервера".'; $MESS ['INFO_1'] = 'Введите адрес экземпляра RetailCRM (например, https://demo.retailcrm.ru) и API-ключ.'; $MESS ['INFO_2'] = 'API-ключ можно сгенерировать при регистрации магазина в RetailCRM (Администрирование > Интеграция).'; diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index 0c458074..77f19694 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -27,6 +27,8 @@ $MESS ['ORDER_UPLOAD_INFO'] = 'Для загрузки всех заказов $MESS ['INTEGRATION_PAYMENT_LIST'] = 'Для интеграционных оплат статус не передаётся'; $MESS ['INTEGRATIONS'] = ' (интеграционная)'; +$MESS ['ERR_CURRENCY_SITES'] = 'Базовая валюта отличается от валюты магазина в CRM!'; + $MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки'; $MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить'; diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index aa70a403..ab70d6d5 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -1061,6 +1061,15 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { $currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ?: $baseCurrency; $currencyList = \Bitrix\Currency\CurrencyManager::getCurrencyList(); + $errCurrency = null; + + foreach ($arResult['sitesList'] as $site) { + if ($site['currency'] !== $baseCurrency) { + $errCurrency['site'] = ' (' . $site['name'] . ')'; + $errCurrency['errorText'] = 'ERR_CURRENCY_SITES'; + } + } + $customFields = [['code' => '__default_empty_value__', 'name' => GetMessage('SELECT_VALUE')]]; $crmCouponFieldOption = COption::GetOptionString($mid, $CRM_COUPON_FIELD, 0) ?: null; $page = 1; @@ -1462,7 +1471,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { - + + @@ -1470,6 +1480,17 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { + + + + + + + + + + + 1): ?>