1
0
Fork 0
mirror of synced 2025-04-04 14:23:33 +03:00

ref #91040 Удаление не используемого кода, исправление дублирования кода

This commit is contained in:
Ivan Chaplygin 2023-08-11 17:47:00 +03:00
parent ec7461be1a
commit f8acb7833e
3 changed files with 17 additions and 62 deletions

View file

@ -13,7 +13,6 @@ use Bitrix\Sale\Order;
use Intaro\RetailCrm\Component\ConfigProvider;
use Intaro\RetailCrm\Model\Api\Response\OrdersCreateResponse;
use Intaro\RetailCrm\Model\Api\Response\OrdersEditResponse;
use Logger;
/**
* Class RetailCrmEvent

View file

@ -156,13 +156,7 @@ class RetailCrmHistory
if ($registerNewUser === true) {
$customerBuilder->buildPassword();
$customerArray = $customerBuilder->getCustomer()->getObjectToArray();
if (!array_key_exists('UF_SUBSCRIBE_USER_EMAIL', $customerArray)) {
$customerArray['UF_SUBSCRIBE_USER_EMAIL'] = 'Y';
}
$registeredUserID = $newUser->Add(self::convertBooleanFields($customerArray));
$registeredUserID = $newUser->Add(self::getDataUser($customerBuilder));
if ($registeredUserID === false) {
RCrmActions::eventLog(
@ -932,13 +926,7 @@ class RetailCrmHistory
}
if ($registerNewUser === true) {
$customerArray = $customerBuilder->getCustomer()->getObjectToArray();
if (!array_key_exists('UF_SUBSCRIBE_USER_EMAIL', $customerArray)) {
$customerArray['UF_SUBSCRIBE_USER_EMAIL'] = 'Y';
}
$registeredUserID = $newUser->Add(self::convertBooleanFields($customerArray));
$registeredUserID = $newUser->Add(self::getDataUser($customerBuilder));
if ($registeredUserID === false) {
RCrmActions::eventLog(
@ -2119,4 +2107,19 @@ class RetailCrmHistory
return $array;
}
/**
* @param $customerBuilder
* @return array
*/
private static function getDataUser($customerBuilder)
{
$customerArray = $customerBuilder->getCustomer()->getObjectToArray();
if (!array_key_exists('UF_SUBSCRIBE_USER_EMAIL', $customerArray)) {
$customerArray['UF_SUBSCRIBE_USER_EMAIL'] = 'Y';
}
return self::convertBooleanFields($customerArray);
}
}

View file

@ -214,51 +214,4 @@ class EventsHandlers
Logger::getInstance()->write(GetMessage('CAN_NOT_SAVE_ORDER') . $exception->getMessage(), 'uploadApiErrors');
}
}
/**
* Регистрирует пользователя в CRM системе после регистрации на сайте
*
* @param array $arFields
* @return mixed
* @throws \ReflectionException
*/
public static function OnAfterUserRegisterHandler(array $arFields): void
{
if (isset($arFields['USER_ID']) && $arFields['USER_ID'] > 0) {
$user = UserRepository::getById($arFields['USER_ID']);
if (isset($_POST['REGISTER']['PERSONAL_PHONE'])) {
$phone = htmlspecialchars($_POST['REGISTER']['PERSONAL_PHONE']);
if ($user !== null) {
$user->setPersonalPhone($phone);
$user->save();
}
$arFields['PERSONAL_PHONE'] = $phone;
}
/* @var CustomerService $customerService */
$customerService = ServiceLocator::get(CustomerService::class);
$customer = $customerService->createModel($arFields['USER_ID']);
$customerService->createOrUpdateCustomer($customer);
//Если пользователь выразил желание зарегистрироваться в ПЛ и согласился со всеми правилами
if ((int) $arFields['UF_REG_IN_PL_INTARO'] === 1
&& (int) $arFields['UF_AGREE_PL_INTARO'] === 1
&& (int) $arFields['UF_PD_PROC_PL_INTARO'] === 1
) {
$phone = $arFields['PERSONAL_PHONE'] ?? '';
$card = $arFields['UF_CARD_NUM_INTARO'] ?? '';
$customerId = (string) $arFields['USER_ID'];
/** @var LoyaltyAccountService $service */
$service = ServiceLocator::get(LoyaltyAccountService::class);
$createResponse = $service->createLoyaltyAccount($phone, $card, $customerId);
$service->activateLpUserInBitrix($createResponse, $arFields['USER_ID']);
}
}
}
}