Working with Bitrix events
Rus
Eng
Работа с событиями Битрикс
Order site
By contacting me you will receive a reliable and knowledgeable contractor who will quickly and efficiently implement any task for you and your business.

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

There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment

Send

FEEDBACK

Email me

Please message me to discuss the task. I work remotely and officially (as a self-employed professional); my hourly rate is 1,800 RUB, and I can dedicate 3–4 hours a day to the project. I respond quickly, and the consultation is free.

An error occurred while sending, please try again after a while
Message sent successfully

Phones

+7(993) 007-18-96

Email

info@tichiy.ru

Address

Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site