1
0
mirror of synced 2024-11-23 22:06:11 +03:00

ref #93434 Исправлена критическая ошибка при переходе в настройки модуля (#326)

This commit is contained in:
Uryvskiy Dima 2023-12-12 16:51:15 +03:00 committed by GitHub
parent d47852dc31
commit 992162c01e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 186 additions and 153 deletions

View File

@ -1,4 +1,7 @@
## 2023-10-25 v.6.4.11
## 2023-12-12 v.6.4.12
- Исправлена критическая ошибка при переходе в настройки модуля
## 2023-12-08 v.6.4.11
- Исправлена ошибка при передаче подписки на рекламно-информационные рассылки
## 2023-10-25 v.6.4.10

View File

@ -1,13 +1,16 @@
<?php
use Bitrix\Sale\PersonType;
use Intaro\RetailCrm\Component\ServiceLocator;
use Bitrix\Sale\Delivery\Services\EmptyDeliveryService;
use Bitrix\Sale\Internals\OrderPropsTable;
use Bitrix\Sale\Internals\StatusTable;
use Bitrix\Sale\PaySystem\Manager;
use Intaro\RetailCrm\Service\Utils;
use RetailCrm\Exception\CurlException;
use RetailCrm\Exception\InvalidJsonException;
use Intaro\RetailCrm\Service\ManagerService;
use Bitrix\Sale\Internals\SiteCurrencyTable;
IncludeModuleLangFile(__FILE__);
@ -19,33 +22,19 @@ class RCrmActions
public static $MODULE_ID = 'intaro.retailcrm';
public static $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
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 = [];
$baseCurrency = CCurrency::GetBaseCurrency();
$sitesCurrency = [];
foreach ($sites as $site) {
$sitesLID[] = $site['LID'];
}
$siteCurrency = SiteCurrencyTable::getCurrency($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'];
}
$sitesCurrency[$site['LID']] = !empty($siteCurrency['CURRENCY'])
? $siteCurrency['CURRENCY']
: $baseCurrency;
}
return $sitesCurrency;
@ -68,17 +57,21 @@ class RCrmActions
public static function OrderTypesList($arSites)
{
$orderTypesList = array();
$orderTypesList = [];
foreach ($arSites as $site) {
$personTypes = \Bitrix\Sale\PersonType::load($site['LID']);
$bitrixOrderTypesList = array();
$personTypes = PersonType::load($site['LID']);
$bitrixOrderTypesList = [];
foreach ($personTypes as $personType) {
if (!array_key_exists($personType['ID'], $orderTypesList)) {
$bitrixOrderTypesList[$personType['ID']] = $personType;
}
asort($bitrixOrderTypesList);
}
$orderTypesList = $orderTypesList + $bitrixOrderTypesList;
$orderTypesList += $bitrixOrderTypesList;
}
return $orderTypesList;
@ -86,10 +79,11 @@ class RCrmActions
public static function DeliveryList()
{
$bitrixDeliveryTypesList = array();
$bitrixDeliveryTypesList = [];
$arDeliveryServiceAll = \Bitrix\Sale\Delivery\Services\Manager::getActiveList();
$noOrderId = EmptyDeliveryService::getEmptyDeliveryServiceId();
$groups = array();
$groups = [];
foreach ($arDeliveryServiceAll as $arDeliveryService) {
if ($arDeliveryService['CLASS_NAME'] == '\Bitrix\Sale\Delivery\Services\Group') {
$groups[] = $arDeliveryService['ID'];
@ -112,11 +106,9 @@ class RCrmActions
public static function PaymentList()
{
$bitrixPaymentTypesList = array();
$dbPaymentAll = Manager::getList(array(
'select' => array('ID', 'NAME'),
'filter' => array('ACTIVE' => 'Y')
));
$bitrixPaymentTypesList = [];
$dbPaymentAll = Manager::getList(['select' => ['ID', 'NAME'], 'filter' => ['ACTIVE' => 'Y']]);
while ($payment = $dbPaymentAll->fetch()) {
$bitrixPaymentTypesList[] = $payment;
}
@ -126,16 +118,14 @@ class RCrmActions
public static function StatusesList()
{
$bitrixPaymentStatusesList = array();
$obStatuses = StatusTable::getList(array(
'filter' => array('TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID),
'select' => array('ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME')
));
$bitrixPaymentStatusesList = [];
$obStatuses = StatusTable::getList([
'filter' => ['TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID],
'select' => ['ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'],
]);
while ($arStatus = $obStatuses->fetch()) {
$bitrixPaymentStatusesList[$arStatus['ID']] = array(
'ID' => $arStatus['ID'],
'NAME' => $arStatus['NAME'],
);
$bitrixPaymentStatusesList[$arStatus['ID']] = ['ID' => $arStatus['ID'], 'NAME' => $arStatus['NAME']];
}
return $bitrixPaymentStatusesList;
@ -143,11 +133,9 @@ class RCrmActions
public static function OrderPropsList()
{
$bitrixPropsList = array();
$arPropsAll = OrderPropsTable::getList(array(
'select' => array('*'),
'filter' => array('CODE' => '_%')
));
$bitrixPropsList = [];
$arPropsAll = OrderPropsTable::getList(['select' => ['*'], 'filter' => ['CODE' => '_%']]);
while ($prop = $arPropsAll->Fetch()) {
$bitrixPropsList[$prop['PERSON_TYPE_ID']][] = $prop;
}
@ -157,14 +145,8 @@ class RCrmActions
public static function PricesExportList()
{
$catalogExportPrices = array();
$dbPriceType = CCatalogGroup::GetList(
array(),
array(),
false,
false,
array('ID', 'NAME', 'NAME_LANG')
);
$catalogExportPrices = [];
$dbPriceType = CCatalogGroup::GetList([], [], false, false, ['ID', 'NAME', 'NAME_LANG']);
while ($arPriceType = $dbPriceType->Fetch())
{
@ -176,8 +158,9 @@ class RCrmActions
public static function StoresExportList()
{
$catalogExportStores = array();
$dbStores = CCatalogStore::GetList(array(), array('ACTIVE' => 'Y'), false, false, array('ID', 'TITLE'));
$catalogExportStores = [];
$dbStores = CCatalogStore::GetList([], ['ACTIVE' => 'Y'], false, false, ['ID', 'TITLE']);
while ($stores = $dbStores->Fetch()) {
$catalogExportStores[] = $stores;
}
@ -187,18 +170,19 @@ class RCrmActions
public static function IblocksExportList()
{
$catalogExportIblocks = array();
$dbIblocks = CIBlock::GetList(array('IBLOCK_TYPE' => 'ASC', 'NAME' => 'ASC'), array('CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'W'));
$catalogExportIblocks = [];
$dbIblocks = CIBlock::GetList(['IBLOCK_TYPE' => 'ASC', 'NAME' => 'ASC'], ['CHECK_PERMISSIONS' => 'Y', 'MIN_PERMISSION' => 'W']);
while ($iblock = $dbIblocks->Fetch()) {
if ($arCatalog = CCatalog::GetByIDExt($iblock['ID'])) {
if($arCatalog['CATALOG_TYPE'] == 'D' || $arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
$catalogExportIblocks[$iblock['ID']] = array(
$catalogExportIblocks[$iblock['ID']] = [
'ID' => $iblock['ID'],
'IBLOCK_TYPE_ID' => $iblock['IBLOCK_TYPE_ID'],
'LID' => $iblock['LID'],
'CODE' => $iblock['CODE'],
'NAME' => $iblock['NAME'],
);
];
if ($arCatalog['CATALOG_TYPE'] == 'X' || $arCatalog['CATALOG_TYPE'] == 'P') {
$iblockOffer = CCatalogSKU::GetInfoByProductIBlock($iblock['ID']);
@ -289,8 +273,9 @@ class RCrmActions
*/
public static function clearArr(array $arr): array
{
/** @var \Intaro\RetailCrm\Service\Utils $utils */
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
/** @var Utils $utils */
$utils = ServiceLocator::getOrCreate(Utils::class);
return $utils->clearArray($arr);
}
@ -302,8 +287,9 @@ class RCrmActions
*/
public static function toJSON($str)
{
/** @var \Intaro\RetailCrm\Service\Utils $utils */
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
/** @var Utils $utils */
$utils = ServiceLocator::getOrCreate(Utils::class);
return $utils->toUTF8($str);
}
@ -319,8 +305,8 @@ class RCrmActions
return '';
}
/** @var \Intaro\RetailCrm\Service\Utils $utils */
$utils = ServiceLocator::getOrCreate(\Intaro\RetailCrm\Service\Utils::class);
/** @var Utils $utils */
$utils = ServiceLocator::getOrCreate(Utils::class);
return $utils->fromUTF8($str);
}
@ -523,14 +509,14 @@ class RCrmActions
case 'cartClear':
return self::proxy($api, $methodApi, $method, [$params, $site]);
default:
return self::proxy($api, $methodApi, $method, array($params, $site));
return self::proxy($api, $methodApi, $method, [$params, $site]);
}
}
private static function proxy($api, $methodApi, $method, $params) {
$version = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_VERSION, 0);
try {
$result = call_user_func_array(array($api, $methodApi), $params);
$result = call_user_func_array([$api, $methodApi], $params);
if (!$result) {
$err = new RuntimeException(
@ -551,21 +537,21 @@ class RCrmActions
|| $methodApi == 'customersGet'
|| $methodApi == 'customersCorporateGet'
) {
Logger::getInstance()->write(array(
Logger::getInstance()->write([
'api' => $version,
'methodApi' => $methodApi,
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
'errors' => !empty($result['errors']) ? $result['errors'] : '',
'params' => $params
), 'apiErrors');
], 'apiErrors');
} elseif ($methodApi == 'customersUpload' || $methodApi == 'ordersUpload') {
Logger::getInstance()->write(array(
Logger::getInstance()->write([
'api' => $version,
'methodApi' => $methodApi,
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
'errors' => !empty($result['errors']) ? $result['errors'] : '',
'params' => $params
), 'uploadApiErrors');
], 'uploadApiErrors');
} elseif ($methodApi == 'cartGet') {
Logger::getInstance()->write(
[
@ -584,13 +570,13 @@ class RCrmActions
!empty($result['errorMsg']) ? $result['errorMsg'] : ''
);
Logger::getInstance()->write(array(
Logger::getInstance()->write([
'api' => $version,
'methodApi' => $methodApi,
'errorMsg' => !empty($result['errorMsg']) ? $result['errorMsg'] : '',
'errors' => !empty($result['errors']) ? $result['errors'] : '',
'params' => $params,
), 'apiErrors');
], 'apiErrors');
}
if (function_exists('retailCrmApiResult')) {
@ -671,13 +657,13 @@ class RCrmActions
$exception->getCode() . ': ' . $exception->getMessage()
);
Logger::getInstance()->write(array(
Logger::getInstance()->write([
'api' => $version,
'methodApi' => $methodApi,
'errorMsg' => $exception->getMessage(),
'errors' => $exception->getCode(),
'params' => $params
), 'apiErrors');
], 'apiErrors');
if (function_exists('retailCrmApiResult')) {
retailCrmApiResult($methodApi, false, $apiResultExceptionName);

View File

@ -51,7 +51,6 @@ class RetailCrmHistory
public static $CRM_DISCOUNT_ROUND = 'discount_round';
const PAGE_LIMIT = 25;
const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
public static function customerHistory()
{

View File

@ -431,11 +431,11 @@ class RetailCrmOrder
$arUser = UserTable::getById($arOrder['USER_ID'])->fetch();
$fioCrm = [$order['firstName'] ?? null, $order['lastName'] ?? null, $order['patronymic'] ?? null];
if (in_array($arUser['NAME'], $fioCrm)) {
if ($arUser['NAME'] !== '' && in_array($arUser['NAME'], $fioCrm)) {
$order['firstName'] = $arUser['NAME'];
}
if (in_array($arUser['LAST_NAME'], $fioCrm)) {
if ($arUser['LAST_NAME'] !== '' && in_array($arUser['LAST_NAME'], $fioCrm)) {
$order['lastName'] = $arUser['LAST_NAME'];
}

View File

@ -1 +1 @@
- Исправлена ошибка при передаче подписки на рекламно-информационные рассылки
- Исправлена критическая ошибка при переходе в настройки модуля

View File

@ -15,6 +15,7 @@ use Bitrix\Sale\EventActions;
use Bitrix\Sale\Internals\OrderTable;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Component\Installer\InstallerTrait;
use Intaro\RetailCrm\Service\CurrencyService;
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder;
use RetailCrm\ApiClient;
@ -242,6 +243,7 @@ class intaro_retailcrm extends CModule
include($this->INSTALL_PATH . '/../lib/component/constants.php');
include($this->INSTALL_PATH . '/../lib/repository/agreementrepository.php');
include($this->INSTALL_PATH . '/../lib/service/orderloyaltydataservice.php');
include($this->INSTALL_PATH . '/../lib/service/currencyservice.php');
include($this->INSTALL_PATH . '/../lib/component/factory/clientfactory.php');
include($this->INSTALL_PATH . '/../lib/component/apiclient/clientadapter.php');
@ -311,9 +313,11 @@ class intaro_retailcrm extends CModule
// form correct url
$api_host = parse_url($api_host);
if ($api_host['scheme'] !== 'https') {
$api_host['scheme'] = 'https';
}
$api_host = $api_host['scheme'] . '://' . $api_host['host'];
if (!$api_host || !$api_key) {
@ -374,15 +378,14 @@ class intaro_retailcrm extends CModule
$api_key = COption::GetOptionString($this->MODULE_ID, $this->CRM_API_KEY_OPTION, 0);
foreach ($arResult['arSites'] as $site) {
$siteCode[$site['LID']] = null;
if ($_POST['sites-id-' . $site['LID']] && !empty($_POST['sites-id-' . $site['LID']])) {
$siteCode[$site['LID']] = htmlspecialchars(trim($_POST['sites-id-' . $site['LID']]));
} else {
$siteCode[$site['LID']] = null;
}
}
$arResult['arCurrencySites'] = RCrmActions::getCurrencySites();
$bitrixBaseCurrency = CCurrency::GetBaseCurrency();
$result = $this->getReferenceShops($api_host, $api_key);
if (isset($result['errCode'])) {
@ -392,26 +395,18 @@ class intaro_retailcrm extends CModule
}
foreach ($arResult['arSites'] as $bitrixSite) {
$currentCurrency = $bitrixBaseCurrency;
$LID = $bitrixSite['LID'];
$LID = $bitrixSite['LID'] ?? null;
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
$crmCurrency = $arResult['sitesList'][$siteCode[$LID]]['currency'] ?? null;
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';
}
$arResult['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
}
if (count($arResult['arSites']) != count($siteCode)) {
$arResult['errCode'] = 'ERR_FIELDS_API_HOST';
}
if (isset($arResult['errCode'])) {
if (!empty($arResult['errCode'])) {
$APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step11.php'
);
@ -1458,11 +1453,11 @@ class intaro_retailcrm extends CModule
global $APPLICATION;
$client = new Client($api_host . '/api/'.self::V5, ['apiKey' => $api_key]);
$result = [];
try {
$result = $client->makeRequest('/reference/sites', 'GET');
$siteResponse = $client->makeRequest('/reference/sites', 'GET');
$bitrixSites = RCrmActions::getSitesList();
$bitrixBaseCurrency = CCurrency::GetBaseCurrency();
$currencySites = RCrmActions::getCurrencySites();
} catch (CurlException $e) {
RCrmActions::eventLog(
@ -1470,47 +1465,44 @@ class intaro_retailcrm extends CModule
$e->getCode() . ': ' . $e->getMessage()
);
$res['errCode'] = 'ERR_' . $e->getCode();
$result['errCode'] = 'ERR_' . $e->getCode();
return $res;
return $result;
}
//Проверка, что был получен корректный ответ
if (isset($result) && $result->getStatusCode() == 200) {
//Проверка количества магазинов, доступных по апи
if (count($bitrixSites) === 1 && count($result->sites) > 1) {
$res['errCode'] = 'ERR_COUNT_SITES';
// Проверка, что был получен корректный ответ
if (isset($siteResponse) && $siteResponse->getStatusCode() === 200) {
$sites = $siteResponse->sites ?? null;
if ($sites === null) {
$result['errCode'] = 'UNKNOWN_ERROR';
}
if (!isset($res['errCode']) && 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';
}
//Проверка количества магазинов, доступных по API
if (count($bitrixSites) === 1 && count($sites) > 1) {
$result['errCode'] = 'ERR_COUNT_SITES';
}
if (!isset($res)) {
if (!isset($result['errCode']) && count($bitrixSites) === 1 ) {
$LID = $bitrixSites[0]['LID'] ?? null;
$cmsCurrency = $currencySites[$LID] ?? null;
$crmSiteData = reset($sites);
$crmCurrency = $crmSiteData['currency'] ?? null;
$result['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
}
if (empty($result['errCode'])) {
ConfigProvider::setApiVersion(self::V5);
$res['sitesList'] = $APPLICATION->ConvertCharsetArray(
$result->sites,
'utf-8',
SITE_CHARSET
);
$result['sitesList'] = $APPLICATION->ConvertCharsetArray($sites, 'utf-8', SITE_CHARSET);
}
} else {
$res['errCode'] = 'ERR_METHOD_NOT_FOUND';
$result['errCode'] = 'ERR_METHOD_NOT_FOUND';
}
return $res;
return $result;
}
/**

View File

@ -1,6 +1,6 @@
<?php
$arModuleVersion = [
'VERSION' => '6.4.11',
'VERSION_DATE' => '2023-12-08 13:00:00'
'VERSION' => '6.4.12',
'VERSION_DATE' => '2023-12-12 17:00:00'
];

View File

@ -17,3 +17,4 @@ $MESS ['ERR_ARTICLE_IBLOCK'] = 'Articles are not set';
$MESS ['DATE_TIMEZONE_ERR'] = 'Timezone is not specified in php settings.';
$MESS ['SALE_VERSION_ERR'] = '\'Online-store\' module version must be higher than 16.';
$MESS['UF_SUBSCRIBE_USER_EMAIL_TITLE'] = 'Agree to receive promotional newsletters';
$MESS ['CRM_SITES_ERROR'] = 'Failed to get list of CRM stores, please try another API key or contact RetailCRM support.';

View File

@ -19,3 +19,5 @@ $MESS ['ERR_COUNT_SITES'] = 'The API Key you entered relates to more than one st
Change the access settings for the API key, it should work with only one store in CRM';
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
For the integration to work correctly, the currencies in CRM and CMS must match';
$MESS ['ERR_CMS_CURRENCY'] = 'Failed to get Bitrix site currency';
$MESS ['ERR_CRM_CURRENCY'] = 'Failed to get CRM store currency';

View File

@ -12,3 +12,5 @@ $MESS ['INFO_1'] = 'Set the correspondence between 1C-Bitrix and RetailCRM store
$MESS ['INFO_2'] = 'All your stores in RetailCRM must have a common API key!';
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
For the integration to work correctly, the currencies in CRM and CMS must match';
$MESS ['ERR_CMS_CURRENCY'] = 'Failed to get Bitrix site currency';
$MESS ['ERR_CRM_CURRENCY'] = 'Failed to get CRM store currency';

View File

@ -105,7 +105,10 @@ $MESS ['INTEGRATIONS'] = ' (integration)';
$MESS ['ERR_COUNT_SITES'] = 'The API Key you entered relates to more than one store.
Change the access settings for the API key, it should work with only one store in CRM';
$MESS ['ERR_CURRENCY_SITES'] = 'The currency of the site differs from the currency of the store in CRM.
For the integration to work correctly, the currencies in CRM and CMS must match';
For the integration to work correctly, the currencies in CRM and CMS must match #NAME#';
$MESS ['ERR_CMS_CURRENCY'] = 'Failed to get Bitrix site currency';
$MESS ['ERR_CRM_CURRENCY'] = 'Failed to get CRM store currency';
$MESS ['CRM_STORE'] = 'CRM store: ';
$MESS ['ACTIVITY_SETTINGS'] = 'Module activity settings';
$MESS ['DEACTIVATE_MODULE'] = 'Deactivate the module';

View File

@ -16,6 +16,7 @@ $MESS ['DATE_TIMEZONE_ERR'] = 'Не указана временная зона
$MESS ['SALE_VERSION_ERR'] = 'Версия модуля \'Интернет-магазин\' должна быть выше 16.';
$MESS ['AGREEMENT_LOYALTY_PROGRAM_TEXT'] = 'Вставить текст Правил программы лояльности';
$MESS ['AGREEMENT_PERSONAL_DATA_TEXT'] = 'Вставить текст соглашения на обработку персональных данных';
$MESS ['CRM_SITES_ERROR'] = 'Не удалось получить список магазинов CRM, попробуйте другой ключ API или обратитесь в службу поддержки RetailCRM.';
$MESS ['RETAIL_MODULE_NAME'] = 'RetailCRM';
$MESS ['MODULE_DESCRIPTION'] = 'Модуль интеграции с RetailCRM - специализированной CRM для e-commerce';

View File

@ -15,7 +15,8 @@ $MESS ['ERR_COUNT_SITES'] = 'Введенный вами API Ключ относ
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
//$MESS ['URL_NOT_FOUND'] = 'В настройках одного или нескольких сайтов не заполнено поле "URL сервера".';
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';
$MESS ['INFO_1'] = 'Введите адрес экземпляра RetailCRM (например, https://demo.retailcrm.ru) и API-ключ.';
$MESS ['INFO_2'] = 'API-ключ можно сгенерировать при регистрации магазина в RetailCRM (Администрирование > Интеграция).';
$MESS ['INFO_3'] = 'Код сайта в 1С-Битрикс должен совпадать с кодом сайта в RetailCRM (Администрирование > Магазины).';

View File

@ -11,4 +11,6 @@ $MESS ['ERR_FIELDS_API_HOST'] = 'Неверно заполнены поля.';
$MESS ['INFO_1'] = 'Задайте соответствия между Вашими магазинами в 1С-Битрикс и RetailCRM.';
$MESS ['INFO_2'] = 'У всех Ваших магазинов в RetailCRM должен быть общий API-ключ!';
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';

View File

@ -31,6 +31,9 @@ $MESS ['ERR_COUNT_SITES'] = 'Введенный вами API Ключ относ
Измените настройки доступа для API ключа, он должен работать только с одним магазином в CRM';
$MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается от валюты магазина в CRM.
Для корректной работы интеграции, валюты в CRM и CMS должны совпадать';
$MESS ['ERR_CMS_CURRENCY'] = 'Не удалось получить валюту сайта Bitrix';
$MESS ['ERR_CRM_CURRENCY'] = 'Не удалось получить валюту магазина CRM';
$MESS ['CRM_STORE'] = 'CRM магазин: ';
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки';
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить';

View File

@ -73,7 +73,6 @@ class Constants
public const CRM_ORDER_HISTORY_DATE = 'order_history_date';
public const CRM_CATALOG_BASE_PRICE = 'catalog_base_price';
public const CRM_ORDER_DIMENSIONS = 'order_dimensions';
public const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED';
public const CRM_INTEGRATION_DELIVERY = 'integration_delivery';
public const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted';
public const CORPORATE_CONTRAGENT_TYPE = 'legal-entity';

View File

@ -0,0 +1,22 @@
<?php
namespace Intaro\RetailCrm\Service;
class CurrencyService
{
public static function validateCurrency($cmsCurrency, $crmCurrency): string
{
$errorCode = '';
if ($cmsCurrency === null) {
$errorCode = 'ERR_CMS_CURRENCY';
} elseif ($crmCurrency === null) {
$errorCode = 'ERR_CRM_CURRENCY';
} elseif ($cmsCurrency !== $crmCurrency) {
$errorCode = 'ERR_CURRENCY_SITES';
}
return $errorCode;
}
}

View File

@ -13,9 +13,10 @@ use Intaro\RetailCrm\Component\Constants;
use Intaro\RetailCrm\Component\Handlers\EventsHandlers;
use Intaro\RetailCrm\Repository\AgreementRepository;
use Intaro\RetailCrm\Repository\TemplateRepository;
use Intaro\RetailCrm\Service\CurrencyService;
use Intaro\RetailCrm\Service\OrderLoyaltyDataService;
use Intaro\RetailCrm\Service\Utils as RetailCrmUtils;
use RetailCrm\Exception\CurlException;
use \Intaro\RetailCrm\Service\Utils as RetailcrmUtils;
IncludeModuleLangFile(__FILE__);
$mid = 'intaro.retailcrm';
@ -605,7 +606,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
if (isset($_POST['loyalty_toggle']) && $_POST['loyalty_toggle'] === 'on') {
try {
$hlName = RetailcrmUtils::getHlClassByName(Constants::HL_LOYALTY_CODE);
$hlName = RetailCrmUtils::getHlClassByName(Constants::HL_LOYALTY_CODE);
if (empty($hlName)) {
OrderLoyaltyDataService::createLoyaltyHlBlock();
@ -1066,10 +1067,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$version = COption::GetOptionString($mid, $CRM_API_VERSION, 0);
//currency
$baseCurrency = \Bitrix\Currency\CurrencyManager::getBaseCurrency();
$currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ?: $baseCurrency;
$currencyList = \Bitrix\Currency\CurrencyManager::getCurrencyList();
// Old functional
$currencyOption = COption::GetOptionString($mid, $CRM_CURRENCY, 0) ?: CCurrency::GetBaseCurrency();
//Validate currency
$currencyList = CurrencyManager::getCurrencyList();
$errorsText = [];
@ -1088,29 +1091,26 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
continue;
}
$currentCurrency = $baseCurrency;
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
$crmCurrency = $arResult['sitesList'][$crmCode]['currency'] ?? null;
$crmSiteName = $arResult['sitesList'][$crmCode]['name'] ?? null;
if (isset($arResult['arCurrencySites'][$LID])) {
$currentCurrency = $arResult['arCurrencySites'][$LID];
}
$errorCode = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
if ($currentCurrency !== $arResult['sitesList'][$crmCode]['currency']) {
$errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $arResult['sitesList'][$crmCode]['name'] . ')';
if ($errorCode === 'ERR_CMS_CURRENCY') {
$errorsText[] = GetMessage($errorCode) . ' (' . $LID . ')';
} elseif($errorCode !== '') {
$errorsText[] = GetMessage($errorCode) . ' (' . GetMessage('CRM_STORE') . $crmSiteName . ')';
}
}
} else {
$currentCurrency = $baseCurrency;
$LID = $arResult['arSites'][0]['LID'];
$LID = $arResult['arSites'][0]['LID'] ?? null;
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
if (isset($arResult['arCurrencySites'][$LID])) {
$currentCurrency = $arResult['arCurrencySites'][$LID];
}
$crmSiteData = reset($arResult['sitesList']);
$crmCurrency = $crmSiteData['currency'] ?? null;
$crmSite = reset($arResult['sitesList']);
if ($currentCurrency !== $crmSite['currency']) {
$errorsText[] = GetMessage('ERR_CURRENCY_SITES') . ' (' . $crmSite['name'] . ')';
}
$errorsText[] = GetMessage(CurrencyService::validateCurrency($cmsCurrency, $crmCurrency));
}
}

View File

@ -0,0 +1,17 @@
<?php
use Intaro\RetailCrm\Service\CurrencyService;
class CurrencyServiceTest extends BitrixTestCase
{
public function setUp(): void
{
parent::setUp();
}
public function testValidateCurrency()
{
self::assertNotEquals('', CurrencyService::validateCurrency('RUB', 'USD'));
self::assertNotEquals('', CurrencyService::validateCurrency('USD', 'RUB'));
self::assertEquals('', CurrencyService::validateCurrency('RUB', 'RUB'));
}
}