ref #92774
Проверка опции передачи кастомных полей Передача кастомных полей по истории
This commit is contained in:
parent
58500a722b
commit
b43d17cf4f
3 changed files with 51 additions and 6 deletions
|
@ -49,6 +49,7 @@ class RetailCrmHistory
|
|||
public static $CRM_CANSEL_ORDER = 'cansel_order';
|
||||
public static $CRM_CURRENCY = 'currency';
|
||||
public static $CRM_DISCOUNT_ROUND = 'discount_round';
|
||||
public static $CUSTOM_FIELDS_IS_ACTIVE = 'N';
|
||||
|
||||
const PAGE_LIMIT = 25;
|
||||
|
||||
|
@ -63,6 +64,10 @@ class RetailCrmHistory
|
|||
$historyStart = RetailcrmConfigProvider::getCustomersHistorySinceId();
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
|
||||
$matchedCustomFields = RetailcrmConfigProvider::getMatchedUserFields() ?? [];
|
||||
$matchedCustomFields = array_flip($matchedCustomFields);
|
||||
self::$CUSTOM_FIELDS_IS_ACTIVE = RetailcrmConfigProvider::getCustomFieldsStatus();
|
||||
|
||||
if ($historyStart && $historyStart > 0) {
|
||||
$historyFilter['sinceId'] = $historyStart;
|
||||
}
|
||||
|
@ -124,6 +129,8 @@ class RetailCrmHistory
|
|||
|
||||
$customerBuilder->setDataCrm($customer)->build();
|
||||
|
||||
$customFields = self::getCustomUserFields($customer, $matchedCustomFields);
|
||||
|
||||
if (!isset($customer['externalId'])) {
|
||||
if (!isset($customer['id'])) {
|
||||
continue;
|
||||
|
@ -155,7 +162,7 @@ class RetailCrmHistory
|
|||
if ($registerNewUser === true) {
|
||||
$customerBuilder->buildPassword();
|
||||
|
||||
$registeredUserID = $newUser->Add(self::getDataUser($customerBuilder));
|
||||
$registeredUserID = $newUser->Add(self::getDataUser($customerBuilder, $customFields));
|
||||
|
||||
if ($registeredUserID === false) {
|
||||
RCrmActions::eventLog(
|
||||
|
@ -197,6 +204,8 @@ class RetailCrmHistory
|
|||
}
|
||||
|
||||
$customerArray = $customerBuilder->getCustomer()->getObjectToArray();
|
||||
$customerArray = array_merge($customerArray, $customFields);
|
||||
|
||||
$u = $newUser->Update($customer['externalId'], self::convertBooleanFields($customerArray));
|
||||
|
||||
if (!$u) {
|
||||
|
@ -261,6 +270,10 @@ class RetailCrmHistory
|
|||
$contragentTypes = array_flip(RetailcrmConfigProvider::getContragentTypes());
|
||||
$shipmentDeducted = RetailcrmConfigProvider::getShipmentDeducted();
|
||||
|
||||
$matchedCustomFields = RetailcrmConfigProvider::getMatchedUserFields() ?? [];
|
||||
$matchedCustomFields = array_flip($matchedCustomFields);
|
||||
self::$CUSTOM_FIELDS_IS_ACTIVE = RetailcrmConfigProvider::getCustomFieldsStatus();
|
||||
|
||||
$api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey());
|
||||
$page = 1;
|
||||
/* @var OrderLoyaltyDataService $orderLoyaltyDataService */
|
||||
|
@ -459,6 +472,9 @@ class RetailCrmHistory
|
|||
$newUser = new CUser();
|
||||
$customerArray = $corporateCustomerBuilder->getCustomer()->getObjectToArray();
|
||||
|
||||
$customFields = self::getCustomUserFields($userData, $matchedCustomFields);
|
||||
$customerArray = array_merge($customerArray, $customFields);
|
||||
|
||||
if (!array_key_exists('UF_SUBSCRIBE_USER_EMAIL', $customerArray)) {
|
||||
$customerArray['UF_SUBSCRIBE_USER_EMAIL'] = 'Y';
|
||||
}
|
||||
|
@ -925,7 +941,8 @@ class RetailCrmHistory
|
|||
}
|
||||
|
||||
if ($registerNewUser === true) {
|
||||
$registeredUserID = $newUser->Add(self::getDataUser($customerBuilder));
|
||||
$customFields = self::getCustomUserFields($response['customer'], $matchedCustomFields);
|
||||
$registeredUserID = $newUser->Add(self::getDataUser($customerBuilder, $customFields));
|
||||
|
||||
if ($registeredUserID === false) {
|
||||
RCrmActions::eventLog(
|
||||
|
@ -2113,7 +2130,7 @@ class RetailCrmHistory
|
|||
* @param $customerBuilder
|
||||
* @return array
|
||||
*/
|
||||
private static function getDataUser($customerBuilder)
|
||||
private static function getDataUser($customerBuilder, $customFields)
|
||||
{
|
||||
$customerArray = $customerBuilder->getCustomer()->getObjectToArray();
|
||||
|
||||
|
@ -2121,6 +2138,26 @@ class RetailCrmHistory
|
|||
$customerArray['UF_SUBSCRIBE_USER_EMAIL'] = 'Y';
|
||||
}
|
||||
|
||||
$customerArray = array_merge($customerArray, $customFields);
|
||||
|
||||
return self::convertBooleanFields($customerArray);
|
||||
}
|
||||
|
||||
private static function getCustomUserFields($customer, $matchedCustomFields)
|
||||
{
|
||||
$customFields = [];
|
||||
|
||||
if (self::$CUSTOM_FIELDS_IS_ACTIVE === 'Y'
|
||||
&& isset($customer['customFields'])
|
||||
&& is_array($customer['customFields'])
|
||||
) {
|
||||
foreach ($customer['customFields'] as $code => $value) {
|
||||
if (isset($matchedCustomFields[$code])) {
|
||||
$customFields[$matchedCustomFields[$code]] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $customFields;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,6 +123,7 @@ class RetailCrmOrder
|
|||
|
||||
$countryList = BitrixOrderService::getCountryList();
|
||||
$deliveryAddress = ['city' => '', 'text' => '', 'index' => '', 'region' => '', 'countryIso' => ''];
|
||||
$isSendCustomFields = RetailcrmConfigProvider::getCustomFieldsStatus();
|
||||
|
||||
//Order fields
|
||||
foreach ($arOrder['PROPS']['properties'] as $prop) {
|
||||
|
@ -131,7 +132,8 @@ class RetailCrmOrder
|
|||
&& $search = array_search($prop['CODE'], $arParams['optionsLegalDetails'][$arOrder['PERSON_TYPE_ID']])
|
||||
) {
|
||||
$order['contragent'][$search] = $prop['VALUE'][0];//legal order data
|
||||
} elseif (!empty($arParams['customOrderProps'])
|
||||
} elseif ($isSendCustomFields === 'Y'
|
||||
&& !empty($arParams['customOrderProps'])
|
||||
&& isset($arParams['customOrderProps'][$prop['ID'] . '#' . $prop['CODE']])
|
||||
) {
|
||||
$order['customFields'][$arParams['customOrderProps'][$prop['ID'] . '#' . $prop['CODE']]] = $prop['VALUE'][0];
|
||||
|
|
|
@ -26,10 +26,13 @@ class RetailCrmUser
|
|||
}
|
||||
|
||||
$customer = self::getSimpleCustomer($arFields);
|
||||
$customer['customFields'] = self::getCustomFields($arFields);
|
||||
$customer['createdAt'] = new \DateTime($arFields['DATE_REGISTER']);
|
||||
$customer['contragent'] = ['contragentType' => $contragentType];
|
||||
|
||||
if (RetailcrmConfigProvider::getCustomFieldsStatus() === 'Y') {
|
||||
$customer['customFields'] = self::getCustomFields($arFields);
|
||||
}
|
||||
|
||||
if ($send && isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != '') {
|
||||
$customer['browserId'] = $_COOKIE['_rc'];
|
||||
}
|
||||
|
@ -74,9 +77,12 @@ class RetailCrmUser
|
|||
}
|
||||
|
||||
$customer = self::getSimpleCustomer($arFields);
|
||||
$customer['customFields'] = self::getCustomFields($arFields);
|
||||
$found = false;
|
||||
|
||||
if (RetailcrmConfigProvider::getCustomFieldsStatus() === 'Y') {
|
||||
$customer['customFields'] = self::getCustomFields($arFields);
|
||||
}
|
||||
|
||||
if (count($optionsSitesList) > 0) {
|
||||
foreach ($optionsSitesList as $site) {
|
||||
$userCrm = RCrmActions::apiMethod($api, 'customersGet', __METHOD__, $arFields['ID'], $site);
|
||||
|
|
Loading…
Add table
Reference in a new issue