$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('sender', 'OnBeforePostingSendRecipient', ['SenderEvents', 'OnBeforePostingSendRecipient']);
class SenderEvents {
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters();
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
}
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('sender', 'OnBeforePostingSendRecipient', ['SenderEvents', 'OnBeforePostingSendRecipient']);
class SenderEvents {
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters();
file_put_contents($_SERVER["DOCUMENT_ROOT"].'/upload/log/sender.txt', json_encode($parameters)."\n", FILE_APPEND | LOCK_EX);
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
}
[{"FIELDS":{"EMAIL_TO":"test@site.ru","NAME":"test","USER_ID":"1","SENDER_CHAIN_ID":2,"SENDER_CHAIN_CODE":"sender_chain_item_2"},"TRACK_READ":{"MODULE_ID":"sender","FIELDS":{"RECIPIENT_ID":"68"},"URL_PAGE":"","URL_PARAMS":[]},"TRACK_CLICK":{"MODULE_ID":"sender","FIELDS":{"RECIPIENT_ID":"68"},"URL_PAGE":"","URL_PARAMS":{"bx_sender_conversion_id":"68"}},"MAILING_CHAIN_ID":"3","LINK_DOMAIN":"site.ru"}]
[{"FIELDS":{"EMAIL_TO":"test2@mail.ru","NAME":"test2","USER_ID":"726","SENDER_CHAIN_ID":2,"SENDER_CHAIN_CODE":"sender_chain_item_2"},"TRACK_READ":{"MODULE_ID":"sender","FIELDS":{"RECIPIENT_ID":"69"},"URL_PAGE":"","URL_PARAMS":{"bx_sender_conversion_id":"68"}},"TRACK_CLICK":{"MODULE_ID":"sender","FIELDS":{"RECIPIENT_ID":"69"},"URL_PAGE":"","URL_PARAMS":{"bx_sender_conversion_id":"69"}},"MAILING_CHAIN_ID":"3","LINK_DOMAIN":"site.ru"}]
[{"FIELDS":{"EMAIL_TO":"test@site.ru","NAME":"test","USER_ID":"1","SENDER_CHAIN_ID":2,"SENDER_CHAIN_CODE":"sender_chain_item_2"},"TRACK_READ":{"MODULE_ID":"sender","FIELDS":{"RECIPIENT_ID":"68"},"URL_PAGE":"","URL_PARAMS":[]},"TRACK_CLICK":{"MODULE_ID":"sender","FIELDS":{"RECIPIENT_ID":"68"},"URL_PAGE":"","URL_PARAMS":{"bx_sender_conversion_id":"68"}},"MAILING_CHAIN_ID":"3","LINK_DOMAIN":"site.ru"}]
$event = new Main\Event('sender', 'OnBeforePostingSendRecipient', [$eventSendParams]);
$event = new Main\Event('sender', 'OnBeforePostingSendRecipient', [0 => $eventSendParams]);
$parameters = $event->getParameters();
$data = $parameters[0]['FIELDS'];
class SenderEvents {
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
// если отправлять не надо
$parameters['FIELDS'] = [];
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
}
class SenderEvents {
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
$mailingChainId = $parameters['MAILING_CHAIN_ID'];
if($mailingChainId) {
$mailingTrigger = \Bitrix\Sender\MailingTriggerTable::getList([
'select' => ['ENDPOINT'],
'filter' => ['MAILING_CHAIN_ID' => $mailingChainId, 'IS_TYPE_START' => 1]
])->fetch();
if($mailingTrigger) {
if($mailingTrigger['ENDPOINT']['CODE'] == \Bitrix\Sale\Sender\TriggerBasketForgotten::getCode()) {
// здесь проверяешь юзера
$parameters['FIELDS'] = [];
}
}
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
}
class SenderEvents {
const USER_GROUP_DILLER_ID = 1;
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
$mailingChainId = $parameters['MAILING_CHAIN_ID'];
$isUserDiller = self::userInGroup($parameters['FIELDS']['USER_ID'], self::USER_GROUP_DILLER_ID);
if($mailingChainId && $isUserDiller) {
$mailingTrigger = new \MailingTrigger($mailingChainId);
if($mailingTrigger->isTriggerBasketForgotten()) {
$parameters['FIELDS'] = [];
}
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
private static function userInGroup(int $userId = 0, $userGroupsId = []) {
if($userId && $userGroupsId) {
$userGroupsId = (array) $userGroupsId;
$userGroups = CUser::GetUserGroup($userId);
return array_intersect($userGroups, $userGroupsId) ? true : false;
}
else {
return false;
}
}
}
class MailingTrigger {
private $trigger;
public function __construct(int $mailingChainId) {
$this->setTrigger($mailingChainId);
}
public function getTrigger(int $mailingChainId) {
return $this->trigger;
}
private function setTrigger(int $mailingChainId) {
if(!isset($this->trigger)) {
$this->trigger = \Bitrix\Sender\MailingTriggerTable::getList([
'select' => ['ENDPOINT'],
'filter' => ['MAILING_CHAIN_ID' => $mailingChainId, 'IS_TYPE_START' => 1]
])->fetch();
}
}
public function getCode() {
return $this->trigger['ENDPOINT']['CODE'];
}
public function isTriggerBasketForgotten() {
$triggerBasketForgottenCode = \Bitrix\Sale\Sender\TriggerBasketForgotten::getCode();
return $this->getCode() == $triggerBasketForgottenCode ? true : false;
}
}
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('sender', 'OnBeforePostingSendRecipient', ['SenderEvents', 'OnBeforePostingSendRecipient']);
class SenderEvents {
const USER_GROUP_DILLER_ID = 1;
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
$isUserDiller = self::userInGroup($parameters['FIELDS']['USER_ID'], self::USER_GROUP_DILLER_ID);
if($isUserDiller) {
$parameters['FIELDS']['EMAIL_TO'] = '';
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
private static function userInGroup(int $userId = 0, $userGroupsId = []) {
if($userId && $userGroupsId) {
$userGroupsId = (array) $userGroupsId;
$userGroups = CUser::GetUserGroup($userId);
return array_intersect($userGroups, $userGroupsId) ? true : false;
}
else {
return false;
}
}
}
class SenderEvents {
const USER_GROUP_DILLER_ID = 1;
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
$mailingChainId = $parameters['MAILING_CHAIN_ID'];
$isUserDiller = self::userInGroup($parameters['FIELDS']['USER_ID'], self::USER_GROUP_DILLER_ID);
if($mailingChainId && $isUserDiller) {
$mailingTrigger = new \MailingTrigger($mailingChainId);
if($mailingTrigger->isTriggerBasketForgotten()) {
$parameters['FIELDS']['EMAIL_TO'] = '';
}
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
private static function userInGroup(int $userId = 0, $userGroupsId = []) {
if($userId && $userGroupsId) {
$userGroupsId = (array) $userGroupsId;
$userGroups = CUser::GetUserGroup($userId);
return array_intersect($userGroups, $userGroupsId) ? true : false;
}
else {
return false;
}
}
}
class MailingTrigger {
private $trigger;
public function __construct(int $mailingChainId) {
$this->setTrigger($mailingChainId);
}
public function getTrigger(int $mailingChainId) {
return $this->trigger;
}
private function setTrigger(int $mailingChainId) {
if(!isset($this->trigger)) {
$this->trigger = \Bitrix\Sender\MailingTriggerTable::getList([
'select' => ['ENDPOINT'],
'filter' => ['MAILING_CHAIN_ID' => $mailingChainId, 'IS_TYPE_START' => 1]
])->fetch();
}
}
public function getCode() {
return $this->trigger['ENDPOINT']['CODE'];
}
public function isTriggerBasketForgotten() {
$triggerBasketForgottenCode = \Bitrix\Sale\Sender\TriggerBasketForgotten::getCode();
return $this->getCode() == $triggerBasketForgottenCode ? true : false;
}
}
$eventManager = \Bitrix\Main\EventManager::getInstance();
$eventManager->addEventHandler('sender', 'OnBeforePostingSendRecipient', ['SenderEvents', 'OnBeforePostingSendRecipient']);
class SenderEvents {
// Исключение из рассылки юзеров состоящих в группах
const USER_GROUP_EXCLUSE = [
"LOGIC"=>"OR",
//"ID"=>[1,2,5], // filter by Group {ID}
"DESCRIPTION"=>["DISCOUNT","SKIDKA","ADMIN"] // filter by Group {DESCRIPTION}
];
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
$isUserExcluse = self::userInGroup($parameters['FIELDS']['USER_ID'], self::USER_GROUP_EXCLUSE);
if($isUserExcluse) {
$parameters['FIELDS']["EMAIL_TO"] = "";
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
private static function userInGroup(int $userId = 0, $userGroupsFilter = []) {
$arGroupIds = [];
if($userId && $userGroupsFilter) {
$rsGroups = \Bitrix\Main\GroupTable::getList([
"select"=>["ID","NAME","ACTIVE","DESCRIPTION"],
"filter"=>[
"ACTIVE" => "Y",
$userGroupsFilter
]
]);
if($rsGroups->getSelectedRowsCount() > 0){
while($arGroups = $rsGroups->Fetch()){
$arGroupIds[$arGroups["ID"]] = $arGroups["NAME"];
}
}
$arGroupsCurrent = array_intersect(CUser::GetUserGroup($userId), array_keys($arGroupIds));
return sizeof($arGroupsCurrent) ? true : false;
}else {
return false;
}
}
}
To: #EMAIL_TO#
Subject: =?UTF-8?B?0KHQv9C10YbQuNCwRLvRjNC90YvQuDDQsdC+0L3Rg9GBINC00LvRjyDRgdCw0LzRi9GFIDCy0LTRg9C80YfQuNCy0YvRhSE=?=
X-PHP-Originating-Script: 0:tools.php
From: =?UTF-8?F?SJzQtdC90LXQtNC20LXGgA==?=
if($isUserDiller) {
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::ERROR, $parameters);
}
else {
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}