last version
This commit is contained in:
parent
7e1a7ace96
commit
f78d2a443b
7 changed files with 50 additions and 38 deletions
|
@ -243,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');
|
||||
|
||||
|
@ -312,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) {
|
||||
|
@ -394,18 +397,16 @@ class intaro_retailcrm extends CModule
|
|||
foreach ($arResult['arSites'] as $bitrixSite) {
|
||||
$LID = $bitrixSite['LID'] ?? null;
|
||||
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
||||
$crmCurrency = $arResult['sitesList'][$siteCode[$LID]]['currency'] ?? null;
|
||||
|
||||
$crmCurrency = $arResult['sitesList'][$siteCode]['currency'] ?? null;
|
||||
$crmSite = $arResult['sitesList'][$siteCode]['name'] ?? null;
|
||||
|
||||
$arResult['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSite);
|
||||
$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'
|
||||
);
|
||||
|
@ -1452,9 +1453,10 @@ 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();
|
||||
$currencySites = RCrmActions::getCurrencySites();
|
||||
} catch (CurlException $e) {
|
||||
|
@ -1463,43 +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 ) {
|
||||
$LID = $bitrixSites[0]['LID'] ?? null;
|
||||
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
||||
//Проверка количества магазинов, доступных по API
|
||||
if (count($bitrixSites) === 1 && count($sites) > 1) {
|
||||
$result['errCode'] = 'ERR_COUNT_SITES';
|
||||
}
|
||||
|
||||
$crmSiteData = reset($arResult['sitesList']);
|
||||
$crmSiteName = $crmSiteData['name'] ?? null;
|
||||
if (!isset($result['errCode']) && count($bitrixSites) === 1 ) {
|
||||
$LID = $bitrixSites[0]['LID'] ?? null;
|
||||
$cmsCurrency = $currencySites[$LID] ?? null;
|
||||
|
||||
$crmSiteData = reset($sites);
|
||||
$crmCurrency = $crmSiteData['currency'] ?? null;
|
||||
|
||||
$res['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSiteName);
|
||||
$result['errCode'] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
|
||||
}
|
||||
|
||||
if (!isset($res)) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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.';
|
||||
|
|
|
@ -105,9 +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';
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -33,6 +33,7 @@ $MESS ['ERR_CURRENCY_SITES'] = 'Валюта сайта отличается о
|
|||
Для корректной работы интеграции, валюты в 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'] = 'Сохранить';
|
||||
|
|
|
@ -5,18 +5,18 @@ namespace Intaro\RetailCrm\Service;
|
|||
|
||||
class CurrencyService
|
||||
{
|
||||
public static function validateCurrency($cmsCurrency, $crmCurrency, $cmsSite = null, $crmSite = null)
|
||||
public static function validateCurrency($cmsCurrency, $crmCurrency): string
|
||||
{
|
||||
$errorMessage = '';
|
||||
$errorCode = '';
|
||||
|
||||
if ($cmsCurrency === null) {
|
||||
$errorMessage = GetMessage('ERR_CMS_CURRENCY') . ' (' . $cmsSite . ')';
|
||||
$errorCode = 'ERR_CMS_CURRENCY';
|
||||
} elseif ($crmCurrency === null) {
|
||||
$errorMessage = GetMessage('ERR_CRM_CURRENCY') . ' (' . $crmSite . ')';
|
||||
$errorCode = 'ERR_CRM_CURRENCY';
|
||||
} elseif ($cmsCurrency !== $crmCurrency) {
|
||||
$errorMessage = GetMessage('ERR_CURRENCY_SITES') . ' (' . $crmSite . ')';
|
||||
$errorCode = 'ERR_CURRENCY_SITES';
|
||||
}
|
||||
|
||||
return $errorMessage;
|
||||
return $errorCode;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1093,19 +1093,24 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
|
|||
|
||||
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
||||
$crmCurrency = $arResult['sitesList'][$crmCode]['currency'] ?? null;
|
||||
$crmSite = $arResult['sitesList'][$crmCode]['name'] ?? null;
|
||||
$crmSiteName = $arResult['sitesList'][$crmCode]['name'] ?? null;
|
||||
|
||||
$errorsText[] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSite);
|
||||
$errorCode = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency);
|
||||
|
||||
if ($errorCode === 'ERR_CMS_CURRENCY') {
|
||||
$errorsText[] = GetMessage($errorCode) . ' (' . $LID . ')';
|
||||
} elseif($errorCode !== '') {
|
||||
$errorsText[] = GetMessage($errorCode) . ' (' . GetMessage('CRM_STORE') . $crmSiteName . ')';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$LID = $arResult['arSites'][0]['LID'] ?? null;
|
||||
$cmsCurrency = $arResult['arCurrencySites'][$LID] ?? null;
|
||||
|
||||
$crmSiteData = reset($arResult['sitesList']);
|
||||
$crmSiteName = $crmSiteData['name'] ?? null;
|
||||
$crmCurrency = $crmSiteData['currency'] ?? null;
|
||||
|
||||
$errorsText[] = CurrencyService::validateCurrency($cmsCurrency, $crmCurrency, $LID, $crmSiteName);
|
||||
$errorsText[] = GetMessage(CurrencyService::validateCurrency($cmsCurrency, $crmCurrency));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue