Current Path : /var/www/www-root/data/webdav/www/www.monolith-realty.ru/roistat/ |
Current File : /var/www/www-root/data/webdav/www/www.monolith-realty.ru/roistat/roistat_events.php |
<?php /** * Created by PhpStorm. * User: borz * Date: 03.04.2020 * Time: 15:48 */ //use Bitrix\Main; use Bitrix\Sale\Internals\OrderPropsValueTable; require_once __DIR__ . '/NewRoistat.php'; const DEBUG = true; AddEventHandler("sale", "OnOrderAdd", "rsOnAddOrder"); AddEventHandler("form", "onBeforeResultAdd", "rsOnFormAdd"); AddEventHandler("iblock", "OnAfterIBlockElementAdd", 'rsOnIblockAdd'); //AddEventHandler('main','OnBeforeEventAdd','rsOnMainAdd'); /** * Функция Order * @param $ID * @param $arFields * @return bool|string|void|null */ function rsOnAddOrder($ID, $arFields) { if(DEBUG) { Roistat::writeToLog($arFields, 'rsOnAddOrder_$arFields'); Roistat::writeToLog($_REQUEST, 'rsOnAddOrder_$_REQUEST'); return null; } if(!$ID) return; $roistat = new Roistat(); $product = ''; if(isset($_REQUEST['BUY1CLICK'])) { $oneClick = $_REQUEST['BUY1CLICK']; $roistat ->setName($oneClick['FIO']) ->setPhone($oneClick['PHONE']) ->setEmail($oneClick['EMAIL']) ->setComment($oneClick['COMMENT']) ->setForm('Купить в 1 клик') ; } else { if($arFields['PERSON_TYPE_ID'] == 1) { $roistat ->setName("{$_REQUEST['ORDER_PROP_24']} {$_REQUEST['ORDER_PROP_1']}") ->setPhone($_REQUEST['ORDER_PROP_3']) ->setEmail($_REQUEST['ORDER_PROP_2']) ->setComment( "Комментарий к заказу: {$_REQUEST['ORDER_DESCRIPTION']}\r\n" . "Адрес доставки: {$_REQUEST['ORDER_PROP_7']}" ) ; } else { $roistat ->setName("{$_REQUEST['ORDER_PROP_12']} {$_REQUEST['ORDER_PROP_25']}") ->setPhone($_REQUEST['ORDER_PROP_14']) ->setEmail($_REQUEST['ORDER_PROP_13']) ->setComment( "Название компании: {$_REQUEST['ORDER_PROP_8']}\r\n" . "ИНН: {$_REQUEST['ORDER_PROP_10']}\r\n" . "Комментарий к заказу: {$_REQUEST['ORDER_DESCRIPTION']}\r\n" . "Юр.адрес: {$_REQUEST['ORDER_PROP_9']}\r\n" . "Адрес доставки: {$_REQUEST['ORDER_PROP_19']}" ) ; } $roistat->setForm('Корзина'); } foreach ($arFields['BASKET_ITEMS'] as $item) { $qty = (int) $item['QUANTITY']; $price = (double) $item['PRICE']; $product .= "{$item['NAME']}, кол-во: {$qty}шт., цена: {$price}руб.\r\n"; } $roistat->setComment( "\r\nЗаказ:\r\n{$product}\r\n". "Номер заказа на сайте: {$ID}" ); $roistat->setFields([ 'price' => $arFields['PRICE'], ]); $roistat->setIsSkipSending(1); return $roistat->execute(); } /** * Функция форм * @param $WEB_FORM_ID * @param $arFields * @param $arrVALUES * @return bool|string|void|null */ function rsOnFormAdd($WEB_FORM_ID, &$arFields, &$arrVALUES) { if(DEBUG) { Roistat::writeToLog($arFields, 'rsOnFormAdd_$arFields'); Roistat::writeToLog($_REQUEST, 'rsOnFormAdd_$_REQUEST'); return null; } if( !$WEB_FORM_ID ) return; $roistatData = []; $formname = null; switch ($WEB_FORM_ID) { default: Roistat::writeToLog($_REQUEST, 'rsOnFormAdd_$_REQUEST'); break; } } /** * Функция iBlock * @param $arFields * @return bool|string|null */ function rsOnIblockAdd(&$arFields) { if(DEBUG) { Roistat::writeToLog($arFields, 'rsOnIblockAdd_$arFields'); Roistat::writeToLog($_REQUEST, 'rsOnIblockAdd_$_REQUEST'); return null; } $data = $_REQUEST; $roistat = new Roistat(); switch ($arFields['IBLOCK_ID']) { case 11: $roistat ->setName($data['FIELD_642']) ->setPhone($data['FIELD_644']) ->setEmail($data['FIELD_643']) ->setComment($data['FIELD_645']) ->setForm('Связаться с нами') ; break; default: return Roistat::writeToLog($arFields, 'ID не найден'); } $roistat->setIsSkipSending(1); return $roistat->execute(); } /** * Функция Main * @param $arFields * @return bool|string|null */ function rsOnMainAdd($arFields) { if(DEBUG) { Roistat::writeToLog($arFields, 'rsOnMainAdd_$arFields'); Roistat::writeToLog($_REQUEST, 'rsOnMainAdd_$_REQUEST'); return null; } $roistatData = [ 'name' => !empty($_REQUEST['NAME']) ? $_REQUEST['NAME'] : null, 'phone' => !empty($_REQUEST['PHONE']) ? $_REQUEST['PHONE'] : null, 'email' => !empty($_REQUEST['EMAIL']) ? $_REQUEST['EMAIL'] : null ]; $formname = !empty($_REQUEST['formname']) ? $_REQUEST['formname'] : 'Неизвестная форма'; }