From 85b53c6e27591253fa1fec04a659efbf2e0bf321 Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Thu, 13 Jul 2023 18:01:44 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#91040=20=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=B8=D1=81=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D1=83=D0=B5=D0=BC=D0=BE=D0=B3=D0=BE=20=D1=84=D1=83?= =?UTF-8?q?=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- intaro.retailcrm/install/index.php | 6 - .../component/installer/installertrait.php | 2 +- .../installer/loyaltyinstallertrait.php | 251 ------------------ .../installer/subscriberinstallertrait.php | 143 ---------- 4 files changed, 1 insertion(+), 401 deletions(-) delete mode 100644 intaro.retailcrm/lib/component/installer/loyaltyinstallertrait.php delete mode 100644 intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 68b83ae6..9bb192a9 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -14,8 +14,6 @@ use Bitrix\Sale\Delivery\Services\Manager; use Bitrix\Sale\EventActions; use Bitrix\Sale\Internals\OrderTable; use Intaro\RetailCrm\Component\ConfigProvider; -use Intaro\RetailCrm\Component\Installer\LoyaltyInstallerTrait; -use Intaro\RetailCrm\Component\Installer\SubscriberInstallerTrait; use Intaro\RetailCrm\Component\Installer\InstallerTrait; use Intaro\RetailCrm\Service\OrderLoyaltyDataService; use Intaro\RetailCrm\Vendor\Symfony\Component\Process\PhpExecutableFinder; @@ -31,14 +29,10 @@ if (class_exists('intaro_retailcrm')) { return false; } -include(__DIR__ . '/../lib/component/installer/loyaltyinstallertrait.php'); -include (__DIR__ . '/../lib/component/installer/subscriberinstallertrait.php'); include (__DIR__ . '/../lib/component/installer/installertrait.php'); class intaro_retailcrm extends CModule { - //use LoyaltyInstallerTrait; - //use SubscriberInstallerTrait; use InstallerTrait; public const V5 = 'v5'; diff --git a/intaro.retailcrm/lib/component/installer/installertrait.php b/intaro.retailcrm/lib/component/installer/installertrait.php index c34248a8..34368180 100644 --- a/intaro.retailcrm/lib/component/installer/installertrait.php +++ b/intaro.retailcrm/lib/component/installer/installertrait.php @@ -92,7 +92,7 @@ trait InstallerTrait } /** - * Add USER fields for LP + * Добавление полей пользователя для ПЛ и подписки */ public function addUserFields(): void { diff --git a/intaro.retailcrm/lib/component/installer/loyaltyinstallertrait.php b/intaro.retailcrm/lib/component/installer/loyaltyinstallertrait.php deleted file mode 100644 index 10f27f35..00000000 --- a/intaro.retailcrm/lib/component/installer/loyaltyinstallertrait.php +++ /dev/null @@ -1,251 +0,0 @@ - - * @license MIT - * @link http://retailcrm.ru - * @see http://retailcrm.ru/docs - */ - -namespace Intaro\RetailCrm\Component\Installer; - -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__); - -trait LoyaltyInstallerTrait -{ - /** - * create loyalty program events handlers - */ - public function addLPEvents(): void - { - $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() - ); - } - } - } - - /** - * CamelCase в имени является требованием Bitrix. Изменить на lowerCamelCase нельзя - */ - public function CopyFiles(): void - { - $pathFrom = $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/' . Constants::MODULE_ID . '/install'; - - CopyDirFiles( - $pathFrom . '/export', - $_SERVER['DOCUMENT_ROOT'], - true, - true, - false - ); - - $lpTemplateNames = [ - 'sale.order.ajax', - 'sale.basket.basket', - 'main.register', - ]; - - foreach ($lpTemplateNames as $lpTemplateName){ - $lpTemplatePath = $_SERVER['DOCUMENT_ROOT'] - . '/local/templates/.default/components/bitrix/' . $lpTemplateName . '/default_loyalty'; - - if (!file_exists($lpTemplatePath)) { - $pathFrom = $_SERVER['DOCUMENT_ROOT'] - . '/bitrix/modules/intaro.retailcrm/install/export/local/components/intaro/' - . $lpTemplateName - . '/templates/.default'; - - CopyDirFiles( - $pathFrom, - $lpTemplatePath, - true, - true, - false - ); - } - } - } - - /** - * Add USER fields for LP - */ - public function addLPUserFields(): void - { - $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'), - ], - ] - ); - } - - /** - * @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(); - $dbRes = CUserTypeEntity::GetList([], ['FIELD_NAME' => $filed['name']])->fetch(); - - 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 - */ - private function deleteLPEvents(): void - { - $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' - ); - } - } -} diff --git a/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php b/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php deleted file mode 100644 index efa723a2..00000000 --- a/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php +++ /dev/null @@ -1,143 +0,0 @@ -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'; - - CopyDirFiles( - $pathFrom . '/export', - $_SERVER['DOCUMENT_ROOT'], - true, - true, - false - ); - - $lpTemplateNames = [ - 'sale.personal.section' - ]; - - foreach ($lpTemplateNames as $lpTemplateName){ - $lpTemplatePath = $_SERVER['DOCUMENT_ROOT'] - . '/local/templates/.default/components/bitrix/' . $lpTemplateName . '/default_subscribe16'; - - if (!file_exists($lpTemplatePath)) { - $pathFrom = $_SERVER['DOCUMENT_ROOT'] - . '/bitrix/modules/intaro.retailcrm/install/export/local/components/intaro/' - . $lpTemplateName; - - CopyDirFiles( - $pathFrom, - $lpTemplatePath, - true, - true, - false - ); - } - } - } - - 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' - ); - } - } -} \ No newline at end of file