1
0
mirror of synced 2024-11-21 21:06:09 +03:00

ref #86982 предотвращение создания дублей пользователей по истории (#282)

This commit is contained in:
Kocmonavtik 2023-03-31 11:44:26 +03:00 committed by GitHub
parent b8aab91880
commit 9c5ce1e53b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 187 additions and 24 deletions

View File

@ -1,3 +1,6 @@
## 2023-03-30 v.6.2.4
- Добавлен функционал слияния дублей пользователей по истории
## 2023-03-29 v.6.2.3
- Исправление ошибок при установке модуля и выгрузке истории заказов для работы с несколькими сайтами

View File

@ -126,7 +126,8 @@ class RetailCrmHistory
$registerNewUser = true;
if (!empty($customer['email'])) {
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $customer['email']));
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'DESC'), ['=EMAIL' => $customer['email']]);
switch ($dbUser->SelectedRowsCount()) {
case 0:
$login = $customer['email'];
@ -138,8 +139,9 @@ class RetailCrmHistory
$registerNewUser = false;
break;
default:
$login = uniqid('user_' . time()) . '@example.com';
$customerBuilder->setLogin($login);
$lastBitrixUser = $dbUser->Fetch();
$registeredUserID = $lastBitrixUser['ID'];
$registerNewUser = false;
break;
}
}
@ -159,15 +161,18 @@ class RetailCrmHistory
continue;
}
}
if(RCrmActions::apiMethod(
$api,
'customersFixExternalIds',
__METHOD__,
array(array('id' => $customer['id'], 'externalId' => $registeredUserID))) == false
) {
continue;
if (
RCrmActions::apiMethod
(
$api,
'customersFixExternalIds',
__METHOD__,
[['id' => $customer['id'], 'externalId' => $registeredUserID]]
) == false
) {
continue;
}
}
$customer['externalId'] = $registeredUserID;
@ -414,8 +419,8 @@ class RetailCrmHistory
$dbUser = CUser::GetList(
($by = 'ID'),
($sort = 'ASC'),
array('=EMAIL' => $order['customer']['email'])
($sort = 'DESC'),
['=EMAIL' => $order['customer']['email']]
);
switch ($dbUser->SelectedRowsCount()) {
@ -429,8 +434,9 @@ class RetailCrmHistory
$registerNewUser = false;
break;
default:
$login = uniqid('user_' . time()) . '@example.com';
$corporateCustomerBuilder->setLogin($login);
$lastBitrixUser = $dbUser->Fetch();
$registeredUserID = $lastBitrixUser['ID'];
$registerNewUser = false;
break;
}
@ -883,8 +889,8 @@ class RetailCrmHistory
$registerNewUser = true;
$dbUser = CUser::GetList(
($by = 'ID'),
($sort = 'ASC'),
array('=EMAIL' => $response['customer']['email'])
($sort = 'DESC'),
['=EMAIL' => $response['customer']['email']]
);
switch ($dbUser->SelectedRowsCount()) {
@ -899,9 +905,9 @@ class RetailCrmHistory
$registerNewUser = false;
break;
default:
$login = uniqid('user_' . time()) . '@example.com';
$customerBuilder->setLogin($login);
$customerBuilder->buildPassword();
$lastBitrixUser = $dbUser->Fetch();
$registeredUserID = $lastBitrixUser['ID'];
$registerNewUser = false;
break;
}

View File

@ -1 +1 @@
- Исправление ошибок при установке модуля и выгрузке истории заказов для работы с несколькими сайтами
- Добавлен функционал слияния дублей пользователей по истории

View File

@ -1,6 +1,6 @@
<?php
$arModuleVersion = [
'VERSION' => '6.2.3',
'VERSION_DATE' => '2023-03-29 18:00:00'
'VERSION' => '6.2.4',
'VERSION_DATE' => '2023-03-30 18:00:00'
];

View File

@ -44,3 +44,4 @@ $DB->Query($strSql);
require_once __DIR__ . '/BitrixTestCase.php';
require_once __DIR__ . '/helpers/Helpers.php';
require_once __DIR__ . '/datasets/DataHistory.php';

View File

