add error handler in register component
This commit is contained in:
parent
433a889fdd
commit
461129aed6
5 changed files with 69 additions and 25 deletions
|
@ -1,4 +1,7 @@
|
|||
<?php
|
||||
|
||||
use Intaro\RetailCrm\Component\ConfigProvider;
|
||||
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
class RetailCrmOrder
|
||||
{
|
||||
|
@ -282,6 +285,10 @@ class RetailCrmOrder
|
|||
$order['payments'] = $payments;
|
||||
}
|
||||
|
||||
if (ConfigProvider::getLoyaltyProgramStatus() === 'Y') {
|
||||
$order['privilegeType'] = 'loyalty_level';
|
||||
}
|
||||
|
||||
//send
|
||||
if (function_exists('retailCrmBeforeOrderSend')) {
|
||||
$newResOrder = retailCrmBeforeOrderSend($order, $arFields);
|
||||
|
@ -306,7 +313,7 @@ class RetailCrmOrder
|
|||
$order = $normalizer->normalize($order, 'orders');
|
||||
|
||||
Logger::getInstance()->write($order, 'orderSend');
|
||||
|
||||
|
||||
if ($send) {
|
||||
if (!RCrmActions::apiMethod($api, $methodApi, __METHOD__, $order, $site)) {
|
||||
return false;
|
||||
|
|
|
@ -208,22 +208,7 @@ class EventsHandlers
|
|||
$service = new UserAccountService();
|
||||
$createResponse = $service->createLoyaltyAccount($phone, $card, $customerId, $customFields);
|
||||
|
||||
//если участник ПЛ создан и активирован
|
||||
if (($createResponse !== null)
|
||||
&& $createResponse->success === true
|
||||
&& $createResponse->loyaltyAccount->active
|
||||
) {
|
||||
global $USER_FIELD_MANAGER;
|
||||
|
||||
$USER_FIELD_MANAGER->Update('USER', $arFields['USER_ID'], [
|
||||
'UF_EXT_REG_PL_INTARO' => 'Y',
|
||||
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($createResponse->errorMsg)) {
|
||||
AddMessage2Log($createResponse->errorMsg);
|
||||
}
|
||||
$service->activateLpUserInBitrix($createResponse, $arFields['USER_ID']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,4 +7,5 @@ $MESS["SEND"] = 'Отправить';
|
|||
$MESS["COMPLETE_YOUR_REGISTRATION"] = 'Для завершения регистрации в Программе лояльности необходимо заполнить форму.';
|
||||
$MESS["CREATE"] = 'Создать';
|
||||
$MESS["INVITATION_TO_REGISTER"] = 'Для регистрации в Программе лояльности заполните форму.';
|
||||
$MESS["REGISTER_ERROR"] = 'Ошибка регистрации в Программе лояльности';
|
||||
|
||||
|
|
|
@ -263,14 +263,41 @@ class LoyaltyService
|
|||
}
|
||||
} else {
|
||||
//НЕТ. Выясняем, каких полей не хватает для СОЗДАНИЯ аккаунта, выводим форму
|
||||
$regInLp['msg'] = GetMessage('COMPLETE_YOUR_REGISTRATION');
|
||||
$regInLp['form'] = [
|
||||
'button' => [
|
||||
'name' => GetMessage('CREATE'),
|
||||
'action' => 'createAccount',
|
||||
],
|
||||
'fields' => $this->getFields($userFields),
|
||||
];
|
||||
$fields = $this->getFields($userFields);
|
||||
|
||||
//Если все необходимые поля заполнены, то пытаемся его еще раз зарегистрировать
|
||||
if (empty($fields)) {
|
||||
$phone = $userFields['PERSONAL_PHONE'] ?? '';
|
||||
$card = $userFields['UF_CARD_NUM_INTARO'] ?? '';
|
||||
$customerId = (string) $userFields['ID'];
|
||||
$customFields = $userFields['UF_CSTM_FLDS_INTARO'] ?? [];
|
||||
$service = new UserAccountService();
|
||||
$createResponse = $service->createLoyaltyAccount($phone, $card, $customerId, $customFields);
|
||||
$service->activateLpUserInBitrix($createResponse, $userFields['ID']);
|
||||
|
||||
if ($createResponse !== null
|
||||
&& $createResponse->success === false
|
||||
&& isset($createResponse->errorMsg)
|
||||
&& !empty($createResponse->errorMsg)
|
||||
) {
|
||||
$errorDetails = $createResponse->errors['loyalty'] ?? '';
|
||||
|
||||
AddMessage2Log(GetMessage('REGISTER_ERROR') . ' ('.$createResponse->errorMsg.' '. $errorDetails .')');
|
||||
|
||||
$regInLp['msg'] = GetMessage('REGISTER_ERROR') . ' ('.$createResponse->errorMsg.' '. $errorDetails .')';
|
||||
}else{
|
||||
header("Refresh: 0");
|
||||
}
|
||||
}else{
|
||||
$regInLp['msg'] = GetMessage('COMPLETE_YOUR_REGISTRATION');
|
||||
$regInLp['form'] = [
|
||||
'button' => [
|
||||
'name' => GetMessage('CREATE'),
|
||||
'action' => 'createAccount',
|
||||
],
|
||||
'fields' => $this->getFields($userFields),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
|
@ -130,6 +130,30 @@ class UserAccountService
|
|||
//если в ответ получаем номер кода подтверждения, то отдаем два поля: скрытое с номером отправки и инпут для ввода кода проверки
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Api\Response\Loyalty\Account\LoyaltyAccountCreateResponse|null $createResponse
|
||||
* @param int $userId
|
||||
*/
|
||||
public function activateLpUserInBitrix(?LoyaltyAccountCreateResponse $createResponse, int $userId): void
|
||||
{
|
||||
//если участник ПЛ создан и активирован
|
||||
if (($createResponse !== null)
|
||||
&& $createResponse->success === true
|
||||
&& $createResponse->loyaltyAccount->active
|
||||
) {
|
||||
global $USER_FIELD_MANAGER;
|
||||
|
||||
$USER_FIELD_MANAGER->Update('USER', $userId, [
|
||||
'UF_EXT_REG_PL_INTARO' => 'Y',
|
||||
'UF_LP_ID_INTARO' => $createResponse->loyaltyAccount->id,
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($createResponse->errorMsg)) {
|
||||
AddMessage2Log($createResponse->errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue