• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/fuser.php
  • Класс: BitrixSaleFuser
  • Вызов: Fuser::handlerOnUserLogin
static function handlerOnUserLogin($userId, array $params): void
{
	$userId = (int)$userId;
	if ($userId <= 0)
	{
		return;
	}
	$options = [
		'update' => ($params['update'] ?? true) === true,
		'save' => ($params['save'] ?? false) === true,
	];

	$id = static::getIdFromSession();
	if ($id === null)
	{
		$filter = static::getFilterFromCookie(static::getIdFromCookie());
		if ($filter !== null)
		{
			$id = static::getIdByFilter($filter);
		}
	}

	$filter = [
		'=USER_ID' => $userId
	];
	if ($id !== null)
	{
		$filter['!=ID'] = $id;
	}
	$row = InternalsFuserTable::getRow([
		'select' => [
			'ID',
		],
		'filter' => $filter,
		'order' => [
			'ID' => 'DESC',
		],
	]);
	if ($row !== null)
	{
		$newId = (int)$row['ID'];
		if ($id !== null)
		{
			if (CSaleBasket::TransferBasket($id, $newId))
			{
				CSaleUser::Delete($id);
			}
		}
		$id = $newId;
	}

	if ($id !== null)
	{
		static::update($id, $options);
	}
	elseif ($options['update'])
	{
		unset($options['update']);
		static::add($options);
	}
}