Created
April 7, 2016 20:19
-
-
Save d1i1m1o1n/51cc011f7f3d2a892092ede29aca0e30 to your computer and use it in GitHub Desktop.
Подписка на рассылку при регистрации. Нужно создать пользовательское поле UF_SUBSCRIBE типа "Да/Нет". Компонент system.auth.registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Подписка на рассылку при регистрации | |
AddEventHandler("main", "OnAfterUserAdd", "OnAfterUserAddHandler"); | |
function OnAfterUserAddHandler(&$arFields) | |
{ | |
$errors = Array(); | |
if($arFields["ID"]>0 && $arFields["UF_SUBSCRIBE"]) | |
{ | |
if(CModule::IncludeModule("subscribe")) { | |
$USER_ID = $arFields["ID"]; | |
$EMAIL = $arFields["EMAIL"]; | |
$arFilter = array( | |
"ACTIVE" => "Y", | |
"LID" => "s1", | |
"VISIBLE"=>"Y", | |
); | |
$rsRubrics = CRubric::GetList(array(), $arFilter); | |
$arRubrics = array(); | |
while($arRubric = $rsRubrics->GetNext()) $arRubrics[] = $arRubric["ID"]; | |
$obSubscription = new CSubscription; | |
$rsSubscription = $obSubscription->GetList(array(), array("USER_ID" => $USER_ID)); | |
$arSubscription = $rsSubscription->Fetch(); | |
if(is_array($arSubscription)) | |
{ | |
$rs = $obSubscription->Update( | |
$arSubscription["ID"], | |
array( | |
"FORMAT" => "html", | |
"RUB_ID" => $arRubrics, | |
), | |
false | |
); | |
} | |
else | |
{ | |
$ID = $obSubscription->Add(array( | |
"USER_ID" => $USER_ID, | |
"ACTIVE" => "Y", | |
"EMAIL" => $EMAIL, | |
"FORMAT" => "html", | |
"CONFIRMED" => "Y", | |
"SEND_CONFIRM" => "N", | |
"RUB_ID" => $arRubrics, | |
)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment