2022-03-02 15:40:53 +03:00
|
|
|
<?php
|
|
|
|
|
2024-08-08 09:47:15 +03:00
|
|
|
namespace Intaro\RetailCrm\Component\Advanced;
|
2022-03-02 15:40:53 +03:00
|
|
|
|
|
|
|
use Bitrix\Main\ArgumentException;
|
|
|
|
use Bitrix\Main\EventManager;
|
|
|
|
use Bitrix\Main\ObjectPropertyException;
|
|
|
|
use Bitrix\Main\SystemException;
|
|
|
|
use Bitrix\Main\Type\DateTime;
|
|
|
|
use CUserTypeEntity;
|
|
|
|
use Intaro\RetailCrm\Component\Constants;
|
|
|
|
use Intaro\RetailCrm\Component\Handlers\EventsHandlers;
|
|
|
|
use Intaro\RetailCrm\Model\Bitrix\Agreement;
|
|
|
|
use Intaro\RetailCrm\Repository\AgreementRepository;
|
|
|
|
use Intaro\RetailCrm\Repository\ToModuleRepository;
|
|
|
|
use RCrmActions;
|
|
|
|
|
|
|
|
IncludeModuleLangFile(__FILE__);
|
|
|
|
|
2024-08-08 09:47:15 +03:00
|
|
|
class LoyaltyInstaller
|
2022-03-02 15:40:53 +03:00
|
|
|
{
|
|
|
|
/**
|
2023-08-22 13:09:20 +03:00
|
|
|
* Создание событий для программы лояльности
|
2022-03-02 15:40:53 +03:00
|
|
|
*/
|
2023-08-22 13:09:20 +03:00
|
|
|
public function addEvents(): void
|
2022-03-02 15:40:53 +03:00
|
|
|
{
|
|
|
|
$eventManager = EventManager::getInstance();
|
|
|
|
|
|
|
|
foreach (Constants::LP_EVENTS as $event) {
|
|
|
|
try {
|
|
|
|
$events = ToModuleRepository::getCollectionByWhere(
|
|
|
|
['ID'],
|
|
|
|
[
|
|
|
|
['from_module_id', '=', $event['FROM_MODULE']],
|
|
|
|
['to_module_id', '=', Constants::MODULE_ID],
|
|
|
|
['to_method', '=', $event['EVENT_NAME'] . 'Handler'],
|
|
|
|
['to_class', '=', EventsHandlers::class],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($events !== null && count($events) === 0) {
|
|
|
|
$eventManager->registerEventHandler(
|
|
|
|
$event['FROM_MODULE'],
|
|
|
|
$event['EVENT_NAME'],
|
|
|
|
Constants::MODULE_ID,
|
|
|
|
EventsHandlers::class,
|
|
|
|
$event['EVENT_NAME'] . 'Handler'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
} catch (ObjectPropertyException | ArgumentException | SystemException $exception) {
|
|
|
|
RCrmActions::eventLog(
|
|
|
|
'intaro.retailcrm/install/index.php',
|
|
|
|
'RetailCrm\ApiClient::addLPEvents',
|
|
|
|
$exception->getMessage()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-08-22 13:09:20 +03:00
|
|
|
* Перемещение модульных шаблонов в CMS
|
2022-03-02 15:40:53 +03:00
|
|
|
*/
|
|
|
|
public function CopyFiles(): void
|
|
|
|
{
|
|
|
|
$pathFrom = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . Constants::MODULE_ID . '/install';
|
|
|
|
|
|
|
|
CopyDirFiles(
|
|
|
|
$pathFrom . '/export',
|
|
|
|
$_SERVER['DOCUMENT_ROOT'],
|
2024-08-08 09:47:15 +03:00
|
|
|
false,
|
2022-03-02 15:40:53 +03:00
|
|
|
true,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
|
2023-08-22 13:09:20 +03:00
|
|
|
$templateNames = [
|
|
|
|
'default_loyalty' => [
|
|
|
|
0 => [
|
|
|
|
'name' => 'sale.order.ajax',
|
|
|
|
'templateDirectory' => '.default'
|
|
|
|
],
|
|
|
|
1 => [
|
|
|
|
'name' => 'sale.basket.basket',
|
|
|
|
'templateDirectory' => '.default'
|
|
|
|
],
|
|
|
|
2 => [
|
|
|
|
'name' => 'main.register',
|
|
|
|
'templateDirectory' => '.default'
|
|
|
|
],
|
|
|
|
]
|
2022-03-02 15:40:53 +03:00
|
|
|
];
|
|
|
|
|
2023-08-22 13:09:20 +03:00
|
|
|
foreach ($templateNames as $directory => $templates) {
|
|
|
|
foreach ($templates as $template) {
|
|
|
|
$this->copy($directory, $template);
|
2022-03-02 15:40:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-08-08 09:47:15 +03:00
|
|
|
* Добавление полей пользователя для ПЛ
|
2022-03-02 15:40:53 +03:00
|
|
|
*/
|
2023-08-22 13:09:20 +03:00
|
|
|
public function addUserFields(): void
|
2022-03-02 15:40:53 +03:00
|
|
|
{
|
|
|
|
$this->addCustomUserFields(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'name' => 'UF_CARD_NUM_INTARO',
|
|
|
|
'title' => GetMessage('UF_CARD_NUMBER_INTARO_TITLE'),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'string'
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addCustomUserFields(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'name' => 'UF_LP_ID_INTARO',
|
|
|
|
'title' => GetMessage('UF_LP_ID_INTARO_TITLE'),
|
|
|
|
],
|
|
|
|
],
|
|
|
|
'string',
|
|
|
|
['EDIT_IN_LIST' => 'N']
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->addCustomUserFields(
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'name' => 'UF_REG_IN_PL_INTARO',
|
|
|
|
'title' => GetMessage('UF_REG_IN_PL_INTARO_TITLE'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'UF_AGREE_PL_INTARO',
|
|
|
|
'title' => GetMessage('UF_AGREE_PL_INTARO_TITLE'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'UF_PD_PROC_PL_INTARO',
|
|
|
|
'title' => GetMessage('UF_PD_PROC_PL_INTARO_TITLE'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'name' => 'UF_EXT_REG_PL_INTARO',
|
|
|
|
'title' => GetMessage('UF_EXT_REG_PL_INTARO_TITLE'),
|
2023-08-22 13:09:20 +03:00
|
|
|
]
|
2022-03-02 15:40:53 +03:00
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $fields
|
|
|
|
* @param string $filedType
|
|
|
|
* @param array $customProps
|
|
|
|
*/
|
|
|
|
public function addCustomUserFields($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();
|
2024-08-08 09:47:15 +03:00
|
|
|
$dbRes = CUserTypeEntity::GetList([], ['FIELD_NAME' => $filed['name']])->fetch();
|
2022-03-02 15:40:53 +03:00
|
|
|
|
|
|
|
if (!$dbRes['ID']) {
|
|
|
|
$obUserField->Add($props);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Добавление соглашений для формы регистрации
|
|
|
|
*
|
|
|
|
* @throws \Bitrix\Main\ArgumentException
|
|
|
|
* @throws \Bitrix\Main\ObjectPropertyException
|
|
|
|
* @throws \Bitrix\Main\SystemException
|
|
|
|
*/
|
|
|
|
public function addAgreement(): void
|
|
|
|
{
|
|
|
|
$isAgreementLoyaltyProgram = AgreementRepository::getFirstByWhere(
|
|
|
|
['ID'],
|
|
|
|
[
|
|
|
|
['CODE', '=', Constants::AGREEMENT_LOYALTY_PROGRAM_CODE]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!isset($isAgreementLoyaltyProgram['ID'])) {
|
|
|
|
$agreementLoyaltyProgram = new Agreement();
|
|
|
|
$agreementLoyaltyProgram->setCode(Constants::AGREEMENT_LOYALTY_PROGRAM_CODE);
|
|
|
|
$agreementLoyaltyProgram->setDateInsert(new DateTime());
|
|
|
|
$agreementLoyaltyProgram->setActive('Y');
|
|
|
|
$agreementLoyaltyProgram->setName(GetMessage('AGREEMENT_LOYALTY_PROGRAM_TITLE'));
|
|
|
|
$agreementLoyaltyProgram->setType('C');
|
|
|
|
$agreementLoyaltyProgram->setAgreementText(GetMessage('AGREEMENT_LOYALTY_PROGRAM_TEXT'));
|
|
|
|
$agreementLoyaltyProgram->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
$isAgreementPersonalProgram = AgreementRepository::getFirstByWhere(
|
|
|
|
['ID'],
|
|
|
|
[
|
|
|
|
['CODE', '=', Constants::AGREEMENT_PERSONAL_DATA_CODE]
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!isset($isAgreementPersonalProgram['ID'])) {
|
|
|
|
$agreementPersonalData = new Agreement();
|
|
|
|
$agreementPersonalData->setCode(Constants::AGREEMENT_PERSONAL_DATA_CODE);
|
|
|
|
$agreementPersonalData->setDateInsert(new DateTime());
|
|
|
|
$agreementPersonalData->setActive('Y');
|
|
|
|
$agreementPersonalData->setName(GetMessage('AGREEMENT_PERSONAL_DATA_TITLE'));
|
|
|
|
$agreementPersonalData->setType('C');
|
|
|
|
$agreementPersonalData->setAgreementText(GetMessage('AGREEMENT_PERSONAL_DATA_TEXT'));
|
|
|
|
$agreementPersonalData->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* delete loyalty program events handlers
|
|
|
|
*/
|
2024-08-08 09:47:15 +03:00
|
|
|
public function deleteLPEvents(): void
|
2022-03-02 15:40:53 +03:00
|
|
|
{
|
|
|
|
$eventManager = EventManager::getInstance();
|
|
|
|
|
|
|
|
foreach (Constants::LP_EVENTS as $event){
|
|
|
|
$eventManager->unRegisterEventHandler(
|
|
|
|
$event['FROM_MODULE'],
|
|
|
|
$event['EVENT_NAME'],
|
|
|
|
$this->MODULE_ID,
|
|
|
|
EventsHandlers::class,
|
|
|
|
$event['EVENT_NAME'].'Handler'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2023-08-22 13:09:20 +03:00
|
|
|
|
|
|
|
private function copy($directory, $template): void
|
|
|
|
{
|
|
|
|
$templatePath = $_SERVER['DOCUMENT_ROOT']
|
|
|
|
. '/local/templates/.default/components/bitrix/' . $template['name'] . '/'. $directory
|
|
|
|
;
|
|
|
|
|
|
|
|
if (!file_exists($templatePath)) {
|
|
|
|
$pathFrom = $_SERVER['DOCUMENT_ROOT']
|
|
|
|
. '/bitrix/modules/intaro.retailcrm/install/export/local/components/intaro/'
|
|
|
|
. $template['name']
|
|
|
|
. '/templates/' . $template['templateDirectory']
|
|
|
|
;
|
|
|
|
|
|
|
|
CopyDirFiles(
|
|
|
|
$pathFrom,
|
|
|
|
$templatePath,
|
2024-08-08 09:47:15 +03:00
|
|
|
false,
|
2023-08-22 13:09:20 +03:00
|
|
|
true,
|
|
|
|
false
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2024-01-18 11:48:35 +03:00
|
|
|
}
|