fixes for corporate customers duplicates
This commit is contained in:
parent
395f0b8aa8
commit
c1208daff6
3 changed files with 75 additions and 18 deletions
|
@ -266,8 +266,7 @@ class RetailCrmEvent
|
|||
}
|
||||
|
||||
if (!isset($userCorp['customerCorporate'])) {
|
||||
|
||||
$resultUserCorp = RetailCrmCorporateClient::clientSend($arOrder, $api, $optionsContragentType[$arOrder['PERSON_TYPE_ID']], true, $site);
|
||||
$resultUserCorp = RetailCrmCorporateClient::clientSend($arOrder, $api, $optionsContragentType[$arOrder['PERSON_TYPE_ID']], true, false, $site);
|
||||
|
||||
$log = new Logger();
|
||||
$log->write($resultUserCorp, 'resultUserCorp');
|
||||
|
@ -280,20 +279,20 @@ class RetailCrmEvent
|
|||
|
||||
$arParams['customerCorporate'] = $resultUserCorp;
|
||||
|
||||
//TODO address bulder add
|
||||
$customerCorporateAdress = array(
|
||||
//TODO address builder add
|
||||
$customerCorporateAddress = array(
|
||||
'name' => $nickName,
|
||||
'isMain' => true,
|
||||
'text' => $address
|
||||
);
|
||||
|
||||
$adressResult = $api->customersCorporateAddressesCreate($resultUserCorp['id'], $customerCorporateAdress, 'id', $site);
|
||||
$addressResult = $api->customersCorporateAddressesCreate($resultUserCorp['id'], $customerCorporateAddress, 'id', $site);
|
||||
$customerCorporateCompani = array(
|
||||
'name' => $nickName,
|
||||
'isMain' => true,
|
||||
'contragent' => $contragent,
|
||||
'address' => array(
|
||||
'id' =>$adressResult['id']
|
||||
'id' =>$addressResult['id']
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -438,6 +438,15 @@ class RetailCrmOrder
|
|||
$site
|
||||
);
|
||||
|
||||
$arCustomerCorporate = RetailCrmCorporateClient::clientSend(
|
||||
$order,
|
||||
$api,
|
||||
'legal-entity',
|
||||
false,
|
||||
true,
|
||||
$site
|
||||
);
|
||||
|
||||
$arParams['contactExId'] = $user['ID'];
|
||||
} else {
|
||||
$arCustomer = RetailCrmUser::customerSend(
|
||||
|
@ -459,8 +468,9 @@ class RetailCrmOrder
|
|||
continue;
|
||||
}
|
||||
|
||||
if (!empty($arCustomerCorporate)) {
|
||||
$resCustomersCorporate[$order['LID']][] = $arCustomerCorporate;
|
||||
if (!empty($arCustomerCorporate) && !empty($arCustomerCorporate['nickName'])
|
||||
) {
|
||||
$resCustomersCorporate[$arCustomerCorporate['nickName']] = $arCustomerCorporate;
|
||||
}
|
||||
|
||||
$resCustomers[$order['LID']][] = $arCustomer;
|
||||
|
@ -514,13 +524,8 @@ class RetailCrmOrder
|
|||
return false;
|
||||
}
|
||||
|
||||
if (false === $uploadItems($resCustomersCorporate, 'customersCorporateUpload')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("Y" == $optionCorpClient) {
|
||||
foreach ($resOrders as $packKey => $pack) {
|
||||
|
||||
foreach ($pack as $key => $orderData) {
|
||||
if (isset($orderData['contragent']['contragentType'])
|
||||
&& $orderData['contragent']['contragentType'] == 'legal-entity'
|
||||
|
@ -538,9 +543,17 @@ class RetailCrmOrder
|
|||
$corpData = reset($corpData);
|
||||
|
||||
$orderData['customer'] = array('id' => $corpData['id']);
|
||||
$pack[$key] = $orderData;
|
||||
} elseif (array_key_exists($orderData['contragent']['legalName'], $resCustomersCorporate)) {
|
||||
$createResponse = $api
|
||||
->customersCreate($resCustomersCorporate[$orderData['contragent']['legalName']]);
|
||||
|
||||
if ($createResponse && $createResponse->isSuccessful()) {
|
||||
$orderData['customer'] = array('id' => $createResponse['id']);
|
||||
}
|
||||
}
|
||||
|
||||
$pack[$key] = $orderData;
|
||||
|
||||
time_nanosleep(0, 250000000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,17 +7,20 @@ class RetailCrmCorporateClient
|
|||
public static $CRM_CORP_NAME = 'nickName-corporate';
|
||||
public static $CRM_LEGAL_DETAILS = 'legal_details';
|
||||
public static $CRM_DELIVERY_TYPES_ARR = 'deliv_types_arr';
|
||||
public static $CRM_CORP_ADRES = 'adres-corporate';
|
||||
public static $CRM_CORP_ADDRESS = 'adres-corporate';
|
||||
public static $CRM_ORDER_PROPS = 'order_props';
|
||||
|
||||
public static function clientSend($arOrder, $api, $contragentType, $send = false, $site = null)
|
||||
public static function clientSend($arOrder, $api, $contragentType, $send = false, $fillCorp = false, $site = null)
|
||||
{
|
||||
if (!$api || empty($contragentType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$address = array();
|
||||
$contragent = array();
|
||||
$shops = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_SITES_LIST, 0));
|
||||
$corpName = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_NAME, 0));
|
||||
$corpAdres = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_ADRES, 0));
|
||||
$corpAdres = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_CORP_ADDRESS, 0));
|
||||
$arUser = Bitrix\Main\UserTable::getById($arOrder['USER_ID'])->fetch();
|
||||
$optionsLegalDetails = unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_LEGAL_DETAILS, 0));
|
||||
|
||||
|
@ -31,6 +34,16 @@ class RetailCrmCorporateClient
|
|||
if ($prop['CODE'] == $corpName) {
|
||||
$nickName = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
if ($prop['CODE'] == $corpAdres) {
|
||||
$address = $prop['VALUE'][0];
|
||||
}
|
||||
|
||||
if (!empty($optionsLegalDetails)
|
||||
&& $search = array_search($prop['CODE'], $optionsLegalDetails[$arOrder['PERSON_TYPE_ID']])
|
||||
) {
|
||||
$contragent[$search] = $prop['VALUE'][0];//legal order data
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($nickName)) {
|
||||
|
@ -46,9 +59,39 @@ class RetailCrmCorporateClient
|
|||
'createdAt' => $arOrder['DATE_INSERT'],
|
||||
"nickName" => $nickName,
|
||||
);
|
||||
|
||||
if ($fillCorp) {
|
||||
$customerCorporate = array_merge(
|
||||
$customerCorporate,
|
||||
array(
|
||||
'customerContacts' => array(
|
||||
array(
|
||||
'isMain' => true,
|
||||
'customer' => array(
|
||||
'externalId' => $arUser['ID'],
|
||||
'site' => $shop
|
||||
)
|
||||
)
|
||||
),
|
||||
'companies' => array(
|
||||
array(
|
||||
'name' => $nickName,
|
||||
'isMain' => true,
|
||||
)
|
||||
),
|
||||
'addresses' => array(
|
||||
array(
|
||||
'name' => $nickName,
|
||||
'isMain' => true,
|
||||
'text' => $address
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ($customerCorporate) {
|
||||
if (isset($customerCorporate)) {
|
||||
if ($send && isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != '') {
|
||||
$customerCorporate['browserId'] = $_COOKIE['_rc'];
|
||||
}
|
||||
|
@ -70,5 +113,7 @@ class RetailCrmCorporateClient
|
|||
|
||||
return $customerCorporate;
|
||||
}
|
||||
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue