1
0
Fork 0
mirror of synced 2025-04-20 01:21:01 +00:00

use companyName filter in event & pass companyName into order

This commit is contained in:
Pavel 2020-03-18 13:55:12 +03:00 committed by gorokh
parent f224fed6ca
commit 2eb23bc109
2 changed files with 55 additions and 10 deletions

View file

@ -193,6 +193,8 @@ class RetailCrmEvent
$methodApi = 'ordersCreate';
}
$orderCompany = null;
if ("Y" == $optionCorpClient && $optionsContragentType[$arOrder['PERSON_TYPE_ID']] == 'legal-entity') {
//corparate cliente
$nickName = '';
@ -224,10 +226,37 @@ class RetailCrmEvent
}
$customersCorporate = false;
$response = $api->customersCorporateList(array('nickName' => array($nickName)));
$response = $api->customersCorporateList(array('companyName' => $nickName));
if ($response && $response->getStatusCode() == 200) {
$customersCorporate = $response['customersCorporate'];
$singleCorp = reset($customersCorporate);
if (!empty($singleCorp)) {
$userCorp['customerCorporate'] = $singleCorp;
$companiesResponse = $api->customersCorporateCompanies(
$singleCorp['id'],
array(),
null,
null,
'id',
$site
);
if ($companiesResponse && $companiesResponse->isSuccessful()) {
$orderCompany = array_reduce(
$companiesResponse['companies'],
function ($carry, $item) use ($nickName) {
if (is_array($item) && $item['name'] == $nickName) {
$carry = $item;
}
return $carry;
},
null
);
}
}
} else {
RCrmActions::eventLog(
'RetailCrmEvent::orderSave',
@ -238,14 +267,6 @@ class RetailCrmEvent
return false;
}
foreach ($customersCorporate as $corp) {
if (isset($corp['mainCompany']['name']) && $nickName == $corp['mainCompany']['name']) {
$userCorp['customerCorporate'] = $corp;
break;
}
}
//user
$userCrm = RCrmActions::apiMethod($api, 'customersGet', __METHOD__, $arOrder['USER_ID'], $site);
@ -290,6 +311,7 @@ class RetailCrmEvent
}
$arParams['customerCorporate'] = $resultUserCorp;
$arParams['orderCompany'] = isset($resultUserCorp['mainCompany']) ? $resultUserCorp['mainCompany'] : null;
$customerCorporateAddress = array();
$customerCorporateCompany = array();
@ -392,6 +414,10 @@ class RetailCrmEvent
}
$arParams['customerCorporate'] = $userCorp['customerCorporate'];
if (!empty($orderCompany)) {
$arParams['orderCompany'] = $orderCompany;
}
}
$arParams['contactExId'] = $userCrm['customer']['externalId'];
@ -411,6 +437,7 @@ class RetailCrmEvent
//order
$resultOrder = RetailCrmOrder::orderSend($arOrder, $api, $arParams, true, $site, $methodApi);
if (!$resultOrder) {
RCrmActions::eventLog('RetailCrmEvent::orderSave', 'RetailCrmOrder::orderSend', 'error during creating order');

View file

@ -54,6 +54,18 @@ class RetailCrmOrder
$order['contact']['externalId'] = $arParams['contactExId'];
}
if (isset($arParams['orderCompany']) && !empty($arParams['orderCompany'])) {
$company = $arParams['orderCompany'];
if (isset($company['id'])) {
$order['company']['id'] = $company['id'];
}
if (isset($company['name'])) {
$order['contragent']['legalName'] = $company['name'];
}
}
if ($send && isset($_COOKIE['_rc']) && $_COOKIE['_rc'] != '') {
$order['customer']['browserId'] = $_COOKIE['_rc'];
}
@ -88,15 +100,18 @@ class RetailCrmOrder
if ($arLoc) {
$server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
$countrys = array();
if (file_exists($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml')) {
$countrysFile = simplexml_load_file($server . '/bitrix/modules/intaro.retailcrm/classes/general/config/country.xml');
foreach ($countrysFile->country as $country) {
$countrys[RCrmActions::fromJSON((string) $country->name)] = (string) $country->alpha;
}
}
$location = \Bitrix\Sale\Location\Name\LocationTable::getList(array(
'filter' => array('=LOCATION_ID' => $arLoc['CITY_ID'], 'LANGUAGE_ID' => 'ru')
))->fetch();
if (count($countrys) > 0) {
$countryOrder = \Bitrix\Sale\Location\Name\LocationTable::getList(array(
'filter' => array('=LOCATION_ID' => $arLoc['COUNTRY_ID'], 'LANGUAGE_ID' => 'ru')
@ -605,10 +620,11 @@ class RetailCrmOrder
'BASKET' => array(),
'USER_DESCRIPTION' => $obOrder->getField('USER_DESCRIPTION'),
'COMMENTS' => $obOrder->getField('COMMENTS'),
'REASON_CANCELED' => $obOrder->getField('REASON_CANCELED'),
'REASON_CANCELED' => $obOrder->getField('REASON_CANCELED')
);
$shipmentList = $obOrder->getShipmentCollection();
foreach ($shipmentList as $shipmentData) {
if ($shipmentData->isSystem()) {
continue;
@ -633,11 +649,13 @@ class RetailCrmOrder
}
$paymentList = $obOrder->getPaymentCollection();
foreach ($paymentList as $paymentData) {
$arOrder['PAYMENTS'][] = $paymentData->getFields()->getValues();
}
$basketItems = $obOrder->getBasket();
foreach ($basketItems as $item) {
$arOrder['BASKET'][] = $item->getFields();
}