ref #91040 Добавлены методы создания событий и кастомного поля подписки.
Удален дублирующий код Добавлена получение кастомного поля подписки при сохранении профиля пользователя
This commit is contained in:
parent
cae1f14bab
commit
08a068e7bd
5 changed files with 61 additions and 5 deletions
|
@ -84,10 +84,6 @@
|
|||
"type": "bool",
|
||||
"default": false
|
||||
},
|
||||
"subscribed": {
|
||||
"type": "bool",
|
||||
"default": false
|
||||
},
|
||||
"commentary": {
|
||||
"type": "string"
|
||||
},
|
||||
|
|
|
@ -126,6 +126,7 @@ class RetailCrmUser
|
|||
$customer['address']['city'] = $arFields['PERSONAL_CITY'] ?? null;
|
||||
$customer['address']['text'] = $arFields['PERSONAL_STREET'] ?? null;
|
||||
$customer['address']['index'] = $arFields['PERSONAL_ZIP'] ?? null;
|
||||
$customer['subscribed'] = $arFields['UF_SUBSCRIBE_USER_EMAIL'] ?? false;
|
||||
|
||||
if (mb_strlen($arFields['EMAIL']) < 100) {
|
||||
$customer['email'] = $arFields['EMAIL'];
|
||||
|
|
|
@ -256,6 +256,8 @@ class intaro_retailcrm extends CModule
|
|||
$this->addAgreement();
|
||||
|
||||
$this->CopyFilesSubscribe();
|
||||
$this->addSubscribeUserFields();
|
||||
$this->addSubscriberEvents();
|
||||
|
||||
OrderLoyaltyDataService::createLoyaltyHlBlock();
|
||||
|
||||
|
@ -1293,6 +1295,7 @@ class intaro_retailcrm extends CModule
|
|||
|
||||
$this->deleteFiles();
|
||||
$this->deleteLPEvents();
|
||||
$this->deleteSubscribeEvents();
|
||||
|
||||
UnRegisterModule($this->MODULE_ID);
|
||||
|
||||
|
|
|
@ -54,4 +54,5 @@ $MESS ['UF_CARD_NUMBER_INTARO_TITLE'] = 'Номер карты программ
|
|||
$MESS ['UF_LP_ID_INTARO_TITLE'] = 'Номер аккаунта в программе лояльности';
|
||||
$MESS['IBLOCK_NOT_SELECTED'] = 'Не выбрано ни одного инфоблока для экспорта';
|
||||
$MESS['TARGET_DIR_DOESNT_EXIST'] = 'Целевая директория не существует';
|
||||
$MESS['UF_SUBSCRIBE_USER_EMAIL_TITLE'] = 'Подписка на события';
|
||||
|
||||
|
|
|
@ -10,12 +10,13 @@ use Bitrix\Main\SystemException;
|
|||
use Bitrix\Main\ObjectPropertyException;
|
||||
use Bitrix\Main\ArgumentException;
|
||||
use RCrmActions;
|
||||
use CUserTypeEntity;
|
||||
|
||||
IncludeModuleLangFile(__FILE__);
|
||||
|
||||
trait SubscriberInstallerTrait
|
||||
{
|
||||
public function addSubscribeEvents(): void
|
||||
public function addSubscriberEvents(): void
|
||||
{
|
||||
$eventManager = EventManager::getInstance();
|
||||
|
||||
|
@ -85,4 +86,58 @@ trait SubscriberInstallerTrait
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function addSubscribeUserFields(): void
|
||||
{
|
||||
$this->addCustomSubscribeUserFields(
|
||||
[
|
||||
[
|
||||
'name' => 'UF_SUBSCRIBE_USER_EMAIL',
|
||||
'title' => GetMessage('UF_SUBSCRIBE_USER_EMAIL_TITLE')
|
||||
]
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fields
|
||||
* @param string $filedType
|
||||
* @param array $customProps
|
||||
*/
|
||||
public function addCustomSubscribeUserFields($fields, string $filedType = 'boolean', array $customProps = []): void
|
||||
{
|
||||
foreach ($fields as $filed) {
|
||||
$arProps = [
|
||||
'ENTITY_ID' => 'USER',
|
||||
'FIELD_NAME' => $filed['name'],
|
||||
'USER_TYPE_ID' => $filedType,
|
||||
'MULTIPLE' => 'N',
|
||||
'MANDATORY' => 'N',
|
||||
'EDIT_FORM_LABEL' => ['ru' => $filed['title']],
|
||||
|
||||
];
|
||||
$props = array_merge($arProps, $customProps);
|
||||
$obUserField = new CUserTypeEntity();
|
||||
$dbRes = CUserTypeEntity::GetList([], ['FIELD_NAME' => $filed['name']])->fetch();
|
||||
|
||||
if (!$dbRes['ID']) {
|
||||
$obUserField->Add($props);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function deleteSubscribeEvents(): void
|
||||
{
|
||||
$eventManager = EventManager::getInstance();
|
||||
|
||||
foreach (Constants::SUBSCRIBE_EVENTS as $event){
|
||||
$eventManager->unRegisterEventHandler(
|
||||
$event['FROM_MODULE'],
|
||||
$event['EVENT_NAME'],
|
||||
$this->MODULE_ID,
|
||||
EventsHandlers::class,
|
||||
$event['EVENT_NAME'].'Handler'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue