The last notes
All English-language materials have been translated fully automatically using the Google service
Interception of adding an infoblock element
// We intercept the creation of infoblock elements after filling out the forms to add them to Bitrix24
AddEventHandler ("iblock", "OnAfterIBlockElementAdd", Array ("OnAfterIBlockElementAddClass", "OnAfterIBlockElementAddHandler"));
class OnAfterIBlockElementAddClass
{
function OnAfterIBlockElementAddHandler (& $ arFields)
{
if (($ arFields ["IBLOCK_ID"] == 15) {// We work with an infoblock with id = 15
// Your code is here
}
}
}
The $ arFields
array contains something like the following:
array (
'IBLOCK_ID' => 13,
'ACTIVE' => 'Y',
'NAME' => 'Name of information block element',
'PROPERTY_VALUES' =>
array (
'bxajaxid' => '2b203f84d8a89c2',
'AJAX_CALL' => 'Y',
'sessid' => '8fa4b79357bcd2a',
'PHONE' => '899300000000',
'EMAIL' => '123@123.com',
'FIO' => 'Pround',
'COMMENT' =>
array (
'VALUE' =>
array (
'TEXT' => 'User comment',
'TYPE' => 'html',
),
),
'form_submit' => 'Add',
'PHPSESSID' => '2fd5f8352a64d5',
'BITRIX_SM_SOUND_LOGIN_PLAYED' => 'Y',
'BITRIX_SM_UIDL' => 'admin',
'BITRIX_SM_LOGIN' => 'admin',
'BITRIX_SM_DSC' => '44',
),
'SEARCHABLE_CONTENT' => 'Name of information block element',
'CREATED_BY' => 1,
'MODIFIED_BY' => 1,
'~ DATE_CREATE' => 'now ()',
'~ TIMESTAMP_X' => 'now ()',
'XML_ID' => 3487,
'ID' => 3487,
'RESULT' => 3487,
)
Intercept emails
Intercepting a message just before sending
AddEventHandler ('main', 'OnBeforeEventSend', Array ("OnBeforeEventSendClass", "my_OnBeforeEventSend"));
class OnBeforeEventSendClass
{
function my_OnBeforeEventSend ($ arFields, $ arTemplate)
{
// get the message
}
}
// Intercept the generation of a mail event with the ability to cancel it
AddEventHandler ("main", "OnBeforeEventAdd", array ("OnBeforeEventAddClass", "OnBeforeEventAddHandler"));
class OnBeforeEventAddClass {
function OnBeforeEventAddHandler (& $ event, & $ lid, & $ arFields, & $ message_id, & $ files) {
}
}
Exchange with 1C
Handler for resetting the stock of goods
AddEventHandler ("catalog", "OnSuccessCatalogImport1C", "DSOnSuccessCatalogImport1C");
function DSOnSuccessCatalogImport1C ()
{
if (CModule :: IncludeModule ("catalog"))
{
$ db_res = CCatalogProduct :: GetList (array ("QUANTITY" => "DESC"), array ("> QUANTITY_RESERVED" => 0), false, false);
while ($ ar_res = $ db_res-> Fetch ())
{
if (! CCatalogProduct :: Update ($ ar_res ["ID"], array ("QUANTITY_RESERVED" => 0))) {
AddMessage2Log ("Update failed". $ Ar_res ["ID"]);
} // endif
} // endwhile
}
}
Events:
OnCompleteCatalogImport1C // handler triggered after loading all products and information on them
Comments