From abf7e6df3efe8d47b7ee8b3d7c0860a0660a0737 Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Wed, 23 Aug 2023 17:55:21 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#91590=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D1=8B=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B2=D0=B0=D0=BB=D1=8E=D1=82=D1=8B=20=D0=BF=D1=80=20?= =?UTF-8?q?=D0=B8=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B5=20?= =?UTF-8?q?=D0=B8=20=D0=BD=D0=B0=D1=81=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B5?= =?UTF-8?q?=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F.=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B2=D0=B5=D1=80=D1=81?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20=D0=B2=D1=8B=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=B0=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intaro.retailcrm/install/index.php | 41 ++++++++++++++++------ intaro.retailcrm/lang/ru/install/step1.php | 2 ++ intaro.retailcrm/lang/ru/options.php | 2 ++ intaro.retailcrm/options.php | 23 +++++++++++- 4 files changed, 56 insertions(+), 12 deletions(-) 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): ?>