From abef997fc3c40bd98581669db0595e53f801d32d Mon Sep 17 00:00:00 2001 From: Ivan Chaplygin Date: Thu, 13 Jul 2023 15:28:40 +0300 Subject: [PATCH] =?UTF-8?q?ref=20#91040=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=BD=D0=B5=20=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=B7=D1=83=D0=B5=D0=BC=D1=8B=D0=B9=20=D1=81=D0=B5=D1=80=D0=B2?= =?UTF-8?q?=D0=B8=D1=81=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=BE=20?= =?UTF-8?q?=D1=81=D0=BE=D0=B1=D1=8B=D1=82=D0=B8=D0=B5=20OnBeforeUserUpdate?= =?UTF-8?q?=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B0=20=D0=B1?= =?UTF-8?q?=D1=83=D0=BB=D0=B5=D0=B2=D1=8B=D1=85=20=D1=82=D0=B8=D0=BF=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5=20=D0=B2=20CRM=20?= =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B0=20?= =?UTF-8?q?=D1=84=D0=BE=D1=80=D0=BC=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/general/events/RetailCrmEvent.php | 19 ++++++++++++ .../classes/general/user/RetailCrmUser.php | 15 +++++++++- intaro.retailcrm/include.php | 2 -- .../main.profile/.default/component.php | 29 ------------------- .../bitrix/main.profile/.default/template.php | 2 +- intaro.retailcrm/install/index.php | 3 +- .../installer/subscriberinstallertrait.php | 2 +- .../lib/service/subscriberservice.php | 16 ---------- 8 files changed, 37 insertions(+), 51 deletions(-) delete mode 100644 intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/component.php delete mode 100644 intaro.retailcrm/lib/service/subscriberservice.php diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index a3d10bb7..23e0d230 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -61,6 +61,25 @@ class RetailCrmEvent return true; } + /** + * @param $arFields + * + * @return bool + * @throws InvalidArgumentException + */ + public static function OnBeforeUserUpdate(&$arFields) + { + if (isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) { + return false; + } + + if (empty($arFields['UF_SUBSCRIBE_USER_EMAIL'])) { + $arFields['UF_SUBSCRIBE_USER_EMAIL'] = false; + } + + return true; + } + /** * onUpdateOrder * diff --git a/intaro.retailcrm/classes/general/user/RetailCrmUser.php b/intaro.retailcrm/classes/general/user/RetailCrmUser.php index 46db5b61..668ff8bb 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmUser.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmUser.php @@ -90,6 +90,7 @@ class RetailCrmUser if ($found) { $normalizer = new RestNormalizer(); $customer = $normalizer->normalize($customer, 'customers'); + $customer = self::getBooleanFields($customer); if (function_exists('retailCrmBeforeCustomerSend')) { $newResCustomer = retailCrmBeforeCustomerSend($customer); @@ -126,7 +127,10 @@ 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 (!empty($arFields['UF_SUBSCRIBE_USER_EMAIL']) && $arFields['UF_SUBSCRIBE_USER_EMAIL'] == true) { + $customer['subscribed'] = true; + } if (mb_strlen($arFields['EMAIL']) < 100) { $customer['email'] = $arFields['EMAIL']; @@ -134,4 +138,13 @@ class RetailCrmUser return $customer; } + + private static function getBooleanFields($customer) + { + if (empty($customer['subscribed'])) { + $customer['subscribed'] = false; + } + + return $customer; + } } diff --git a/intaro.retailcrm/include.php b/intaro.retailcrm/include.php index 2f7f6499..da9d245f 100644 --- a/intaro.retailcrm/include.php +++ b/intaro.retailcrm/include.php @@ -11,7 +11,6 @@ use Intaro\RetailCrm\Service\OrderLoyaltyDataService; use Intaro\RetailCrm\Service\LoyaltyService; use Intaro\RetailCrm\Service\LoyaltyAccountService; use Intaro\RetailCrm\Service\CustomerService; -use Intaro\RetailCrm\Service\SubscriberService; use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationReader; use Intaro\RetailCrm\Vendor\Doctrine\Common\Annotations\AnnotationRegistry; use \Intaro\RetailCrm\Component\Builder\Api\CustomerBuilder; @@ -44,7 +43,6 @@ ServiceLocator::registerServices([ CustomerService::class, OrderLoyaltyDataService::class, CustomerBuilder::class, - SubscriberService::class ]); $arJsConfig = [ diff --git a/intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/component.php b/intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/component.php deleted file mode 100644 index 040caec8..00000000 --- a/intaro.retailcrm/install/export/local/components/intaro/sale.personal.section/bitrix/main.profile/.default/component.php +++ /dev/null @@ -1,29 +0,0 @@ -IsAuthorized()) { - die(); -} - -try { - if (!Loader::includeModule('intaro.retailcrm')) { - die(GetMessage('MODULE_NOT_INSTALL')); - } -} catch (Throwable $exception) { - die(GetMessage('MODULE_NOT_INSTALL') . ': ' . $exception->getMessage()); -} - -try { - $arResult["arUser"]["SUBSCRIBE"] = SubscriberService::getSubscribeStatusUser(); - - $this->IncludeComponentTemplate(); -} catch (\Throwable $exception) { - $arResult['ERRORS'] = $exception->getMessage(); - - $this->IncludeComponentTemplate(); -} \ No newline at end of file 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 9d8be07f..a1bcf7e3 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 @@ -117,7 +117,7 @@ use Bitrix\Main\Localization\Loc;
- /> + />
diff --git a/intaro.retailcrm/install/index.php b/intaro.retailcrm/install/index.php index 71bf06f9..be5db0fb 100644 --- a/intaro.retailcrm/install/index.php +++ b/intaro.retailcrm/install/index.php @@ -248,7 +248,6 @@ class intaro_retailcrm extends CModule include($this->INSTALL_PATH . '/../lib/service/orderloyaltydataservice.php'); include($this->INSTALL_PATH . '/../lib/component/factory/clientfactory.php'); include($this->INSTALL_PATH . '/../lib/component/apiclient/clientadapter.php'); - include($this->INSTALL_PATH . '/../lib/service/subscriberservice.php'); $this->CopyFiles(); $this->addLPUserFields(); @@ -1074,6 +1073,7 @@ class intaro_retailcrm extends CModule RegisterModule($this->MODULE_ID); RegisterModuleDependences('sale', 'OnOrderUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'onUpdateOrder'); RegisterModuleDependences('main', 'OnAfterUserUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserUpdate'); + RegisterModuleDependences('main', 'OnBeforeUserUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'OnBeforeUserUpdate'); RegisterModuleDependences('sale', 'OnSaleOrderDeleted', $this->MODULE_ID, 'RetailCrmEvent', 'orderDelete'); RegisterModuleDependences('sale', 'OnSalePaymentEntitySaved', $this->MODULE_ID, 'RetailCrmEvent', 'paymentSave'); RegisterModuleDependences('sale', 'OnSalePaymentEntityDeleted', $this->MODULE_ID, 'RetailCrmEvent', 'paymentDelete'); @@ -1270,6 +1270,7 @@ class intaro_retailcrm extends CModule UnRegisterModuleDependences('sale', 'OnOrderUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'onUpdateOrder'); UnRegisterModuleDependences('main', 'OnAfterUserUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'OnAfterUserUpdate'); + UnRegisterModuleDependences('main', 'OnBeforeUserUpdate', $this->MODULE_ID, 'RetailCrmEvent', 'OnBeforeUserUpdate'); UnRegisterModuleDependences('sale', 'OnSaleOrderDeleted', $this->MODULE_ID, 'RetailCrmEvent', 'orderDelete'); UnRegisterModuleDependences('main', 'OnBeforeProlog', $this->MODULE_ID, 'RetailCrmCollector', 'add'); UnRegisterModuleDependences('main', 'OnBeforeProlog', $this->MODULE_ID, 'RetailCrmUa', 'add'); diff --git a/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php b/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php index 4ceedf2c..efa723a2 100644 --- a/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php +++ b/intaro.retailcrm/lib/component/installer/subscriberinstallertrait.php @@ -69,7 +69,7 @@ trait SubscriberInstallerTrait foreach ($lpTemplateNames as $lpTemplateName){ $lpTemplatePath = $_SERVER['DOCUMENT_ROOT'] - . '/local/templates/.default/components/bitrix/' . $lpTemplateName . '/default_subscribe12'; + . '/local/templates/.default/components/bitrix/' . $lpTemplateName . '/default_subscribe16'; if (!file_exists($lpTemplatePath)) { $pathFrom = $_SERVER['DOCUMENT_ROOT'] diff --git a/intaro.retailcrm/lib/service/subscriberservice.php b/intaro.retailcrm/lib/service/subscriberservice.php deleted file mode 100644 index 87585a80..00000000 --- a/intaro.retailcrm/lib/service/subscriberservice.php +++ /dev/null @@ -1,16 +0,0 @@ -GetID())->Fetch(); - - return isset($userFields['UF_SUBSCRIBE_EMAIL']) && $userFields['UF_SUBSCRIBE_EMAIL'] == '1'; - } -} \ No newline at end of file