1
0
Fork 0
mirror of synced 2025-04-11 05:00:55 +00:00
Исправления по коду
Изменение переводов
This commit is contained in:
Ivan Chaplygin 2023-12-18 12:08:16 +03:00
parent d7da02df3f
commit 1588a67227
8 changed files with 137 additions and 120 deletions

View file

@ -470,9 +470,8 @@ class RCrmActions
['MULTIPLE' => 'N'],
['ACTIVE' => 'Y']
]
]);
])->fetchAll();
$propsList = $propsList->fetchAll();
$resultList = [];
foreach ($propsList as $prop) {
@ -552,7 +551,7 @@ class RCrmActions
return $result;
}
public static function convertFieldToCrmValue($value, $type)
public static function convertCmsFieldToCrmValue($value, $type)
{
$result = $value;
@ -564,75 +563,58 @@ class RCrmActions
$result = date('Y-m-d', strtotime($value));
}
switch ($type) {
case 'boolean':
$result = $value === '1' ? 1 : 0;
break;
case 'Y/N':
$result = $result === 'Y' ? 1 : 0;
break;
case 'STRING':
case 'string':
if (strlen($value) > 500) {
$result = '';
}
break;
case 'datetime':
$result = date('Y-m-d', strtotime($value));
break;
}
return $result;
}
public static function convertCrmValueToFieldUser($crmValue, $type)
public static function convertCrmValueToCmsField($crmValue, $type)
{
$result = $crmValue;
if ($type === 'boolean') {
$result = $crmValue == 1 ? 'Y' : 'N';
}
switch ($type) {
case 'Y/N':
case 'boolean':
$result = $crmValue == 1 ? 'Y' : 'N';
break;
case 'DATE':
case 'date':
if (empty($crmValue)) {
return '';
}
if ($type === 'date') {
if (empty($crmValue)) {
return '';
}
try {
$result = date('d.m.Y', strtotime($crmValue));
} catch (\Exception $exception) {
$result = '';
}
try {
$result = date('d.m.Y', strtotime($crmValue));
} catch (\Exception $exception) {
$result = '';
}
}
break;
case 'STRING':
case 'string':
case 'text':
if (strlen($result) > 500) {
$result = '';
}
if (array_search($type, ['string', 'text']) && strlen($result) > 500) {
$result = '';
}
return $result;
}
public static function convertPropToCrmValue($prop)
{
$result = $prop['VALUE'][0];
if ($prop['TYPE'] === 'Y/N') {
$result = $prop['VALUE'][0] === 'Y' ? 1 : 0;
}
if ($prop['TYPE'] === 'STRING' && strlen($result) > 500) {
$result = '';
}
return $result;
}
public static function convertCrmValueToPropOrder($objProperty, $crmValue)
{
$result = $crmValue;
$typeField = $objProperty->getType();
if ($typeField === 'Y/N') {
$result = $crmValue == 1 ? 'Y' : 'N';
}
if ($typeField === 'DATE') {
if (empty($crmValue)) {
return '';
}
try {
$result = date('d.m.Y', strtotime($crmValue));
} catch (\Exception $exception) {
$result = '';
}
}
if ($typeField === 'STRING' && strlen($crmValue) > 500) {
$result = '';
break;
}
return $result;

View file

@ -212,9 +212,9 @@ class RetailCrmHistory
$customerArray = $customerBuilder->getCustomer()->getObjectToArray();
$customerArray = array_merge($customerArray, $customFields);
$u = $newUser->Update($customer['externalId'], self::convertBooleanFields($customerArray));
$queryUpdate = $newUser->Update($customer['externalId'], self::convertBooleanFields($customerArray));
if (!$u) {
if (!$queryUpdate) {
RCrmActions::eventLog(
'RetailCrmHistory::customerHistory',
'Error update user',
@ -1255,10 +1255,10 @@ class RetailCrmHistory
if (isset($matchedCustomOrderFields[$code])) {
$masIdentifier = explode('#', $matchedCustomOrderFields[$code], 2);
$property = $propertyCollection->getItemByOrderPropertyId($masIdentifier[0]);
$value = RCrmActions::convertCrmValueToPropOrder($property, $value);
$r = $property->setField('VALUE', $value);
$value = RCrmActions::convertCrmValueToCmsField($value, $property->getType());
$queryResult = $property->setField('VALUE', $value);
if (!$r->isSuccess()) {
if (!$queryResult->isSuccess()) {
RCrmActions::eventLog(
'RetailCrmHistory::orderHistory',
'CustomOrderPropSave',
@ -2190,7 +2190,7 @@ class RetailCrmHistory
foreach ($customer['customFields'] as $code => $value) {
if (isset($matchedCustomFields[$code]) && !empty($customUserFieldTypes[$matchedCustomFields[$code]])) {
$type = $customUserFieldTypes[$matchedCustomFields[$code]];
$customFields[$matchedCustomFields[$code]] = RCrmActions::convertCrmValueToFieldUser($value, $type);
$customFields[$matchedCustomFields[$code]] = RCrmActions::convertCrmValueToCmsField($value, $type);
}
}
}

View file

@ -136,7 +136,7 @@ class RetailCrmOrder
&& !empty($arParams['customOrderProps'])
&& isset($arParams['customOrderProps'][$prop['ID'] . '#' . $prop['CODE']])
) {
$order['customFields'][$arParams['customOrderProps'][$prop['ID'] . '#' . $prop['CODE']]] = RCrmActions::convertPropToCrmValue($prop);
$order['customFields'][$arParams['customOrderProps'][$prop['ID'] . '#' . $prop['CODE']]] = RCrmActions::convertCmsFieldToCrmValue($prop['VALUE'][0], $prop['TYPE']);
} elseif (is_array($arParams['optionsOrderProps'][$arOrder['PERSON_TYPE_ID']])
&& $search = array_search($prop['CODE'], $arParams['optionsOrderProps'][$arOrder['PERSON_TYPE_ID']])) {//other
if (in_array($search, ['fio', 'phone', 'email'])) {//fio, phone, email

View file

@ -169,7 +169,7 @@ class RetailCrmUser
foreach ($customUserFields as $code => $codeCrm) {
if (isset($arFields[$code])) {
$type = $typeList[$code] ?? '';
$result[$codeCrm] = RCrmActions::convertFieldToCrmValue($arFields[$code], $type);
$result[$codeCrm] = RCrmActions::convertCmsFieldToCrmValue($arFields[$code], $type);
}
}

View file

@ -179,7 +179,7 @@ $MESS ['ORDER_TRACK_NUMBER'] = 'Получать трек-номер';
$MESS ['CUSTOM_FIELDS_TITLE'] = 'Пользовательские поля';
$MESS ['CUSTOM_FIELDS_CAPTION'] = 'Сопоставление пользовательских полей';
$MESS ['CUSTOM_FIELDS_TOGGLE_MSG'] = 'Активность обмена пользовательскими полями';
$MESS ['CUSTOM_FIELDS_TOGGLE_MSG'] = 'Активировать синхронизацию пользовательских полей';
$MESS ['CUSTOM_FIELDS_ORDER_LABEL'] = 'Свойство заказа Битрикс/Пользовательское поле RetailCRM';
$MESS ['CUSTOM_FIELDS_USER_LABEL'] = 'Пользовательское поле Битрикс/Пользовательское поле RetailCRM';
$MESS ['INTEGER_TYPE'] = 'Целое число';

View file

@ -944,16 +944,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
foreach ($arResult['bitrixOrdersCustomProp'] as $list) {
foreach ($list as $code => $text) {
if (!empty($_POST['bitrixOrderProp_' . $code]) && !empty($_POST['crmOrderField_' . $code])) {
$customOrderProps[htmlspecialchars($_POST['bitrixOrderProp_' . $code])] = htmlspecialchars($_POST['crmOrderField_' . $code]);
if (!empty($_POST['bitrixOrderFields_' . $code]) && !empty($_POST['crmOrderFields_' . $code])) {
$customOrderProps[htmlspecialchars($_POST['bitrixOrderFields_' . $code])] = htmlspecialchars($_POST['crmOrderFields_' . $code]);
}
}
}
foreach ($arResult['bitrixCustomUserFields'] as $list) {
foreach ($list as $code => $text) {
if (!empty($_POST['bitrixUserField_' . $code]) && !empty($_POST['crmUserField_' . $code])) {
$customUserFields[htmlspecialchars($_POST['bitrixUserField_' . $code])] = htmlspecialchars($_POST['crmUserField_' . $code]);
if (!empty($_POST['bitrixUserFields_' . $code]) && !empty($_POST['crmUserFields_' . $code])) {
$customUserFields[htmlspecialchars($_POST['bitrixUserFields_' . $code])] = htmlspecialchars($_POST['crmUserFields_' . $code]);
}
}
}
@ -1408,51 +1408,76 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
$('#custom_fields_settings').toggle(500);
}
function createMatchedOrder()
function createMatched(type)
{
let elements = document.getElementsByClassName("adm-list-table-row matchedProps");
let bitrixName = "bitrix" + type + "Fields";
let crmName = "crm" + type + "Fields";
let elements = document.getElementsByClassName("adm-list-table-row matched-" + type);
let nextId = 1;
if (elements.length >= 1) {
let lastElement = elements[elements.length-1];
nextId = parseInt(lastElement.id.replace("matchedOrderProps_", "")) + 1;
let lastElement = elements[elements.length - 1];
nextId = parseInt(lastElement.id.replace("matched" + type + "Fields_", "")) + 1;
}
let matchedBlank = document.getElementById("orderMatchedPropsBlank");
let matchedBlank = document.getElementById(type + "MatchedFieldsBlank");
let matchedElement = matchedBlank.cloneNode(true);
matchedElement.classList.add("adm-list-table-row");
matchedElement.classList.add("matchedProps");
matchedElement.setAttribute("id", "matchedOrderProps_" + nextId);
matchedElement.querySelector("select[name='bitrixOrderProp']").setAttribute("name", "bitrixOrderProp_" + nextId);
matchedElement.querySelector("select[name='crmOrderField']").setAttribute("name", "crmOrderField_" + nextId);
matchedElement.classList.add("matched-" + type);
matchedElement.setAttribute("id", "matched" + type + "Fields_" + nextId);
matchedElement.querySelector(`select[name=${bitrixName}`).setAttribute("name", bitrixName + "_" + nextId);
matchedElement.querySelector(`select[name=${crmName}`).setAttribute("name", crmName + "_" + nextId);
matchedElement.removeAttribute("hidden");
document.getElementById("prop_matched").appendChild(matchedElement);
document.getElementById(type + "_matched").appendChild(matchedElement);
}
function createMatchedOrder()
{
let elements = document.getElementsByClassName("adm-list-table-row matched-Order");
let nextId = 1;
if (elements.length >= 1) {
let lastElement = elements[elements.length - 1];
nextId = parseInt(lastElement.id.replace("matchedOrderFields_", "")) + 1;
}
let matchedBlank = document.getElementById("OrderMatchedFieldsBlank");
let matchedElement = matchedBlank.cloneNode(true);
matchedElement.classList.add("adm-list-table-row");
matchedElement.classList.add("matched-Order");
matchedElement.setAttribute("id", "matchedOrderFields_" + nextId);
matchedElement.querySelector("select[name='bitrixOrderFields']").setAttribute("name", "bitrixOrderFields_" + nextId);
matchedElement.querySelector("select[name='crmOrderFields']").setAttribute("name", "crmOrderFields_" + nextId);
matchedElement.removeAttribute("hidden");
document.getElementById("Order_matched").appendChild(matchedElement);
}
function createMatchedUser()
{
let elements = document.getElementsByClassName("adm-list-table-row matchedField");
let elements = document.getElementsByClassName("adm-list-table-row matched-User");
let nextId = 1;
if (elements.length >= 1) {
let lastElement = elements[elements.length-1];
nextId = parseInt(lastElement.id.replace("matchedUserProps_", "")) + 1;
nextId = parseInt(lastElement.id.replace("matchedUserFields_", "")) + 1;
}
let matchedBlank = document.getElementById("userMatchedFieldsBlank");
let matchedBlank = document.getElementById("UserMatchedFieldsBlank");
let matchedElement = matchedBlank.cloneNode(true);
matchedElement.classList.add("adm-list-table-row");
matchedElement.classList.add("matchedField");
matchedElement.setAttribute("id", "matchedUserProps_" + nextId);
matchedElement.querySelector("select[name='bitrixUserField']").setAttribute("name", "bitrixUserField_" + nextId);
matchedElement.querySelector("select[name='crmUserField']").setAttribute("name", "crmUserField_" + nextId);
matchedElement.classList.add("matched-User");
matchedElement.setAttribute("id", "matchedUserFields_" + nextId);
matchedElement.querySelector("select[name='bitrixUserFields']").setAttribute("name", "bitrixUserFields_" + nextId);
matchedElement.querySelector("select[name='crmUserFields']").setAttribute("name", "crmUserFields_" + nextId);
matchedElement.removeAttribute("hidden");
document.getElementById("field_matched").appendChild(matchedElement);
document.getElementById("User_matched").appendChild(matchedElement);
}
function deleteMatched(element)
@ -1462,16 +1487,16 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
function generateEmptyMatched()
{
let elements = document.getElementsByClassName("adm-list-table-row matchedProps");
let elements = document.getElementsByClassName("adm-list-table-row matched-Order");
if (elements.length < 1) {
createMatchedOrder();
createMatched("Order");
}
elements = document.getElementsByClassName("adm-list-table-row matchedField");
elements = document.getElementsByClassName("adm-list-table-row matched-User");
if (elements.length < 1) {
createMatchedUser();
createMatched("User");
}
}
@ -2304,20 +2329,20 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
<tfoot>
<tr>
<th class="option-head option-other-top option-other-bottom" colspan="4">
<button class="adm-btn-save" type="button" onclick="createMatchedOrder()"><?php echo GetMessage('ADD_LABEL'); ?></button>
<button class="adm-btn-save" type="button" onclick="createMatched(`Order`)"><?php echo GetMessage('ADD_LABEL'); ?></button>
</th>
</tr>
</tfoot>
<tbody id="prop_matched">
<tbody id="Order_matched">
<?php
$matchedPropsNum = 1;
foreach ($arResult['matchedOrderProps'] as $bitrixProp => $crmField) {?>
<tr class="adm-list-table-row matchedProps" id="matchedOrderProps_<?php echo $matchedPropsNum ?>">
<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="bitrixOrderProp_<?php echo $bitrixProp ?>"
onchange="changeSelectBitrixValue(this, 'bitrixOrderProp_', 'crmOrderField_');"
name="bitrixOrderFields_<?php echo $bitrixProp ?>"
onchange="changeSelectBitrixValue(this, 'bitrixOrderFields_', 'crmOrderFields_');"
>
<option value=""></option>
@ -2339,7 +2364,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmOrderField_<?php echo $bitrixProp ?>"
name="crmOrderFields_<?php echo $bitrixProp ?>"
id="crmOrder_<?php echo $crmField?>"
onchange="changeSelectCrmValue(this, 'crmOrder_')"
>
@ -2378,20 +2403,20 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
<tfoot>
<tr>
<th class="option-head option-other-top option-other-bottom" colspan="4">
<button class="adm-btn-save" type="button" onclick="createMatchedUser()"><?php echo GetMessage('ADD_LABEL'); ?></button>
<button class="adm-btn-save" type="button" onclick="createMatched(`User`)"><?php echo GetMessage('ADD_LABEL'); ?></button>
</th>
</tr>
</tfoot>
<tbody id="field_matched">
<tbody id="User_matched">
<?php
$matchedFieldsNum = 1;
foreach ($arResult['matchedUserFields'] as $bitrixProp => $crmField) {?>
<tr class="adm-list-table-row matchedField" id="matchedUserProps_<?php echo $matchedFieldsNum ?>">
<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="bitrixUserField_<?php echo $bitrixProp ?>"
onchange="changeSelectBitrixValue(this, 'bitrixUserField_', 'crmUserField_');"
name="bitrixUserFields_<?php echo $bitrixProp ?>"
onchange="changeSelectBitrixValue(this, 'bitrixUserFields_', 'crmUserFields_');"
>
<option value=""></option>
<?php foreach ($arResult['bitrixCustomUserFields'] as $type => $mass) {?>
@ -2412,7 +2437,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmUserField_<?php echo $bitrixProp ?>"
name="crmUserFields_<?php echo $bitrixProp ?>"
id="crmClient_<?php echo $crmField?>"
onchange="changeSelectCrmValue(this, 'crmClient_')"
>
@ -2441,12 +2466,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
</td>
</tr>
<tr id="orderMatchedPropsBlank" hidden="hidden">
<tr id="OrderMatchedFieldsBlank" hidden="hidden">
<td class="adm-list-table-cell adm-detail-content-cell-l" colspan="2" width="50%">
<select
style="width: 200px;" class="typeselect"
name="bitrixOrderProp"
onchange="changeSelectBitrixValue(this, 'bitrixOrderProp_', 'crmOrderField_');"
name="bitrixOrderFields"
onchange="changeSelectBitrixValue(this, 'bitrixOrderFields_', 'crmOrderFields_');"
>
<option value=""></option>
<?php foreach ($arResult['bitrixOrdersCustomProp'] as $type => $mass) {?>
@ -2468,7 +2493,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmOrderField"
name="crmOrderFields"
onchange="changeSelectCrmValue(this, 'crmOrder_')"
>
<option value=""></option>
@ -2490,12 +2515,12 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
</td>
</tr>
<tr id="userMatchedFieldsBlank" hidden="hidden">
<tr id="UserMatchedFieldsBlank" hidden="hidden">
<td class="adm-list-table-cell adm-detail-content-cell-l" colspan="2" width="50%">
<select
style="width: 200px;" class="typeselect"
name="bitrixUserField"
onchange="changeSelectBitrixValue(this, 'bitrixUserField_', 'crmUserField_');"
name="bitrixUserFields"
onchange="changeSelectBitrixValue(this, 'bitrixUserFields_', 'crmUserFields_');"
>
<option value=""></option>
<?php foreach ($arResult['bitrixCustomUserFields'] as $type => $mass) {?>
@ -2513,7 +2538,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] === 'Y')) {
&nbsp;&nbsp;&nbsp;&nbsp;
<select
style="width: 200px;" class="typeselect"
name="crmUserField"
name="crmUserFields"
onchange="changeSelectCrmValue(this, 'crmClient_')"
>
<option value=""></option>

View file

@ -1188,6 +1188,16 @@ function update()
->updateBonusFieldsTypeInHl()
->updateDefDiscountFieldTypeInHl();
UnRegisterModuleDependences("main", "OnBeforeProlog", 'intaro.retailcrm', "RetailCrmPricePrchase", "add");
UnRegisterModuleDependences("main", "OnBeforeProlog", 'intaro.retailcrm', "RetailCrmDc", "add");
UnRegisterModuleDependences("main", "OnBeforeProlog", 'intaro.retailcrm', "RetailCrmCc", "add");
(new UpdateSubscribe())
->CopyFiles()
->addEvent()
->addCustomUserField()
;
COption::SetOptionString(
'intaro.retailcrm',
'custom_fields_toggle',

View file

@ -42,7 +42,7 @@ class RetailCrmHistory_v5Test extends \BitrixTestCase
$actionsMock->shouldReceive('getTypeUserField')->withAnyArgs()->andReturn([
'UF_FIELD_USER_1' => 'string', 'UF_FIELD_USER_2' => 'string'
]);
$actionsMock->shouldReceive('convertCrmValueToFieldUser')->byDefault();
$actionsMock->shouldReceive('convertCrmValueToCmsField')->byDefault();
$this->deleteTestingUser();
RetailCrmHistory::customerHistory();