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;
}
}
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 {
public static function OnBeforePostingSendRecipient($event) {
$parameters = $event->getParameters()[0];
// если отправлять не надо
$parameters['FIELDS'] = [];
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS, $parameters);
}
}
$event = new Main\Event('sender', 'OnBeforePostingSendRecipient', [$eventSendParams]);
$event = new Main\Event('sender', 'OnBeforePostingSendRecipient', [0 => $eventSendParams]);
$parameters = $event->getParameters();
$data = $parameters[0]['FIELDS'];
[{"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"}]
первое письмо через 2 минуты
второй через 2 минуты
третье через 2 минуты
А если уберешь событие, то все норм будет работать?