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