> For the complete documentation index, see [llms.txt](https://support.morozovpimnev.ru/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.morozovpimnev.ru/amocrm/sobytiya-khuki.md).

# События (хуки)

Для добавление в отправляемые данные своих данных можно использовать следующие хуки ([подробнее](https://www.hostcms.ru/documentation/modules/core/events/))

<pre class="language-php" data-line-numbers data-full-width="true"><code class="lang-php"><strong>// добавление данных в произвольные поля
</strong><strong>class My_AmoCRM
</strong>{
    static public function onBeforeLeadAdd($controller, $args)
    {
        $oEntity = $args[0]; // Shop_Order, Form_Fill или Siteuser
        $oAmoCRM = $args[1]; // сет настроек
        $id = $args[2]; // FALSE (add) или int (update)
        
        /** $args[3] - параметры,
         * добавление параметров в custom_fields_values
         */
        $args[3]['custom_fields_values'][] = array(
            'field_id' => 123456, // ID произвольного поля
            'values' => array(
                array(
                    'value' => '789', // значение
                    //'enum_code' => 'fax' // если есть
                )
            )
        );
    }
}

Core_Event::attach('AmoCRM_Controller.onBeforeShopLeadAdd', array('My_AmoCRM', 'onBeforeLeadAdd'));
Core_Event::attach('AmoCRM_Controller.onBeforeFormLeadAdd', array('My_AmoCRM', 'onBeforeLeadAdd'));
Core_Event::attach('AmoCRM_Controller.onBeforeSiteuserLeadAdd', array('My_AmoCRM', 'onBeforeLeadAdd'));
</code></pre>

## События отправки

{% code lineNumbers="true" fullWidth="true" %}

```php
/**
 * Создание заказа Shop_Payment_System_Handler::_processOrder()
 * @hostcms-event Shop_Payment_System_Handler.onAfterProcessOrder
 * Запустить самостоятельно в своей логике
 */
$oShop_Order = Core_Entity::factory('Shop_Order', 123);
$Shop_Payment_System_Handler = Shop_Payment_System_Handler::factory($oShop_Order->Shop_Payment_System);
$Shop_Payment_System_Handler->shopOrder($oShop_Order);
AmoCRM_Controller::onAfterProcessOrder($Shop_Payment_System_Handler);

/**
 * Создание формы Form_Controller_Show::process()
 * @hostcms-event Form_Controller_Show.onAfterProcess
 * Запустить самостоятельно в своей логике
 */
$oForm_Fill = Core_Entity::factory('Form_Fill', 123);
$oForm = $oForm_Fill->Form;
$Form_Controller_Show = new Form_Controller_Show($oForm);
AmoCRM_Controller::onAfterProcess($Form_Controller_Show, array($oForm_Fill));

/**
 * нет своего хука, перед отправкой письма пользователю о регистрации вставить след код, например в ТДС
 */
$oSiteuser = Core_Entity::factory('Siteuser', 123);
AmoCRM_Controller::siteuser($oSiteuser);
```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://support.morozovpimnev.ru/amocrm/sobytiya-khuki.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
