issues #75 запись в лог перед отправкой в црм
This commit is contained in:
parent
a0db53017c
commit
46c50034f3
@ -3,7 +3,7 @@ IncludeModuleLangFile(__FILE__);
|
||||
class RetailCrmUser
|
||||
{
|
||||
public static function customerSend($arFields, $api, $contragentType, $send = false, $site = null)
|
||||
{
|
||||
{
|
||||
if (!$api || empty($contragentType)) {
|
||||
return false;
|
||||
}
|
||||
@ -11,7 +11,7 @@ class RetailCrmUser
|
||||
RCrmActions::eventLog('RetailCrmUser::customerSend', 'empty($arFields)', 'incorrect customer');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$customer = array(
|
||||
'externalId' => $arFields['ID'],
|
||||
'email' => $arFields['EMAIL'],
|
||||
@ -20,7 +20,7 @@ class RetailCrmUser
|
||||
'contragentType' => $contragentType
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
if (!empty($arFields['NAME'])) {
|
||||
$customer['firstName'] = $arFields['NAME'];
|
||||
}
|
||||
@ -30,14 +30,14 @@ class RetailCrmUser
|
||||
if (!empty($arFields['SECOND_NAME'])) {
|
||||
$customer['patronymic'] = $arFields['SECOND_NAME'];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arFields['PERSONAL_PHONE'])) {
|
||||
$customer['phones'][]['number'] = $arFields['PERSONAL_PHONE'];
|
||||
}
|
||||
if (!empty($arFields['WORK_PHONE'])) {
|
||||
$customer['phones'][]['number'] = $arFields['WORK_PHONE'];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arFields['PERSONAL_CITY'])) {
|
||||
$customer['address']['city'] = $arFields['PERSONAL_CITY'];
|
||||
}
|
||||
@ -47,7 +47,7 @@ class RetailCrmUser
|
||||
if (!empty($arFields['PERSONAL_ZIP'])) {
|
||||
$customer['address']['index'] = $arFields['PERSONAL_ZIP'];
|
||||
}
|
||||
|
||||
|
||||
if ($send && isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != '') {
|
||||
$customer['browserId'] = $_COOKIE['_rc'];
|
||||
}
|
||||
@ -58,37 +58,37 @@ class RetailCrmUser
|
||||
$customer = $newResCustomer;
|
||||
} elseif ($newResCustomer === false) {
|
||||
RCrmActions::eventLog('RetailCrmUser::customerSend', 'retailCrmBeforeCustomerSend()', 'UserID = ' . $arFields['ID'] . '. Sending canceled after retailCrmBeforeCustomerSend');
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
$normalizer = new RestNormalizer();
|
||||
$customer = $normalizer->normalize($customer, 'customers');
|
||||
|
||||
|
||||
$log = new Logger();
|
||||
$log->write($customer, 'customerSend');
|
||||
|
||||
|
||||
if ($send) {
|
||||
if (!RCrmActions::apiMethod($api, 'customersCreate', __METHOD__, $customer, $site)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
|
||||
public static function customerEdit($arFields, $api, $optionsSitesList = array()){
|
||||
if (empty($arFields)) {
|
||||
RCrmActions::eventLog('RetailCrmUser::customerEdit', 'empty($arFields)', 'incorrect customer');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$customer = array(
|
||||
'externalId' => $arFields['ID'],
|
||||
'email' => $arFields['EMAIL'],
|
||||
);
|
||||
|
||||
|
||||
if (!empty($arFields['NAME'])) {
|
||||
$customer['firstName'] = $arFields['NAME'];
|
||||
}
|
||||
@ -98,14 +98,14 @@ class RetailCrmUser
|
||||
if (!empty($arFields['SECOND_NAME'])) {
|
||||
$customer['patronymic'] = $arFields['SECOND_NAME'];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arFields['PERSONAL_PHONE'])) {
|
||||
$customer['phones'][]['number'] = $arFields['PERSONAL_PHONE'];
|
||||
}
|
||||
if (!empty($arFields['WORK_PHONE'])) {
|
||||
$customer['phones'][]['number'] = $arFields['WORK_PHONE'];
|
||||
}
|
||||
|
||||
|
||||
if (!empty($arFields['PERSONAL_CITY'])) {
|
||||
$customer['address']['city'] = $arFields['PERSONAL_CITY'];
|
||||
}
|
||||
@ -115,7 +115,7 @@ class RetailCrmUser
|
||||
if (!empty($arFields['PERSONAL_ZIP'])) {
|
||||
$customer['address']['index'] = $arFields['PERSONAL_ZIP'];
|
||||
}
|
||||
|
||||
|
||||
$found = false;
|
||||
if (count($optionsSitesList) > 0) {
|
||||
foreach ($optionsSitesList as $site) {
|
||||
@ -137,9 +137,6 @@ class RetailCrmUser
|
||||
$normalizer = new RestNormalizer();
|
||||
$customer = $normalizer->normalize($customer, 'customers');
|
||||
|
||||
$log = new Logger();
|
||||
$log->write($customer, 'customerSend');
|
||||
|
||||
if (function_exists('retailCrmBeforeCustomerSend')) {
|
||||
$newResCustomer = retailCrmBeforeCustomerSend($customer);
|
||||
if (is_array($newResCustomer) && !empty($newResCustomer)) {
|
||||
@ -151,9 +148,12 @@ class RetailCrmUser
|
||||
}
|
||||
}
|
||||
|
||||
$log = new Logger();
|
||||
$log->write($customer, 'customerSend');
|
||||
|
||||
RCrmActions::apiMethod($api, 'customersEdit', __METHOD__, $customer, $site);
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user