From cae1f14bab4c4d966aafcee43f62cda0f2b41aa1 Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Wed, 12 Jul 2023 17:32:47 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#91040=20=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=B2=D1=91=D1=80=D1=81=D1=82=D0=BA?= =?UTF-8?q?=D0=B0,=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=20=D1=80=D0=B5=D0=B3=D0=B8=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20=D1=81=D0=BE=D0=B1=D1=8B?= =?UTF-8?q?=D1=82=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bitrix/main.profile/.default/template.php | 6 +-- intaro.retailcrm/lib/component/constants.php | 4 ++ .../installer/subscriberinstallertrait.php | 44 ++++++++++++++++++- 3 files changed, 50 insertions(+), 4 deletions(-) diff --git a/intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/template.php b/intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/template.php index 7a3e3fd7..9d8be07f 100644 --- a/intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/template.php +++ b/intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/template.php @@ -115,10 +115,10 @@ use Bitrix\Main\Localization\Loc; ?> -
- +
- /> + /> +
diff --git a/intaro.retailcrm/lib/component/constants.php b/intaro.retailcrm/lib/component/constants.php index 1f57c107..f91d2beb 100644 --- a/intaro.retailcrm/lib/component/constants.php +++ b/intaro.retailcrm/lib/component/constants.php @@ -103,5 +103,9 @@ class Constants ['EVENT_NAME' => 'OnSaleComponentOrderResultPrepared', 'FROM_MODULE' => 'sale'], ['EVENT_NAME' => 'OnAfterUserRegister', 'FROM_MODULE' => 'main'], ]; + public const SUBSCRIBE_EVENTS = [ + ['EVENT_NAME' => 'OnAfterUserRegister', 'FROM_MODULE' => 'main'], + ['EVENT_NAME' => 'OnAfterUserUpdate', 'FROM_MODULE' => 'main'] + ]; public const SITES_AVAILABLE = 'sites_available'; } diff --git a/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php b/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php index c63f6d5c..da02fbe3 100644 --- a/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php +++ b/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php @@ -3,11 +3,53 @@ namespace Intaro\RetailCrm\Component\Installer; use Intaro\RetailCrm\Component\Constants; +use Bitrix\Main\EventManager; +use Intaro\RetailCrm\Component\Handlers\EventsHandlers; +use Intaro\RetailCrm\Repository\ToModuleRepository; +use Bitrix\Main\SystemException; +use Bitrix\Main\ObjectPropertyException; +use Bitrix\Main\ArgumentException; +use RCrmActions; IncludeModuleLangFile(__FILE__); trait SubscriberInstallerTrait { + public function addSubscribeEvents(): void + { + $eventManager = EventManager::getInstance(); + + foreach (Constants::SUBSCRIBE_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\SubscriberInstallerTrait::addSubscribeEvents', + $exception->getMessage() + ); + } + } + } + public function CopyFilesSubscribe(): void { $pathFrom = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . Constants::MODULE_ID . '/install'; @@ -26,7 +68,7 @@ trait SubscriberInstallerTrait foreach ($lpTemplateNames as $lpTemplateName){ $lpTemplatePath = $_SERVER['DOCUMENT_ROOT'] - . '/local/templates/.default/components/bitrix/' . $lpTemplateName . '/default_subscribe10'; + . '/local/templates/.default/components/bitrix/' . $lpTemplateName . '/default_subscribe12'; if (!file_exists($lpTemplatePath)) { $pathFrom = $_SERVER['DOCUMENT_ROOT']