From b5a1a62b2fae266baa2029ad3956188471aa1715 Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Fri, 25 Aug 2023 17:33:51 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#91590=20=D0=BF=D0=B5=D1=80=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=BD=D1=8B=20=D1=83=D0=B2=D0=B5?= =?UTF-8?q?=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D1=81=D0=BE=D0=BE=D1=82=D0=BD=D0=BE=D1=88=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8E=20=D0=B2=D0=B0=D0=BB=D1=8E=D1=82.=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=82=D0=B5=D0=BA=D1=83=D1=89=D0=B5=D0=B9=20=D0=B2=D0=B0=D0=BB?= =?UTF-8?q?=D1=8E=D1=82=D1=8B=20=D1=81=D0=B0=D0=B9=D1=82=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/general/RCrmActions.php | 30 ++++++++++++++ intaro.retailcrm/install/index.php | 40 +++++++++++++++---- intaro.retailcrm/lang/ru/install/step1.php | 2 +- intaro.retailcrm/options.php | 34 +++++++++++++--- 4 files changed, 92 insertions(+), 14 deletions(-) diff --git a/intaro.retailcrm/classes/general/RCrmActions.php b/intaro.retailcrm/classes/general/RCrmActions.php index b7c6249a..8892ee0a 100644 --- a/intaro.retailcrm/classes/general/RCrmActions.php +++ b/intaro.retailcrm/classes/general/RCrmActions.php @@ -21,6 +21,36 @@ class RCrmActions public static $CRM_API_VERSION = 'api_version'; public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED'; + public static function getCurrencySites(): array + { + global $DB; + + $sites = self::getSitesList(); + $sitesLID = []; + $sitesCurrency = []; + + foreach ($sites as $site) { + $sitesLID[] = $site['LID']; + } + + $currencies = $DB->Query( + "SELECT DISTINCT site.SMN_SITE_ID, hook_data.VALUE + FROM `b_landing_site` site + LEFT JOIN `b_landing_hook_data` hook_data on site.ID = hook_data.ENTITY_ID + WHERE site.SMN_SITE_ID IN ('" . implode("', '", $sitesLID) . "') + AND hook_data.CODE = 'CURRENCY_ID'; + " + ); + + while ($currencySite = $currencies->Fetch()) { + if (!empty($currencySite['SMN_SITE_ID'])) { + $sitesCurrency[$currencySite['SMN_SITE_ID']] = $currencySite['VALUE']; + } + } + + return $sitesCurrency; + } + /** * @return array */ diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index f1bb5339..7a999bd2 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -369,6 +369,8 @@ class intaro_retailcrm extends CModule } $arResult['arSites'] = RCrmActions::getSitesList(); + $arResult['arCurrencySites'] = RCrmActions::getCurrencySites(); + $bitrixBaseCurrency = CCurrency::GetBaseCurrency(); if (count($arResult['arSites']) > 1) { @@ -382,6 +384,23 @@ class intaro_retailcrm extends CModule $siteCode[$site['LID']] = null; } } + + foreach ($arResult['arSites'] as $bitrixSite) { + $currentCurrency = $bitrixBaseCurrency; + $LID = $bitrixSite['LID']; + + if (isset($arResult['arCurrencySites'][$LID])) { + $currentCurrency = $arResult['arCurrencySites'][$LID]; + } + + if ( + isset($arResult['sitesList'][$siteCode[$LID]]) + && $currentCurrency !== $arResult['sitesList'][$siteCode[$LID]]['currency']) + { + $arResult['errCode'] = 'ERR_CURRENCY_SITES'; + } + } + if (count($arResult['arSites']) != count($siteCode)) { $arResult['errCode'] = 'ERR_FIELDS_API_HOST'; $APPLICATION->IncludeAdminFile( @@ -1440,6 +1459,7 @@ class intaro_retailcrm extends CModule $result = $client->makeRequest('/reference/sites', 'GET'); $bitrixSites = RCrmActions::getSitesList(); $bitrixBaseCurrency = CCurrency::GetBaseCurrency(); + $currencySites = RCrmActions::getCurrencySites(); } catch (CurlException $e) { RCrmActions::eventLog( 'intaro.retailcrm/install/index.php', 'RetailCrm\ApiClient::sitesList', @@ -1454,16 +1474,22 @@ class intaro_retailcrm extends CModule //Проверка, что был получен корректный ответ if (isset($result) && $result->getStatusCode() == 200) { //Проверка количества магазинов, доступных по апи - if (count($bitrixSites) < count($result->sites)) { + if (count($bitrixSites) === 1 && count($result->sites) > 1) { $res['errCode'] = 'ERR_COUNT_SITES'; } - //Проверка совпадения базовой валюты CMS - if (!isset($res)) { - foreach ($result->sites as $site) { - if ($site['currency'] !== $bitrixBaseCurrency) { - $res['errCode'] = 'ERR_CURRENCY_SITES'; - } + if (count($bitrixSites) === 1 ) { + $currentCurrency = $bitrixBaseCurrency; + $LID = $bitrixSites[0]['LID']; + + if (isset($currencySites[$LID])) { + $currentCurrency = $currencySites[$LID]; + } + + $crmSite = reset($result->sites); + + if ($currentCurrency !== $crmSite['currency']) { + $res['errCode'] = 'ERR_CURRENCY_SITES'; } } diff --git a/intaro.retailcrm/lang/ru/install/step1.php b/intaro.retailcrm/lang/ru/install/step1.php index 3bc44e2c..c9d3a767 100644 --- a/intaro.retailcrm/lang/ru/install/step1.php +++ b/intaro.retailcrm/lang/ru/install/step1.php @@ -11,7 +11,7 @@ $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_COUNT_SITES'] = 'По введенному ключу апи доступно больше одного магазина!'; $MESS ['ERR_CURRENCY_SITES'] = 'Базовая валюта отличается от валюты магазина в CRM'; //$MESS ['URL_NOT_FOUND'] = 'В настройках одного или нескольких сайтов не заполнено поле "URL сервера".'; $MESS ['INFO_1'] = 'Введите адрес экземпляра RetailCRM (например, https://demo.retailcrm.ru) и API-ключ.'; diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 364714df..af9d6ac6 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -118,6 +118,7 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/cl } $arResult['arSites'] = RCrmActions::getSitesList(); +$arResult['arCurrencySites'] = RCrmActions::getCurrencySites(); //ajax update deliveryServices if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && (strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') && isset($_POST['ajax']) && ($_POST['ajax'] === 1)) { $api_host = COption::GetOptionString($mid, $CRM_API_HOST_OPTION, 0); @@ -1063,16 +1064,37 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) { $errorsText = []; - foreach ($arResult['sitesList'] as $site) { - if ($site['currency'] !== $baseCurrency) { - $errorsText[] = GetMessage('ERR_CURRENCY_SITES') . '(' . $site['name'] . ')'; - } - } - if (count($arResult['arSites']) === 1 && count($arResult['sitesList']) > 1) { $errorsText[] = GetMessage('ERR_COUNT_SITES'); } + if ($arResult['arSites'] > 1) { + foreach ($optionsSitesList as $LID => $crmCode) { + $currentCurrency = $baseCurrency; + + if (isset($arResult['arCurrencySites'][$LID])) { + $currentCurrency = $arResult['arCurrencySites'][$LID]; + } + + if ($currentCurrency !== $arResult['sitesList'][$crmCode]['currency']) { + $errorsText[] = GetMessage('ERR_CURRENCY_SITES') . '(' . $arResult['sitesList'][$crmCode]['name'] . ')'; + } + } + } else { + $currentCurrency = $baseCurrency; + $LID = $arResult['arSites'][0]['LID']; + + if (isset($arResult['arCurrencySites'][$LID])) { + $currentCurrency = $arResult['arCurrencySites'][$LID]; + } + + $crmSite = reset($arResult['sitesList']); + + if ($currentCurrency !== $crmSite['currency']) { + $errorsText[] = GetMessage('ERR_CURRENCY_SITES') . '(' . $crmSite['name'] . ')'; + } + } + if (preg_match('/&errc=ERR_(.*)/is', $uri, $matches)){ $errorsText[] = $matches[1]; }