1
0
mirror of synced 2024-11-21 21:06:09 +03:00

ref# 94173 Доработка вывода ошибок при установке и настройке модуля. (#339)

This commit is contained in:
Kocmonavtik 2024-03-18 14:00:13 +03:00 committed by GitHub
parent 50997b729f
commit d298cffb22
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 225 additions and 248 deletions

View File

@ -61,7 +61,6 @@ class intaro_retailcrm extends CModule
public $CRM_ORDER_LAST_ID = 'order_last_id'; public $CRM_ORDER_LAST_ID = 'order_last_id';
public $CRM_ORDER_PROPS = 'order_props'; public $CRM_ORDER_PROPS = 'order_props';
public $CRM_LEGAL_DETAILS = 'legal_details'; public $CRM_LEGAL_DETAILS = 'legal_details';
public $CRM_CUSTOM_FIELDS = 'custom_fields';
public $CRM_CONTRAGENT_TYPE = 'contragent_type'; public $CRM_CONTRAGENT_TYPE = 'contragent_type';
public $CRM_ORDER_DISCHARGE = 'order_discharge'; public $CRM_ORDER_DISCHARGE = 'order_discharge';
public $CRM_ORDER_FAILED_IDS = 'order_failed_ids'; public $CRM_ORDER_FAILED_IDS = 'order_failed_ids';
@ -217,9 +216,7 @@ class intaro_retailcrm extends CModule
$type['NAME'] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET); $type['NAME'] = $APPLICATION->ConvertCharset((string)$field, 'utf-8', SITE_CHARSET);
$type['ID'] = (string)$field['id']; $type['ID'] = (string)$field['id'];
if ($field['group'] == 'custom') { if (!$field['group']) {
$arResult['customFields'][] = $type;
} elseif (!$field['group']) {
$arResult['orderProps'][] = $type; $arResult['orderProps'][] = $type;
} else { } else {
$groups = explode(',', (string) $field['group']); $groups = explode(',', (string) $field['group']);
@ -485,6 +482,14 @@ class intaro_retailcrm extends CModule
} }
try { try {
$credentials = $this->RETAIL_CRM_API->getCredentials()->getResponseBody();
$residualRight = array_diff(Constants::REQUIRED_API_SCOPES, $credentials['scopes']);
if (count($residualRight) !== 0) {
throw new \InvalidArgumentException(sprintf(GetMessage('ERR_403'), implode(', ', $residualRight)));
}
$arResult['orderTypesList'] = $this->RETAIL_CRM_API->orderTypesList()->orderTypes; $arResult['orderTypesList'] = $this->RETAIL_CRM_API->orderTypesList()->orderTypes;
$arResult['deliveryTypesList'] = $this->RETAIL_CRM_API->deliveryTypesList()->deliveryTypes; $arResult['deliveryTypesList'] = $this->RETAIL_CRM_API->deliveryTypesList()->deliveryTypes;
$arResult['deliveryServicesList'] = $this->RETAIL_CRM_API->deliveryServicesList()->deliveryServices; $arResult['deliveryServicesList'] = $this->RETAIL_CRM_API->deliveryServicesList()->deliveryServices;
@ -498,7 +503,8 @@ class intaro_retailcrm extends CModule
$e->getCode() . ': ' . $e->getMessage() $e->getCode() . ': ' . $e->getMessage()
); );
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
$arResult['errCode'] = 'ERR_METHOD_NOT_FOUND'; $arResult['errCode'] = $e->getMessage();
$APPLICATION->IncludeAdminFile( $APPLICATION->IncludeAdminFile(
GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php' GetMessage('MODULE_INSTALL_TITLE'), $this->INSTALL_PATH . '/step1.php'
); );
@ -764,9 +770,6 @@ class intaro_retailcrm extends CModule
if ($orderProps = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_ORDER_PROPS, 0)) { if ($orderProps = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_ORDER_PROPS, 0)) {
$arResult['ORDER_PROPS'] = unserialize($orderProps); $arResult['ORDER_PROPS'] = unserialize($orderProps);
} }
if ($customFields = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_CUSTOM_FIELDS, 0)) {
$arResult['CUSTOM_FIELDS'] = unserialize($customFields);
}
if ($legalDetails = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_LEGAL_DETAILS, 0)) { if ($legalDetails = COption::GetOptionString($this->OLD_MODULE_ID, $this->CRM_LEGAL_DETAILS, 0)) {
$arResult['LEGAL_DETAILS'] = unserialize($legalDetails); $arResult['LEGAL_DETAILS'] = unserialize($legalDetails);
} }
@ -864,15 +867,6 @@ class intaro_retailcrm extends CModule
$legalDetailsArr[$orderType['ID']] = $_legalDetailsArr; $legalDetailsArr[$orderType['ID']] = $_legalDetailsArr;
} }
$customFieldsArr = [];
foreach ($orderTypesList as $orderType) {
$_customFieldsArr = [];
foreach ($arResult['customFields'] as $custom) {
$_customFieldsArr[$custom['ID']] = htmlspecialchars(trim($_POST['custom-fields-' . $custom['ID'] . '-' . $orderType['ID']]));
}
$customFieldsArr[$orderType['ID']] = $_customFieldsArr;
}
//contragents type list //contragents type list
$contragentTypeArr = []; $contragentTypeArr = [];
foreach ($orderTypesList as $orderType) { foreach ($orderTypesList as $orderType) {
@ -881,7 +875,6 @@ class intaro_retailcrm extends CModule
COption::SetOptionString($this->MODULE_ID, $this->CRM_ADDRESS_OPTIONS, serialize($addressDetailOptions)); COption::SetOptionString($this->MODULE_ID, $this->CRM_ADDRESS_OPTIONS, serialize($addressDetailOptions));
COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr))); COption::SetOptionString($this->MODULE_ID, $this->CRM_ORDER_PROPS, serialize(RCrmActions::clearArr($orderPropsArr)));
COption::SetOptionString($this->MODULE_ID, $this->CRM_CUSTOM_FIELDS, serialize(RCrmActions::clearArr($customFieldsArr)));
COption::SetOptionString($this->MODULE_ID, $this->CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr))); COption::SetOptionString($this->MODULE_ID, $this->CRM_LEGAL_DETAILS, serialize(RCrmActions::clearArr($legalDetailsArr)));
COption::SetOptionString($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr))); COption::SetOptionString($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE, serialize(RCrmActions::clearArr($contragentTypeArr)));
@ -1296,7 +1289,6 @@ class intaro_retailcrm extends CModule
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_TYPES_ARR);
COption::RemoveOption($this->MODULE_ID, $this->CRM_LEGAL_DETAILS); COption::RemoveOption($this->MODULE_ID, $this->CRM_LEGAL_DETAILS);
COption::RemoveOption($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE); COption::RemoveOption($this->MODULE_ID, $this->CRM_CONTRAGENT_TYPE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_CUSTOM_FIELDS);
COption::RemoveOption($this->MODULE_ID, $this->CRM_SITES_LIST); COption::RemoveOption($this->MODULE_ID, $this->CRM_SITES_LIST);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_DISCHARGE);
COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS); COption::RemoveOption($this->MODULE_ID, $this->CRM_ORDER_FAILED_IDS);
@ -1508,11 +1500,14 @@ class intaro_retailcrm extends CModule
{ {
global $APPLICATION; global $APPLICATION;
$client = new Client($api_host . '/api/'.self::V5, ['apiKey' => $api_key]); $client = new Client($api_host . '/api', ['apiKey' => $api_key]);
$result = []; $result = [];
try { try {
$siteResponse = $client->makeRequest('/reference/sites', 'GET'); $credentials = $client->makeRequest('/credentials', 'GET')->getResponseBody();
$residualRight = array_diff(Constants::REQUIRED_API_SCOPES, $credentials['scopes']);
$siteResponse = $client->makeRequest('/v5/reference/sites', 'GET');
$bitrixSites = RCrmActions::getSitesList(); $bitrixSites = RCrmActions::getSitesList();
$currencySites = RCrmActions::getCurrencySites(); $currencySites = RCrmActions::getCurrencySites();
} catch (CurlException $e) { } catch (CurlException $e) {
@ -1527,7 +1522,7 @@ class intaro_retailcrm extends CModule
} }
// Проверка, что был получен корректный ответ // Проверка, что был получен корректный ответ
if (isset($siteResponse) && $siteResponse->getStatusCode() === 200) { if (isset($siteResponse) && $siteResponse->getStatusCode() === 200 && count($residualRight) === 0) {
$sites = $siteResponse->sites ?? null; $sites = $siteResponse->sites ?? null;
if ($sites === null) { if ($sites === null) {
@ -1555,7 +1550,7 @@ class intaro_retailcrm extends CModule
$result['sitesList'] = $APPLICATION->ConvertCharsetArray($sites, 'utf-8', SITE_CHARSET); $result['sitesList'] = $APPLICATION->ConvertCharsetArray($sites, 'utf-8', SITE_CHARSET);
} }
} else { } else {
$result['errCode'] = 'ERR_METHOD_NOT_FOUND'; $result['errCode'] = sprintf(GetMessage('ERR_403'), implode(', ', $residualRight));
} }
return $result; return $result;

View File

@ -1,8 +1,15 @@
<?php <?php
IncludeModuleLangFile(__FILE__); IncludeModuleLangFile(__FILE__);
if(isset($arResult['errCode']) && $arResult['errCode']) if (isset($arResult['errCode']) && $arResult['errCode']) {
echo CAdminMessage::ShowMessage(GetMessage($arResult['errCode'])); $message = GetMessage($arResult['errCode']);
if ($message) {
echo CAdminMessage::ShowMessage($message);
} else {
echo CAdminMessage::ShowMessage(['MESSAGE' => $arResult['errCode'], 'HTML' => true]);
}
}
$MODULE_ID = 'intaro.retailcrm'; $MODULE_ID = 'intaro.retailcrm';
$CRM_API_HOST_OPTION = 'api_host'; $CRM_API_HOST_OPTION = 'api_host';
@ -53,4 +60,4 @@ $arResult['API_KEY'] = COption::GetOptionString($MODULE_ID, $CRM_API_KEY_OPTION)
</div> </div>
</div> </div>
</form> </form>
</div> </div>

View File

@ -284,41 +284,6 @@ if (isset($arResult['ORDER_PROPS'])) {
</select> </select>
</td> </td>
</tr> </tr>
<?if (isset($arResult['customFields']) && count($arResult['customFields']) > 0):?>
<tr class="heading custom-detail-title">
<td colspan="2" style="background-color: transparent;">
<b>
<?=GetMessage('ORDER_CUSTOM'); ?>
</b>
</td>
</tr>
<?foreach($arResult['customFields'] as $customFields):?>
<tr class="custom-detail-<?=$customFields['ID'];?>">
<td width="50%" class="" name="">
<?=$customFields['NAME']; ?>
</td>
<td width="50%" class="">
<select name="custom-fields-<?=$customFields['ID'] . '-' . $bitrixOrderType['ID']?>" class="typeselect">
<option value=""></option>
<?foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp):?>
<option value="<?=$arProp['CODE']?>"
<?= (isset($arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']])
&& $arResult['CUSTOM_FIELDS'][$bitrixOrderType['ID']][$customFields['ID']]
=== $arProp['CODE'])
? 'selected'
: ''
?>>
<?=$arProp['NAME']?>
</option>
<?php endforeach;?>
</select>
</td>
</tr>
<?php endforeach;?>
<?php endif;?>
<tr class="heading legal-detail-title-<?= $bitrixOrderType['ID']?>" style="display:none"> <tr class="heading legal-detail-title-<?= $bitrixOrderType['ID']?>" style="display:none">
<td colspan="2" style="background-color: transparent;"> <td colspan="2" style="background-color: transparent;">
<b> <b>

View File

@ -18,3 +18,4 @@ $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 ['SALE_VERSION_ERR'] = '\'Online-store\' module version must be higher than 16.';
$MESS['UF_SUBSCRIBE_USER_EMAIL_TITLE'] = 'Agree to receive promotional newsletters'; $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.'; $MESS ['CRM_SITES_ERROR'] = 'Failed to get list of CRM stores, please try another API key or contact RetailCRM support.';
$MESS ['ERR_403'] = '<a target="_blank" href="https://docs.retailcrm.ru/Users/Integration/SiteModules/1CBitrix/CreatingOnlineStore1CBitrix">Insufficient permissions for API key. The module must be added for it to work correctly: %s</a>';

View File

@ -27,8 +27,10 @@ $MESS ['ORDER_NUMBER'] = 'Order numbers: ';
$MESS ['ORDER_UPLOAD_INFO'] = 'Click "Start uploading" to upload all the orders . Or list the required order IDs separated by commas, intervals or dashes. For example: 1, 3, 5-10, 12, 13... etc.'; $MESS ['ORDER_UPLOAD_INFO'] = 'Click "Start uploading" to upload all the orders . Or list the required order IDs separated by commas, intervals or dashes. For example: 1, 3, 5-10, 12, 13... etc.';
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Save settings'; $MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Save settings';
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Save'; $MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Save';
$MESS ['ERR_403_LABEL'] = 'The module must be added for it to work correctly: %s';
$MESS ['ERR_404'] = 'CRM address may be incorrect.'; $MESS ['ERR_404'] = 'CRM address may be incorrect.';
$MESS ['ERR_403'] = 'Wrong apiKey.'; $MESS ['ERR_403'] = '<a target="_blank" href="https://docs.retailcrm.ru/Users/Integration/SiteModules/1CBitrix/CreatingOnlineStore1CBitrix">Insufficient permissions for API key. %s</a>';
$MESS ['ERR_403_CUSTOM'] = 'Not enough permissions for API key!';
$MESS ['ERR_JSON'] = 'Invalid data was received from CRM, check data books settings'; $MESS ['ERR_JSON'] = 'Invalid data was received from CRM, check data books settings';
$MESS ['ERR_0'] = 'Server connection timeout error.'; $MESS ['ERR_0'] = 'Server connection timeout error.';
$MESS ['ICRM_OPTIONS_OK'] = 'Changes are successfully saved.'; $MESS ['ICRM_OPTIONS_OK'] = 'Changes are successfully saved.';

View File

@ -56,4 +56,4 @@ $MESS ['UF_LP_ID_INTARO_TITLE'] = 'Номер аккаунта в програм
$MESS['IBLOCK_NOT_SELECTED'] = 'Не выбрано ни одного инфоблока для экспорта'; $MESS['IBLOCK_NOT_SELECTED'] = 'Не выбрано ни одного инфоблока для экспорта';
$MESS['TARGET_DIR_DOESNT_EXIST'] = 'Целевая директория не существует'; $MESS['TARGET_DIR_DOESNT_EXIST'] = 'Целевая директория не существует';
$MESS['UF_SUBSCRIBE_USER_EMAIL_TITLE'] = 'Согласен на рекламно-информационные рассылки'; $MESS['UF_SUBSCRIBE_USER_EMAIL_TITLE'] = 'Согласен на рекламно-информационные рассылки';
$MESS ['ERR_403'] = '<a target="_blank" href="https://docs.retailcrm.ru/Users/Integration/SiteModules/1CBitrix/CreatingOnlineStore1CBitrix">Недостаточно прав для API ключа. Для корректной работы модуля необходимо добавить: %s</a>';

View File

@ -40,8 +40,10 @@ $MESS ['CRM_STORE'] = 'CRM магазин: ';
$MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки'; $MESS ['ICRM_OPTIONS_SUBMIT_TITLE'] = 'Сохранить настройки';
$MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить'; $MESS ['ICRM_OPTIONS_SUBMIT_VALUE'] = 'Сохранить';
$MESS ['ERR_403_LABEL'] = 'Для корректной работы модуля необходимо добавить: %s';
$MESS ['ERR_404'] = 'Возможно не верно введен адрес CRM.'; $MESS ['ERR_404'] = 'Возможно не верно введен адрес CRM.';
$MESS ['ERR_403'] = 'Неверный apiKey.'; $MESS ['ERR_403'] = '<a target="_blank" href="https://docs.retailcrm.ru/Users/Integration/SiteModules/1CBitrix/CreatingOnlineStore1CBitrix">Недостаточно прав для API ключа. %s</a>';
$MESS ['ERR_403_CUSTOM'] = 'Недостаточно прав для API ключа!';
$MESS ['ERR_JSON'] = 'Получены некорректные данные из CRM, проверьте данные справочников в настройках'; $MESS ['ERR_JSON'] = 'Получены некорректные данные из CRM, проверьте данные справочников в настройках';
$MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.'; $MESS ['ERR_0'] = 'Превышено время ожидания ответа от сервера.';
$MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.'; $MESS ['ICRM_OPTIONS_OK'] = 'Изменения успешно сохранены.';

View File

@ -111,4 +111,20 @@ class Constants
public const SYNC_INTEGRATION_PAYMENT = 'sync_integration_payment'; public const SYNC_INTEGRATION_PAYMENT = 'sync_integration_payment';
public const CRM_PART_SUBSTITUTED_PAYMENT_CODE = '-not-integration'; public const CRM_PART_SUBSTITUTED_PAYMENT_CODE = '-not-integration';
public const CRM_SUBSTITUTION_PAYMENT_LIST = 'substitution_payment'; public const CRM_SUBSTITUTION_PAYMENT_LIST = 'substitution_payment';
public const REQUIRED_API_SCOPES = [
'order_read' => 'order_read',
'order_write' => 'order_write',
'customer_read' => 'customer_read',
'customer_write' => 'customer_write',
'store_read' => 'store_read',
'store_write' => 'store_write',
'reference_read' => 'reference_read',
'reference_write' => 'reference_write',
'integration_read' => 'integration_read',
'integration_write' => 'integration_write',
];
public const REQUIRED_API_SCOPES_CUSTOM = [
'custom_fields_read' => 'custom_fields_read',
'custom_fields_write' => 'custom_fields_write'
];
} }

View File

@ -88,6 +88,7 @@ if (!empty($_GET['ok']) && $_GET['ok'] === 'Y') {
} }
$arResult = []; $arResult = [];
$enabledCustom = false;
if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml')) { if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml')) {
$options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml'); $options = simplexml_load_file($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/classes/general/config/options.xml');
@ -102,9 +103,7 @@ if (file_exists($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/intaro.retailcrm/cl
$type["NAME"] = $APPLICATION->ConvertCharset((string) $field, 'utf-8', SITE_CHARSET); $type["NAME"] = $APPLICATION->ConvertCharset((string) $field, 'utf-8', SITE_CHARSET);
$type["ID"] = (string) $field["id"]; $type["ID"] = (string) $field["id"];
if ($field["group"] === 'custom') { if (!$field["group"]) {
$arResult['customFields'][] = $type;
} elseif (!$field["group"]) {
$arResult['orderProps'][] = $type; $arResult['orderProps'][] = $type;
} else { } else {
$groups = explode(",", (string) $field["group"]); $groups = explode(",", (string) $field["group"]);
@ -400,16 +399,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$legalDetailsArr[$orderType['ID']] = $_legalDetailsArr; $legalDetailsArr[$orderType['ID']] = $_legalDetailsArr;
} }
$customFieldsArr = [];
foreach ($orderTypesList as $orderType) {
$_customFieldsArr = [];
foreach ($arResult['customFields'] as $custom) {
$_customFieldsArr[$custom['ID']] = htmlspecialchars(trim($_POST['custom-fields-' . $custom['ID'] . '-' . $orderType['ID']]));
}
$customFieldsArr[$orderType['ID']] = $_customFieldsArr;
}
//contragents type list //contragents type list
$contragentTypeArr = []; $contragentTypeArr = [];
@ -818,11 +807,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$CRM_LEGAL_DETAILS, $CRM_LEGAL_DETAILS,
serialize(RCrmActions::clearArr(is_array($legalDetailsArr) ? $legalDetailsArr : [])) serialize(RCrmActions::clearArr(is_array($legalDetailsArr) ? $legalDetailsArr : []))
); );
COption::SetOptionString(
$mid,
$CRM_CUSTOM_FIELDS,
serialize(RCrmActions::clearArr(is_array($customFieldsArr) ? $customFieldsArr : []))
);
COption::SetOptionString( COption::SetOptionString(
$mid, $mid,
$CRM_ORDER_NUMBERS, $CRM_ORDER_NUMBERS,
@ -1079,6 +1063,19 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
// Prepare crm lists // Prepare crm lists
try { try {
$credentialsApi = $api->getCredentials()->getResponseBody();
$requiredApiScopes = Constants::REQUIRED_API_SCOPES;
if (ConfigProvider::getCustomFieldsStatus() === 'Y') {
$requiredApiScopes = array_merge($requiredApiScopes, Constants::REQUIRED_API_SCOPES_CUSTOM);
}
$residualRight = array_diff($requiredApiScopes, $credentialsApi['scopes']);
if (count($residualRight) !== 0) {
throw new InvalidArgumentException(sprintf(GetMessage('ERR_403_LABEL'), implode(', ', $residualRight)));
}
$arResult['orderTypesList'] = $api->orderTypesList()->orderTypes; $arResult['orderTypesList'] = $api->orderTypesList()->orderTypes;
$arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes; $arResult['deliveryTypesList'] = $api->deliveryTypesList()->deliveryTypes;
$arResult['deliveryServicesList'] = $api->deliveryServicesList()->deliveryServices; $arResult['deliveryServicesList'] = $api->deliveryServicesList()->deliveryServices;
@ -1089,16 +1086,22 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$arResult['sitesList'] = $APPLICATION->ConvertCharsetArray($api->sitesList()->sites, 'utf-8', SITE_CHARSET); $arResult['sitesList'] = $APPLICATION->ConvertCharsetArray($api->sitesList()->sites, 'utf-8', SITE_CHARSET);
$arResult['inventoriesList'] = $APPLICATION->ConvertCharsetArray($api->storesList()->stores, 'utf-8', SITE_CHARSET); $arResult['inventoriesList'] = $APPLICATION->ConvertCharsetArray($api->storesList()->stores, 'utf-8', SITE_CHARSET);
$arResult['priceTypeList'] = $APPLICATION->ConvertCharsetArray($api->pricesTypes()->priceTypes, 'utf-8', SITE_CHARSET); $arResult['priceTypeList'] = $APPLICATION->ConvertCharsetArray($api->pricesTypes()->priceTypes, 'utf-8', SITE_CHARSET);
$arResult['crmCustomOrderFields'] = $APPLICATION->ConvertCharsetArray( $arResult['crmCustomOrderFields'] = [];
$arResult['crmCustomUserFields'] = [];
if (count(array_diff(Constants::REQUIRED_API_SCOPES_CUSTOM, $credentialsApi['scopes'])) === 0) {
$arResult['crmCustomOrderFields'] = $APPLICATION->ConvertCharsetArray(
$api->customFieldsList(['entity' => 'order', 'type' => ['string','text', 'numeric', 'boolean', 'date']], 250)->customFields, $api->customFieldsList(['entity' => 'order', 'type' => ['string','text', 'numeric', 'boolean', 'date']], 250)->customFields,
'utf-8', 'utf-8',
SITE_CHARSET SITE_CHARSET
); );
$arResult['crmCustomUserFields'] = $APPLICATION->ConvertCharsetArray( $arResult['crmCustomUserFields'] = $APPLICATION->ConvertCharsetArray(
$api->customFieldsList(['entity' => 'customer', 'type' => ['string', 'text', 'integer', 'numeric', 'boolean', 'date']], 250)->customFields, $api->customFieldsList(['entity' => 'customer', 'type' => ['string', 'text', 'integer', 'numeric', 'boolean', 'date']], 250)->customFields,
'utf-8', 'utf-8',
SITE_CHARSET SITE_CHARSET
); );
$enabledCustom = true;
}
$orderMethods = []; $orderMethods = [];
$getOrderMethods = $api->orderMethodsList(); $getOrderMethods = $api->orderMethodsList();
@ -1123,7 +1126,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode())); echo CAdminMessage::ShowMessage(GetMessage('ERR_' . $e->getCode()));
} catch (InvalidArgumentException $e) { } catch (InvalidArgumentException $e) {
$badKey = true; $badKey = true;
echo CAdminMessage::ShowMessage(GetMessage('ERR_403')); echo CAdminMessage::ShowMessage(['MESSAGE' => sprintf(GetMessage('ERR_403'), $e->getMessage()), 'HTML' => true]);
} catch (\RetailCrm\Exception\InvalidJsonException $e) { } catch (\RetailCrm\Exception\InvalidJsonException $e) {
$badJson = true; $badJson = true;
echo CAdminMessage::ShowMessage(GetMessage('ERR_JSON')); echo CAdminMessage::ShowMessage(GetMessage('ERR_JSON'));
@ -2201,34 +2204,6 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
</td> </td>
</tr> </tr>
<?php $countProps++; endforeach; ?> <?php $countProps++; endforeach; ?>
<? if (isset($arResult['customFields']) && count($arResult['customFields']) > 0): ?>
<tr class="heading custom-detail-title">
<td colspan="2" style="background-color: transparent;">
<b>
<?=GetMessage("ORDER_CUSTOM");?>
</b>
</td>
</tr>
<? foreach ($arResult['customFields'] as $customFields): ?>
<tr class="custom-detail-<?=$customFields['ID'];?>">
<td width="50%" class="" name="">
<?=$customFields['NAME'];?>
</td>
<td width="50%" class="">
<select name="custom-fields-<?=$customFields['ID'] . '-' . $bitrixOrderType['ID'];?>" class="typeselect">
<option value=""></option>
<? foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?=$arProp['CODE']?>" <?php if ($optionsCustomFields[$bitrixOrderType['ID']][$customFields['ID']] === $arProp['CODE']) {
echo 'selected';
} ?>>
<?=$arProp['NAME'];?>
</option>
<? endforeach; ?>
</select>
</td>
</tr>
<? endforeach; ?>
<? endif; ?>
<tr id="<?php echo 'locationElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden"> <tr id="<?php echo 'locationElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden">
<td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('LOCATION_LABEL'); ?></td> <td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('LOCATION_LABEL'); ?></td>
<td class="adm-detail-content-cell-r" width="50%"> <td class="adm-detail-content-cell-r" width="50%">
@ -2519,152 +2494,166 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
<div id="custom_fields_settings" <?php if ($customFieldsToggle !== 'Y') { <div id="custom_fields_settings" <?php if ($customFieldsToggle !== 'Y') {
echo "hidden"; echo "hidden";
} ?>> } ?>>
<br> <?php if ($enabledCustom): ?>
<br>
<table class="adm-list-table"> <table class="adm-list-table">
<thead> <thead>
<tr class="adm-list-table-header">
<th class="adm-list-table-cell option-head option-other-top option-other-bottom" colspan="4">
<?php echo GetMessage('CUSTOM_FIELDS_ORDER_LABEL');?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<th class="option-head option-other-top option-other-bottom" colspan="4">
<button class="adm-btn-save" type="button" onclick="createMatched(`Order`)"><?php echo GetMessage('ADD_LABEL'); ?></button>
</th>
</tr>
</tfoot>
<tbody id="Order_matched">
<?php
$matchedPropsNum = 1;
foreach ($arResult['matchedOrderProps'] as $bitrixProp => $crmField) {?>
<tr class="adm-list-table-row matched-Order" id="matchedOrderFields_<?php echo $matchedPropsNum ?>">
<td class="adm-list-table-cell adm-detail-content-cell-l" colspan="2" width="50%">
<select
style="width: 200px;" class="typeselect"
name="bitrixOrderFields_<?php echo $bitrixProp ?>"
onchange="changeSelectBitrixValue(this, 'bitrixOrderFields_', 'crmOrderFields_');"
>
<option value=""></option>
<?php foreach ($arResult['bitrixOrdersCustomProp'] as $type => $mass) {?>
<optgroup label="<?php echo GetMessage($type); ?>">
<?php foreach ($mass as $code => $prop) {?>
<option
value="<?php echo $code ?>"
<?php if ($bitrixProp === $code) echo 'selected'; ?>
>
<?php echo $prop ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</td>
<td class="adm-list-table-cell adm-detail-content-cell-r" colspan="2" width="50%">
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmOrderFields_<?php echo $bitrixProp ?>"
id="crmOrder_<?php echo $crmField?>"
onchange="changeSelectCrmValue(this, 'crmOrder_')"
>
<option value=""></option>
<?php foreach ($arResult['crmCustomOrderFields'] as $type => $mass) {?>
<optgroup label="<?php echo GetMessage($type); ?>">
<?php foreach ($mass as $crmProp) {?>
<option
value="<?php echo $crmProp['code'] ?>"
<?php if ($crmField === $crmProp['code']) echo 'selected'; ?>
>
<?php echo $crmProp['name'] ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
&nbsp;
<a onclick="deleteMatched(this)" style="cursor: pointer"><?php echo GetMessage('DELETE_MATCHED'); ?></a>
</td>
</tr>
<?php $matchedPropsNum++; }?>
</tbody>
</table>
<br>
<table class="adm-list-table">
<thead>
<tr class="adm-list-table-header"> <tr class="adm-list-table-header">
<th class="adm-list-table-cell option-head option-other-top option-other-bottom" colspan="4"> <th class="adm-list-table-cell option-head option-other-top option-other-bottom" colspan="4">
<?php echo GetMessage('CUSTOM_FIELDS_ORDER_LABEL');?> <?php echo GetMessage('CUSTOM_FIELDS_USER_LABEL');?>
</th> </th>
</tr> </tr>
</thead> </thead>
<tfoot> <tfoot>
<tr> <tr>
<th class="option-head option-other-top option-other-bottom" colspan="4"> <th class="option-head option-other-top option-other-bottom" colspan="4">
<button class="adm-btn-save" type="button" onclick="createMatched(`Order`)"><?php echo GetMessage('ADD_LABEL'); ?></button> <button class="adm-btn-save" type="button" onclick="createMatched(`User`)"><?php echo GetMessage('ADD_LABEL'); ?></button>
</th> </th>
</tr> </tr>
</tfoot> </tfoot>
<tbody id="Order_matched"> <tbody id="User_matched">
<?php <?php
$matchedPropsNum = 1; $matchedFieldsNum = 1;
foreach ($arResult['matchedOrderProps'] as $bitrixProp => $crmField) {?> foreach ($arResult['matchedUserFields'] as $bitrixProp => $crmField) {?>
<tr class="adm-list-table-row matched-Order" id="matchedOrderFields_<?php echo $matchedPropsNum ?>"> <tr class="adm-list-table-row matched-User" id="matchedUserFields_<?php echo $matchedFieldsNum ?>">
<td class="adm-list-table-cell adm-detail-content-cell-l" colspan="2" width="50%"> <td class="adm-list-table-cell adm-detail-content-cell-l" colspan="2" width="50%">
<select <select
style="width: 200px;" class="typeselect" style="width: 200px;" class="typeselect"
name="bitrixOrderFields_<?php echo $bitrixProp ?>" name="bitrixUserFields_<?php echo $bitrixProp ?>"
onchange="changeSelectBitrixValue(this, 'bitrixOrderFields_', 'crmOrderFields_');" onchange="changeSelectBitrixValue(this, 'bitrixUserFields_', 'crmUserFields_');"
> >
<option value=""></option> <option value=""></option>
<?php foreach ($arResult['bitrixCustomUserFields'] as $type => $mass) {?>
<optgroup label="<?php echo GetMessage($type); ?>">
<?php foreach ($mass as $code => $prop) {?>
<option
value="<?php echo $code ?>"
<?php if ($bitrixProp === $code) echo 'selected'; ?>
>
<?php echo $prop ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</td>
<td class="adm-list-table-cell adm-detail-content-cell-r" colspan="2" width="50%">
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmUserFields_<?php echo $bitrixProp ?>"
id="crmClient_<?php echo $crmField?>"
onchange="changeSelectCrmValue(this, 'crmClient_')"
>
<option value=""></option>
<?php foreach ($arResult['crmCustomUserFields'] as $type => $mass) {?>
<optgroup label="<?php echo GetMessage($type); ?>">
<?php foreach ($mass as $crmProp) {?>
<option
value="<?php echo $crmProp['code'] ?>"
<?php if ($crmField === $crmProp['code']) echo 'selected'; ?>
>
<?php echo $crmProp['name'] ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
&nbsp;
<a onclick="deleteMatched(this)" style="cursor: pointer"><?php echo GetMessage('DELETE_MATCHED'); ?></a>
</td>
</tr>
<?php $matchedFieldsNum++; }?>
</tbody>
</table>
<?php else: ?>
<tr class="">
<td class="option-head" colspan="2">
<div class="adm-info-message-wrap adm-info-message-red">
<div class="adm-info-message">
<div class="adm-info-message-title"><a target="_blank" href="https://docs.retailcrm.ru/Users/Integration/SiteModules/1CBitrix/CreatingOnlineStore1CBitrix"><?php echo GetMessage('ERR_403_CUSTOM'); ?></a></div>
<?php foreach ($arResult['bitrixOrdersCustomProp'] as $type => $mass) {?> <div class="adm-info-message-icon"></div>
<optgroup label="<?php echo GetMessage($type); ?>"> </div>
<?php foreach ($mass as $code => $prop) {?> </div>
<option </td>
value="<?php echo $code ?>"
<?php if ($bitrixProp === $code) echo 'selected'; ?>
>
<?php echo $prop ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</td>
<td class="adm-list-table-cell adm-detail-content-cell-r" colspan="2" width="50%">
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmOrderFields_<?php echo $bitrixProp ?>"
id="crmOrder_<?php echo $crmField?>"
onchange="changeSelectCrmValue(this, 'crmOrder_')"
>
<option value=""></option>
<?php foreach ($arResult['crmCustomOrderFields'] as $type => $mass) {?>
<optgroup label="<?php echo GetMessage($type); ?>">
<?php foreach ($mass as $crmProp) {?>
<option
value="<?php echo $crmProp['code'] ?>"
<?php if ($crmField === $crmProp['code']) echo 'selected'; ?>
>
<?php echo $crmProp['name'] ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
&nbsp;
<a onclick="deleteMatched(this)" style="cursor: pointer"><?php echo GetMessage('DELETE_MATCHED'); ?></a>
</td>
</tr>
<?php $matchedPropsNum++; }?>
</tbody>
</table>
<br>
<table class="adm-list-table">
<thead>
<tr class="adm-list-table-header">
<th class="adm-list-table-cell option-head option-other-top option-other-bottom" colspan="4">
<?php echo GetMessage('CUSTOM_FIELDS_USER_LABEL');?>
</th>
</tr> </tr>
</thead> <?php endif; ?>
<tfoot>
<tr>
<th class="option-head option-other-top option-other-bottom" colspan="4">
<button class="adm-btn-save" type="button" onclick="createMatched(`User`)"><?php echo GetMessage('ADD_LABEL'); ?></button>
</th>
</tr>
</tfoot>
<tbody id="User_matched">
<?php
$matchedFieldsNum = 1;
foreach ($arResult['matchedUserFields'] as $bitrixProp => $crmField) {?>
<tr class="adm-list-table-row matched-User" id="matchedUserFields_<?php echo $matchedFieldsNum ?>">
<td class="adm-list-table-cell adm-detail-content-cell-l" colspan="2" width="50%">
<select
style="width: 200px;" class="typeselect"
name="bitrixUserFields_<?php echo $bitrixProp ?>"
onchange="changeSelectBitrixValue(this, 'bitrixUserFields_', 'crmUserFields_');"
>
<option value=""></option>
<?php foreach ($arResult['bitrixCustomUserFields'] as $type => $mass) {?>
<optgroup label="<?php echo GetMessage($type); ?>">
<?php foreach ($mass as $code => $prop) {?>
<option
value="<?php echo $code ?>"
<?php if ($bitrixProp === $code) echo 'selected'; ?>
>
<?php echo $prop ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
</td>
<td class="adm-list-table-cell adm-detail-content-cell-r" colspan="2" width="50%">
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmUserFields_<?php echo $bitrixProp ?>"
id="crmClient_<?php echo $crmField?>"
onchange="changeSelectCrmValue(this, 'crmClient_')"
>
<option value=""></option>
<?php foreach ($arResult['crmCustomUserFields'] as $type => $mass) {?>
<optgroup label="<?php echo GetMessage($type); ?>">
<?php foreach ($mass as $crmProp) {?>
<option
value="<?php echo $crmProp['code'] ?>"
<?php if ($crmField === $crmProp['code']) echo 'selected'; ?>
>
<?php echo $crmProp['name'] ?>
</option>
<?php } ?>
</optgroup>
<?php } ?>
</select>
&nbsp;
<a onclick="deleteMatched(this)" style="cursor: pointer"><?php echo GetMessage('DELETE_MATCHED'); ?></a>
</td>
</tr>
<?php $matchedFieldsNum++; }?>
</tbody>
</table>
</div> </div>
</td> </td>
</tr> </tr>