D
D
Darklt2021-04-12 16:58:30
1C-Bitrix
Darklt, 2021-04-12 16:58:30

How to automatically create a user profile from 1C?

I have buyers from 1C, but at the same time,
1. EXTERNAL_AUTH_ID is substituted for sale, because of this, the password does not allow me to enter
2. I write the following code in init.php to create a profile, it does not work:

AddEventHandler("main", "OnAfterUserRegister", Array("MyClass", "OnBeforeUserRegisterHandler")); 
class MyClass
{
    function OnBeforeUserRegisterHandler(&$arFields)
    {
      //создаём профиль
      //PERSON_TYPE_ID - идентификатор типа плательщика, для которого создаётся профиль
      $arProfileFields = array(
         "NAME" => "Профиль покупателя (".$arFields['LOGIN'].')',
         "USER_ID" => $arFields['USER_ID'],
         "PERSON_TYPE_ID" => 3
      );
      $PROFILE_ID = CSaleOrderUserProps::Add($arProfileFields);
      
      //если профиль создан
      if ($PROFILE_ID)
      {
         //формируем массив свойств
         $PROPS=Array(
         array(
               "USER_PROPS_ID" => $PROFILE_ID,
               "ORDER_PROPS_ID" => 3,
               "NAME" => "Телефон",
               "VALUE" => $arFields['WORK_PHONE']
            ),
         array(
               "USER_PROPS_ID" => $PROFILE_ID,
               "ORDER_PROPS_ID" => 1,
               "NAME" => "Ф.И.О.",
               "VALUE" => $arFields['LAST_NAME'].' '.$arFields['NAME'].' '.$arFields['SECOND_NAME']
            )
         );
         //добавляем значения свойств к созданному ранее профилю
         foreach ($PROPS as $prop)
            CSaleOrderUserPropsValue::Add($prop);
      }
    }}


UPDATE:

The reason is that if you create it manually, then everything is created automatically, but if you import a user, then there is no :( or if you create it from the admin

panel Tried using the OnAfterUserAdd and OnBeforeUserAdd functions, nothing happened

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question