@ -2,6 +2,8 @@
use Bitrix\Sale\Order;
use Bitrix\Currency\CurrencyManager;
use Tests\Intaro\RetailCrm\DataHistory;
/**
* Class RetailCrmHistory_v5Test
*/
@ -18,6 +20,82 @@ class RetailCrmHistory_v5Test extends \BitrixTestCase
CModule::IncludeModule('intaro.retailcrm');
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testRegisterUser(): void
{
$actionsMock = Mockery::mock('alias:' . RCrmActions::class);
$actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn(DataHistory::get_history_data_new_customer());
$this->deleteTestingUser();
RetailCrmHistory::customerHistory();
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'DESC'), array('=EMAIL' => 'testbitrixreg@gmail.com'));
$this->assertEquals(1, $dbUser->SelectedRowsCount());
}
/**
* @runInSeparateProcess
* @preserveGlobalState disabled
*/
public function testUnregisterDoubleUser(): void
{
$this->deleteTestingUser();
$user = new CUser;
$arFields = [
'NAME' => 'test',
'LAST_NAME' => 'test',
'LOGIN' => 'test',
'EMAIL' => 'testbitrixreg@gmail.com',
'LID' => 'ru',
'ACTIVE' => 'Y',
'GROUP_ID' => [10, 11],
'PASSWORD' => '123456',
'CONFIRM_PASSWORD' => '123456',
];
$ID = $user->Add($arFields);
$this->assertTrue((int) $ID > 0);
$actionsMock = Mockery::mock('alias:' . RCrmActions::class);
$actionsMock->shouldReceive('apiMethod')->withAnyArgs()->andReturn(DataHistory::get_history_data_new_customer());
RetailCrmHistory::customerHistory();
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'DESC'), array('=EMAIL' => 'testbitrixreg@gmail.com'));
$this->assertEquals(1, $dbUser->SelectedRowsCount());
$user = new CUser;
$arFields = [
'NAME' => 'test2',
'LAST_NAME' => 'test2',
'LOGIN' => 'test2',
'EMAIL' => 'testbitrixreg@gmail.com',
'LID' => 'ru',
'ACTIVE' => 'Y',
'GROUP_ID' => [10, 11],
'PASSWORD' => '123456',
'CONFIRM_PASSWORD' => '123456',
];
$ID = $user->Add($arFields);
$this->assertTrue((int) $ID > 0);
RetailCrmHistory::customerHistory();
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'DESC'), array('=EMAIL' => 'testbitrixreg@gmail.com'));
$this->assertEquals(2, $dbUser->SelectedRowsCount());
}
public function testSetPasswordUser(): void
{
$customers = $this->getCustomers();
@ -101,6 +179,17 @@ class RetailCrmHistory_v5Test extends \BitrixTestCase
$this->assertEquals(1515, $cmsOrder->getField('RESPONSIBLE_ID'));
}
private function deleteTestingUser(): void
{
$dbUser = CUser::GetList(($by = 'ID'), ($sort = 'DESC'), array('=EMAIL' => 'testbitrixreg@gmail.com'));
if ($dbUser->SelectedRowsCount() > 0) {
while ($user = $dbUser->Fetch()) {
CUser::Delete((int) $user['ID']);
}
}
}
private function getCustomers(): array
{
return [
@ -126,4 +215,4 @@ class RetailCrmHistory_v5Test extends \BitrixTestCase
],
];
}
}
}

View File

@ -0,0 +1,64 @@
<?php
namespace Tests\Intaro\RetailCrm;
/**
* Class DataHistory
*/
class DataHistory
{
public static function get_history_data_new_customer()
{
return [
'success' => true,
'history' => [
[
'id' => 18009,
'createdAt' => '2021-12-03 13:22:45',
'created' => true,
'source' => 'user',
'user' => ['id' => 11],
'field' => 'id',
'oldValue' => null,
'newValue' => 3758,
'customer' => [
'type' => 'customer',
'id' => 3758,
'isContact' => false,
'createdAt' => '2021-12-03 13:22:45',
'vip' => false,
'bad' => false,
'site' => 'bitrix',
'marginSumm' => 0,
'totalSumm' => 0,
'averageSumm' => 0,
'ordersCount' => 0,
'personalDiscount' => 0,
'cumulativeDiscount' => 0,
'address' => [
'id' => 3503,
'index' => 123456,
'countryIso' => 'ES',
'region' => 'Region',
'city' => 'City',
'text' => 'Street',
],
'customFields' => ['crm_customer' => 'test_customer'],
'segments' => [],
'firstName' => 'Test_Name',
'lastName' => 'Test_LastName',
'email' => 'testbitrixreg@gmail.com',
'phones' => ['0' => ['number' => '+79184563200']],
'birthday' => '2021-10-01'
]
]
],
'pagination' => [
'limit' => 100,
'totalCount' => 1,
'currentPage' => 1,
'totalPageCount' => 1
]
];
}
}