M
M
Mechanic2015-12-30 21:50:07
1C-Bitrix
Mechanic, 2015-12-30 21:50:07

How to track user registration confirmation?

Hello, friends! Happy New Year to you!
I ask for your help. The situation is as follows: I have the simplest event handler: when a user registers, CIBlockElement::Add() is executed - it adds an element to the IB with a binding to the registered user and several more properties. I’ll make a reservation right away that this action needs to be done only once - during registration - this is a kind of "accrual bonus for registration."
This handler copes with its task, but on the condition that confirmation of registration from the user is not requested. If I turn on the registration confirmation, after the user submits the form, he sees a white sheet. This is because USER_ID is not assigned to him immediately, but only after clicking on the link from the letter.
Question:on which event should I hang this handler so that it is executed when the user confirms registration? From googling, I figured out that maybe CUser::Update() should be used. Is it so?
Existing handler code:

AddEventHandler("main", "OnAfterUserRegister", "AddBonusOnRegister");
function AddBonusOnRegister(&$arFields){
  include $_SERVER['DOCUMENT_ROOT'].'/cbk/vars.php';
  CModule::IncludeModule("iblock");
  if($arFields["USER_ID"] > 0){
    // Добавляем бонус как покупку
    $prop[164] = $arFields["USER_ID"]; 			// Привязка к пользователю
               /* ... Еще несколько свойств ... */

    $arLoadProductArray = Array( 
      "IBLOCK_SECTION_ID" => false, 
      "IBLOCK_ID" => $ORDERS_IBLOCK_ID, 
      "PROPERTY_VALUES"=> $prop, 
      "NAME" => "Бонус за регистрацию (".$arFields['LOGIN'].")", 
      "ACTIVE" => "Y"
    );
    
    $bonus = new CIBlockElement;
    if(!$bonus->Add($arLoadProductArray)){
      echo "Ошибка при начислении бонуса: ".$bonus->LAST_ERROR."<br/>";
    }
  }
}

Thank you for your attention! I would be glad for practical advice :)
PS I have earned something .. I wanted to write OnAfterUserUpdate, not CUser::Update()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mechanic, 2015-12-30
@bitrixweb

Problem solved. Since confirmation of user registration is just a change in the value of his activity, the handler hung up on OnBeforeUserUpdate with a check for $arUser["ACTIVE"] == 'N' && !isset($arUser["LAST_LOGIN"]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question