1
0
Fork 0
mirror of synced 2025-04-04 14:23:33 +03:00

ref #91590 переработаны уведомления по соотношению валют.

Добавлен метод получения текущей валюты сайта.
This commit is contained in:
Ivan Chaplygin 2023-08-25 17:33:51 +03:00
parent ec7cdc55d0
commit b5a1a62b2f
4 changed files with 92 additions and 14 deletions

View file

@ -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
*/

View file

@ -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';
}
}

View file

@ -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-ключ.';

View file

@ -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];
}