1
0
mirror of synced 2024-11-25 14:56:09 +03:00
This commit is contained in:
gorokh 2019-09-17 18:10:30 +03:00
parent b98c6ba9ea
commit 27a4e558fb

View File

@ -126,7 +126,7 @@ class RetailCrmHistory
} }
if ($registerNewUser === true) { if ($registerNewUser === true) {
$userPassword = uniqid(); $userPassword = uniqid("R");
$arFields = array( $arFields = array(
"EMAIL" => $customer['email'], "EMAIL" => $customer['email'],
@ -137,7 +137,7 @@ class RetailCrmHistory
); );
$registeredUserID = $newUser->Add($arFields); $registeredUserID = $newUser->Add($arFields);
if ($registeredUserID === false) { if ($registeredUserID === false) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user'); RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user: ' . $newUser->LAST_ERROR);
continue; continue;
} }
@ -361,7 +361,7 @@ class RetailCrmHistory
} }
if ($registerNewUser === true) { if ($registerNewUser === true) {
$userPassword = uniqid(); $userPassword = uniqid("R");
$newUser = new CUser; $newUser = new CUser;
$arFields = array( $arFields = array(
@ -384,7 +384,7 @@ class RetailCrmHistory
$registeredUserID = $newUser->Add($arFields); $registeredUserID = $newUser->Add($arFields);
if ($registeredUserID === false) { if ($registeredUserID === false) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user'); RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user' . $newUser->LAST_ERROR);
continue; continue;
} }
@ -423,7 +423,7 @@ class RetailCrmHistory
if (isset($order['externalId'])) { if (isset($order['externalId'])) {
$itemUpdate = false; $itemUpdate = false;
if ($order['externalId']) { if ($order['externalId'] && is_numeric($order['externalId'])) {
try { try {
$newOrder = Bitrix\Sale\Order::load($order['externalId']); $newOrder = Bitrix\Sale\Order::load($order['externalId']);
} catch (Bitrix\Main\ArgumentNullException $e) { } catch (Bitrix\Main\ArgumentNullException $e) {
@ -566,6 +566,9 @@ class RetailCrmHistory
} }
} elseif (array_key_exists($key, $order['delivery']['address'])) { } elseif (array_key_exists($key, $order['delivery']['address'])) {
if ($propsKey[$orderProp]['TYPE'] == 'LOCATION') { if ($propsKey[$orderProp]['TYPE'] == 'LOCATION') {
if( $order['delivery']['address']['index'] ) {
$location = CSaleLocation::GetByZIP($order['delivery']['address']['index']);
}
$order['delivery']['address'][$key] = trim($order['delivery']['address'][$key]); $order['delivery']['address'][$key] = trim($order['delivery']['address'][$key]);
if(!empty($order['delivery']['address'][$key])){ if(!empty($order['delivery']['address'][$key])){
$parameters = array(); $parameters = array();
@ -582,7 +585,9 @@ class RetailCrmHistory
$parameters['filter']['NAME.LANGUAGE_ID'] = 'ru'; $parameters['filter']['NAME.LANGUAGE_ID'] = 'ru';
try { try {
$location = \Bitrix\Sale\Location\Search\Finder::find($parameters, array('USE_INDEX' => false, 'USE_ORM' => false))->fetch(); if ( !isset($location) ) {
$location = \Bitrix\Sale\Location\Search\Finder::find($parameters, array('USE_INDEX' => false, 'USE_ORM' => false))->fetch();
}
$somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']); $somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']);
self::setProp($somePropValue, $location['CODE']); self::setProp($somePropValue, $location['CODE']);
} catch (\Bitrix\Main\ArgumentException $argumentException) { } catch (\Bitrix\Main\ArgumentException $argumentException) {
@ -606,7 +611,7 @@ class RetailCrmHistory
foreach ($optionsLegalDetails[$personType] as $key => $orderProp) { foreach ($optionsLegalDetails[$personType] as $key => $orderProp) {
if (array_key_exists($key, $order)) { if (array_key_exists($key, $order)) {
$somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']); $somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']);
self::setProp($somePropValue, $order[$key]); self::setProp($somePropValue, RCrmActions::fromJSON($order[$key]));
} }
} }
} }
@ -809,7 +814,7 @@ class RetailCrmHistory
if ($paymentExternalId) { if ($paymentExternalId) {
$newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId; $newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId;
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]); RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]);
\Bitrix\Sale\Internals\PaymentTable::update($paymentExternalId, array('XML_ID' => '')); \Bitrix\Sale\Internals\PaymentTable::update($paymentId, array('XML_ID' => ''));
} }
} }
} }
@ -1057,6 +1062,7 @@ class RetailCrmHistory
if (isset($orderCrm['delivery']['service']['code'])) { if (isset($orderCrm['delivery']['service']['code'])) {
$deliveryCode = \Bitrix\Sale\Delivery\Services\Manager::getCodeById($deliveryId); $deliveryCode = \Bitrix\Sale\Delivery\Services\Manager::getCodeById($deliveryId);
$serviceCode = $orderCrm['delivery']['service']['code']; $serviceCode = $orderCrm['delivery']['service']['code'];
$service = \Bitrix\Sale\Delivery\Services\Manager::getService($deliveryId); $service = \Bitrix\Sale\Delivery\Services\Manager::getService($deliveryId);
if (is_object($service)) { if (is_object($service)) {
$services = $service->getProfilesList(); $services = $service->getProfilesList();
@ -1068,7 +1074,7 @@ class RetailCrmHistory
if ($deliveryCode) { if ($deliveryCode) {
try { try {
$deliveryService = \Bitrix\Sale\Delivery\Services\Manager::getObjectByCode($deliveryCode . ':' . $orderCrm['delivery']['service']['code']); $deliveryService = \Bitrix\Sale\Delivery\Services\Manager::getObjectByCode($deliveryCode . ':' . $serviceCode);
} catch (Bitrix\Main\SystemException $systemException) { } catch (Bitrix\Main\SystemException $systemException) {
RCrmActions::eventLog('RetailCrmHistory::deliveryEdit', '\Bitrix\Sale\Delivery\Services\Manager::getObjectByCode', $systemException->getMessage()); RCrmActions::eventLog('RetailCrmHistory::deliveryEdit', '\Bitrix\Sale\Delivery\Services\Manager::getObjectByCode', $systemException->getMessage());
} }
@ -1206,7 +1212,8 @@ class RetailCrmHistory
foreach ($paymentsCrm['payments'] as $paymentCrm) { foreach ($paymentsCrm['payments'] as $paymentCrm) {
if (isset($paymentCrm['externalId']) && !empty($paymentCrm['externalId'])) { if (isset($paymentCrm['externalId']) && !empty($paymentCrm['externalId'])) {
//find the payment //find the payment
$nowPayment = $paymentsList[$paymentCrm['externalId']]; $nowPaymentId = RCrmActions::getFromPaymentExternalId($paymentCrm['externalId']);
$nowPayment = $paymentsList[$nowPaymentId];
//update data //update data
if ($nowPayment instanceof \Bitrix\Sale\Payment) { if ($nowPayment instanceof \Bitrix\Sale\Payment) {
$nowPayment->setField('SUM', $paymentCrm['amount']); $nowPayment->setField('SUM', $paymentCrm['amount']);
@ -1218,7 +1225,7 @@ class RetailCrmHistory
$nowPayment->setField('PAID', $optionsPayment[$paymentCrm['status']]); $nowPayment->setField('PAID', $optionsPayment[$paymentCrm['status']]);
} }
unset($paymentsList[$paymentCrm['externalId']]); unset($paymentsList[$nowPaymentId]);
} }
} elseif (array_key_exists($paymentCrm['type'], $optionsPayTypes)) { } elseif (array_key_exists($paymentCrm['type'], $optionsPayTypes)) {
$newHistoryPayments[$paymentCrm['id']] = $paymentCrm; $newHistoryPayments[$paymentCrm['id']] = $paymentCrm;