From e6a911a2e70bbf574db31c73db578cdc2b466c90 Mon Sep 17 00:00:00 2001 From: ellynoize Date: Fri, 26 Sep 2025 01:33:00 -0400 Subject: [PATCH 1/7] add button --- .../classes/general/user/RetailCrmUser.php | 31 +++++++++++++++++++ intaro.retailcrm/lang/en/options.php | 1 + intaro.retailcrm/lang/ru/options.php | 1 + .../lib/controller/adminpanel.php | 11 +++++++ intaro.retailcrm/options.php | 28 +++++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/intaro.retailcrm/classes/general/user/RetailCrmUser.php b/intaro.retailcrm/classes/general/user/RetailCrmUser.php index dc454941..4bfced83 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmUser.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmUser.php @@ -264,4 +264,35 @@ public static function fixDateCustomer(): void $offset += $limit; } } + + public static function updateLoyaltyAccountIds() + { + $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); + $offset = 0; + $limit = 50; + + while (true) { + try { + $usersResult = UserTable::getList([ + 'select' => ['ID', 'UF_REG_IN_PL_INTARO'], + 'filter' => ['=UF_REG_IN_PL_INTARO' => true], + 'order' => ['ID'], + 'limit' => $limit, + 'offset' => $offset + ]); + } catch (\Exception $exception) { + Logger::getInstance()->write($exception->getMessage(), 'loyaltyIdsUpdate'); + + break; + } + + $users = $usersResult->fetchAll(); + + if ($users === []) { + break; + } + + $offset += $limit; + } + } } diff --git a/intaro.retailcrm/lang/en/options.php b/intaro.retailcrm/lang/en/options.php index 3a7912c6..e8f2f461 100644 --- a/intaro.retailcrm/lang/en/options.php +++ b/intaro.retailcrm/lang/en/options.php @@ -23,6 +23,7 @@ $MESS ['COUPON_CUSTOM_FIELD'] = 'Select a custom field in the CRM to transfer the applied coupon in the Bitrix order'; $MESS ['SELECT_VALUE'] = '-- Select a value --'; $MESS ['ORDER_UPLOAD'] = 'Re-upload orders'; +$MESS ['LP_IDS_UPDATE'] = 'Update participations'; $MESS ['LP_WARNING'] = 'Loyalty program of RetailCRM is available only with the “Uploading orders by event” options active'; $MESS ['ORDER_NUMBER'] = 'Order numbers: '; $MESS ['ORDER_UPLOAD_INFO'] = 'Click "Start uploading" to upload all the orders . Or list the required order IDs separated by commas, intervals or dashes. For example: 1, 3, 5-10, 12, 13... etc.'; diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index 92797a91..83812ae1 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -169,6 +169,7 @@ $MESS ['LP_CUSTOM_TEMP_CREATE_MSG'] = 'Создать шаблон default_loyalty для компонента регистрации %s c функциями Программы лояльности.
Внимание: если шаблон уже существует, то он будет перезаписан'; $MESS ['LP_DEF_TEMP_CREATE_MSG'] = 'Заменить шаблон .default компонента %s шаблоном с функциями Программы лояльности.
Если в папке шаблонов компонента уже будет .default, то он будет скопирован в папку .default_backup'; $MESS ['LP_CREATE_TEMPLATE'] = 'Создать шаблон'; +$MESS ['LP_IDS_UPDATE'] = 'Обновить участия'; $MESS ['LP_REPLACE_TEMPLATE'] = 'Заменить шаблон'; $MESS ['LP_SALE_ORDER_AJAX_HEAD'] = ' Управление компонентом Оформление заказа (sale.order.ajax)'; $MESS ['LP_TEMP_CHOICE_MSG'] = 'Выберите, в каких шаблонах сайта будет доступен шаблон компонента с функциями Программы лояльности:'; diff --git a/intaro.retailcrm/lib/controller/adminpanel.php b/intaro.retailcrm/lib/controller/adminpanel.php index 49f02c9c..c263d2c7 100644 --- a/intaro.retailcrm/lib/controller/adminpanel.php +++ b/intaro.retailcrm/lib/controller/adminpanel.php @@ -6,6 +6,7 @@ use Bitrix\Main\Engine\Controller; use Intaro\RetailCrm\Component\ConfigProvider; use Intaro\RetailCrm\Component\Constants; +use RetailCrmUser; /** * @category Integration @@ -88,6 +89,16 @@ public function createTemplateAction(array $templates, string $donor, string $re ]; } + /** + * @return int + */ + public function updateIdsAction(): int + { + RetailCrmUser::updateLoyaltyAccountIds(); + + return 1; + } + /** * @return string[] * @throws \Bitrix\Main\ArgumentOutOfRangeException diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 8023da3a..7aa5984b 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -1514,6 +1514,27 @@ function createTemplates(donor) { }); } + function updateIds() { + BX.ajax.runAction('intaro:retailcrm.api.adminpanel.updateIds', + { + data: { + sessid: BX.bitrix_sessid() + } + } + ).then(result => { + if (result.data === 1) { + BX.UI.Notification.Center.notify({ + content: "" + }); + } else { + BX.UI.Notification.Center.notify({ + content: "" + }); + } + + }); + } + function replaceDefaultTemplates(donor) { let templates = []; let i = 0; @@ -2371,6 +2392,13 @@ function updateAddressList() + + +
+ +
+ +
Date: Fri, 26 Sep 2025 14:29:29 +0500 Subject: [PATCH 2/7] working --- CHANGELOG.md | 3 + .../classes/general/user/RetailCrmUser.php | 69 ++++++++++++++++++- intaro.retailcrm/lang/en/options.php | 2 + intaro.retailcrm/lang/ru/options.php | 2 + intaro.retailcrm/lib/component/constants.php | 2 +- .../lib/controller/adminpanel.php | 8 +-- intaro.retailcrm/options.php | 2 +- 7 files changed, 80 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a63b23d..bbf400e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2025-09-26 v6.7.5 +- Добавлена опция обновления участий программы лояльности + ## 2025-08-29 v6.7.4 - Обновлен тип данных у стоимости доставки diff --git a/intaro.retailcrm/classes/general/user/RetailCrmUser.php b/intaro.retailcrm/classes/general/user/RetailCrmUser.php index 4bfced83..1fef23e6 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmUser.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmUser.php @@ -12,6 +12,7 @@ IncludeModuleLangFile(__FILE__); use Bitrix\Main\UserTable; +use Throwable; /** * Class RetailCrmUser @@ -265,16 +266,18 @@ public static function fixDateCustomer(): void } } - public static function updateLoyaltyAccountIds() + public static function updateLoyaltyAccountIds(): bool { $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $offset = 0; $limit = 50; + $optionsSitesList = RetailcrmConfigProvider::getSitesList(); + $status = true; while (true) { try { $usersResult = UserTable::getList([ - 'select' => ['ID', 'UF_REG_IN_PL_INTARO'], + 'select' => ['ID', 'UF_REG_IN_PL_INTARO', 'LID', 'UF_LP_ID_INTARO'], 'filter' => ['=UF_REG_IN_PL_INTARO' => true], 'order' => ['ID'], 'limit' => $limit, @@ -283,6 +286,8 @@ public static function updateLoyaltyAccountIds() } catch (\Exception $exception) { Logger::getInstance()->write($exception->getMessage(), 'loyaltyIdsUpdate'); + $status = false; + break; } @@ -293,6 +298,66 @@ public static function updateLoyaltyAccountIds() } $offset += $limit; + + foreach ($users as $user) { + $site = null; + + if ($optionsSitesList) { + if (isset($user['LID']) && array_key_exists($user['LID'], $optionsSitesList) && $optionsSitesList[$user['LID']] !== null) { + $site = $optionsSitesList[$user['LID']]; + } else { + continue; + } + } + + $filter['customerExternalId'] = $user['ID']; + + try { + $actualLoyalty = null; + $crmAccounts = RCrmActions::apiMethod($api, 'getLoyaltyAccounts', __METHOD__, $filter, $site); + + foreach ($crmAccounts['loyaltyAccounts'] as $crmAccount) { + $loyalty = $crmAccounts = RCrmActions::apiMethod( + $api, + 'getLoyaltyLoyalty', + __METHOD__, + $crmAccount['loyalty']['id'], + $site + ); + + if ($loyalty['loyalty']['active'] === true) { + $actualLoyalty = $crmAccount; + + break; + } + } + + if ($actualLoyalty !== null && $user['UF_LP_ID_INTARO'] !== $actualLoyalty['id']) { + $updateUser = new CUser; + $cardNumber = isset($actualLoyalty['cardNumber']) ? $actualLoyalty['cardNumber'] : ''; + + $fields = [ + "UF_LP_ID_INTARO" => $actualLoyalty['id'], + "UF_CARD_NUM_INTARO" => $cardNumber + ]; + + if ($updateUser->Update($user['ID'], $fields)) { + Logger::getInstance()->write( + sprintf('Loyalty account ID for user with id %s updated', $user['ID']), + 'loyaltyIdsUpdate' + ); + } + } + } catch (Throwable $exception) { + Logger::getInstance()->write($exception->getMessage(), 'loyaltyIdsUpdate'); + + continue; + } + + time_nanosleep(0, 550000000); + } } + + return $status; } } diff --git a/intaro.retailcrm/lang/en/options.php b/intaro.retailcrm/lang/en/options.php index e8f2f461..35a2718d 100644 --- a/intaro.retailcrm/lang/en/options.php +++ b/intaro.retailcrm/lang/en/options.php @@ -24,6 +24,8 @@ $MESS ['SELECT_VALUE'] = '-- Select a value --'; $MESS ['ORDER_UPLOAD'] = 'Re-upload orders'; $MESS ['LP_IDS_UPDATE'] = 'Update participations'; +$MESS ['IDS_UPDATED'] = 'Loyalty program successfully updated'; +$MESS ['IDS_NOT_UPDATED'] = 'Loyalty program update error'; $MESS ['LP_WARNING'] = 'Loyalty program of RetailCRM is available only with the “Uploading orders by event” options active'; $MESS ['ORDER_NUMBER'] = 'Order numbers: '; $MESS ['ORDER_UPLOAD_INFO'] = 'Click "Start uploading" to upload all the orders . Or list the required order IDs separated by commas, intervals or dashes. For example: 1, 3, 5-10, 12, 13... etc.'; diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index 83812ae1..747e65fe 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -160,6 +160,8 @@ $MESS ['LP_DEF_TEMP_CREATE_MSG'] = 'Заменить шаблон .default компонента sale.order.ajax шаблоном с функциями Программы лояльности.
Если в папке .local уже есть шаблон .default для sale.order.ajax, то он будет скопирован в папку .default_backup'; $MESS ['LOYALTY_PROGRAM_TITLE'] = 'Программа лояльности'; +$MESS ['IDS_UPDATED'] = 'Обновление участий программы лояльности завершено'; +$MESS ['IDS_NOT_UPDATED'] = 'Ошибка обновления участий программы лояльности'; $MESS ['LOYALTY_PROGRAM_TOGGLE_MSG'] = 'Активность программы лояльности'; $MESS ['LP_CUSTOM_TEMP_CREATE_MSG'] = 'Создать шаблон intaro.retailCRM для компонента оформления заказа sale.order.ajax c функциями Программы лояльности.
Внимение: если шаблон уже существует, то он будет перезаписан'; $MESS ['LP_DEF_TEMP_CREATE_MSG'] = 'Заменить шаблон .default компонента sale.order.ajax шаблоном с функциями Программы лояльности.
Если в папке .local уже есть шаблон .default для sale.order.ajax, то он будет скопирован в папку .default_backup'; diff --git a/intaro.retailcrm/lib/component/constants.php b/intaro.retailcrm/lib/component/constants.php index c0ece108..917e4f58 100644 --- a/intaro.retailcrm/lib/component/constants.php +++ b/intaro.retailcrm/lib/component/constants.php @@ -18,7 +18,7 @@ */ class Constants { - public const MODULE_VERSION = '6.7.4'; + public const MODULE_VERSION = '6.7.5'; public const CRM_PURCHASE_PRICE_NULL = 'purchasePrice_null'; public const BITRIX_USER_ID_PREFIX = 'bitrixUserId-'; public const CRM_USERS_MAP = 'crm_users_map'; diff --git a/intaro.retailcrm/lib/controller/adminpanel.php b/intaro.retailcrm/lib/controller/adminpanel.php index c263d2c7..95eb0b4a 100644 --- a/intaro.retailcrm/lib/controller/adminpanel.php +++ b/intaro.retailcrm/lib/controller/adminpanel.php @@ -90,13 +90,13 @@ public function createTemplateAction(array $templates, string $donor, string $re } /** - * @return int + * @return array */ - public function updateIdsAction(): int + public function updateIdsAction(): array { - RetailCrmUser::updateLoyaltyAccountIds(); + $success = RetailCrmUser::updateLoyaltyAccountIds(); - return 1; + return ['success' => $success]; } /** diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 7aa5984b..2f4283b4 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -1522,7 +1522,7 @@ function updateIds() { } } ).then(result => { - if (result.data === 1) { + if (result.data.success === true) { BX.UI.Notification.Center.notify({ content: "" }); From cd3e4497a67bebc67cddd14524000b6d4975863f Mon Sep 17 00:00:00 2001 From: ellynoize Date: Fri, 26 Sep 2025 14:49:45 +0500 Subject: [PATCH 3/7] bump --- .../classes/general/user/RetailCrmUser.php | 9 ++++++++- intaro.retailcrm/classes/general/user/log.txt | 1 + intaro.retailcrm/description.ru | 2 +- intaro.retailcrm/install/version.php | 4 ++-- .../lib/controller/adminpanel.php | 20 ++++++++++++++++++- 5 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 intaro.retailcrm/classes/general/user/log.txt diff --git a/intaro.retailcrm/classes/general/user/RetailCrmUser.php b/intaro.retailcrm/classes/general/user/RetailCrmUser.php index 1fef23e6..edb0cdee 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmUser.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmUser.php @@ -332,7 +332,7 @@ public static function updateLoyaltyAccountIds(): bool } } - if ($actualLoyalty !== null && $user['UF_LP_ID_INTARO'] !== $actualLoyalty['id']) { + if ($actualLoyalty !== null && $user['UF_LP_ID_INTARO'] != $actualLoyalty['id']) { $updateUser = new CUser; $cardNumber = isset($actualLoyalty['cardNumber']) ? $actualLoyalty['cardNumber'] : ''; @@ -360,4 +360,11 @@ public static function updateLoyaltyAccountIds(): bool return $status; } + + public static function updateLoyaltyAccountIdsAgent() + { + self::updateLoyaltyAccountIds(); + + return ""; + } } diff --git a/intaro.retailcrm/classes/general/user/log.txt b/intaro.retailcrm/classes/general/user/log.txt new file mode 100644 index 00000000..2bbd69c2 --- /dev/null +++ b/intaro.retailcrm/classes/general/user/log.txt @@ -0,0 +1 @@ +70 diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 151d099d..2ffb24a1 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Обновлен тип данных у стоимости доставки +- Добавлена опция обновления участий программы лояльности diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 07212f76..d9d0bf8d 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.7.4', - 'VERSION_DATE' => '2025-08-29 9:30:00' + 'VERSION' => '6.7.5', + 'VERSION_DATE' => '2025-09-26 9:30:00' ]; diff --git a/intaro.retailcrm/lib/controller/adminpanel.php b/intaro.retailcrm/lib/controller/adminpanel.php index 95eb0b4a..b7a5b21a 100644 --- a/intaro.retailcrm/lib/controller/adminpanel.php +++ b/intaro.retailcrm/lib/controller/adminpanel.php @@ -94,7 +94,25 @@ public function createTemplateAction(array $templates, string $donor, string $re */ public function updateIdsAction(): array { - $success = RetailCrmUser::updateLoyaltyAccountIds(); + // Устанавливаем разовый агент + $agentName = "RetailCrmUser::updateLoyaltyAccountIdsAgent();"; + + // Сначала удаляем существующего агента (если есть) + \CAgent::RemoveAgent($agentName, "intaro.retailcrm"); + + // Добавляем нового агента для выполнения через 1 минуту + $agentId = \CAgent::AddAgent( + $agentName, + "intaro.retailcrm", // модуль + "N", // не периодический (разовый) + 20, // интервал в секундах (1 минута) + "", // дата начала + "Y", // активность + date("d.m.Y H:i:s", time() + 10), // дата следующего запуска (через 1 минуту) + 30 // приоритет + ); + + $success = ($agentId !== false); return ['success' => $success]; } From f2b1759a7048e93358d9c96b785a8ab2d584c40d Mon Sep 17 00:00:00 2001 From: ellynoize Date: Fri, 26 Sep 2025 14:56:39 +0500 Subject: [PATCH 4/7] rename --- intaro.retailcrm/lang/en/options.php | 4 ++-- intaro.retailcrm/lang/ru/options.php | 4 ++-- .../lib/controller/adminpanel.php | 21 ++++++++----------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/intaro.retailcrm/lang/en/options.php b/intaro.retailcrm/lang/en/options.php index 35a2718d..8db35ff2 100644 --- a/intaro.retailcrm/lang/en/options.php +++ b/intaro.retailcrm/lang/en/options.php @@ -24,8 +24,8 @@ $MESS ['SELECT_VALUE'] = '-- Select a value --'; $MESS ['ORDER_UPLOAD'] = 'Re-upload orders'; $MESS ['LP_IDS_UPDATE'] = 'Update participations'; -$MESS ['IDS_UPDATED'] = 'Loyalty program successfully updated'; -$MESS ['IDS_NOT_UPDATED'] = 'Loyalty program update error'; +$MESS ['IDS_UPDATED'] = 'Task successfully created'; +$MESS ['IDS_NOT_UPDATED'] = 'Task not created. Error'; $MESS ['LP_WARNING'] = 'Loyalty program of RetailCRM is available only with the “Uploading orders by event” options active'; $MESS ['ORDER_NUMBER'] = 'Order numbers: '; $MESS ['ORDER_UPLOAD_INFO'] = 'Click "Start uploading" to upload all the orders . Or list the required order IDs separated by commas, intervals or dashes. For example: 1, 3, 5-10, 12, 13... etc.'; diff --git a/intaro.retailcrm/lang/ru/options.php b/intaro.retailcrm/lang/ru/options.php index 747e65fe..5f388882 100644 --- a/intaro.retailcrm/lang/ru/options.php +++ b/intaro.retailcrm/lang/ru/options.php @@ -160,8 +160,8 @@ $MESS ['LP_DEF_TEMP_CREATE_MSG'] = 'Заменить шаблон .default компонента sale.order.ajax шаблоном с функциями Программы лояльности.
Если в папке .local уже есть шаблон .default для sale.order.ajax, то он будет скопирован в папку .default_backup'; $MESS ['LOYALTY_PROGRAM_TITLE'] = 'Программа лояльности'; -$MESS ['IDS_UPDATED'] = 'Обновление участий программы лояльности завершено'; -$MESS ['IDS_NOT_UPDATED'] = 'Ошибка обновления участий программы лояльности'; +$MESS ['IDS_UPDATED'] = 'Агент для обновления участий ПЛ создан'; +$MESS ['IDS_NOT_UPDATED'] = 'Ошибка при добавлении агента'; $MESS ['LOYALTY_PROGRAM_TOGGLE_MSG'] = 'Активность программы лояльности'; $MESS ['LP_CUSTOM_TEMP_CREATE_MSG'] = 'Создать шаблон intaro.retailCRM для компонента оформления заказа sale.order.ajax c функциями Программы лояльности.
Внимение: если шаблон уже существует, то он будет перезаписан'; $MESS ['LP_DEF_TEMP_CREATE_MSG'] = 'Заменить шаблон .default компонента sale.order.ajax шаблоном с функциями Программы лояльности.
Если в папке .local уже есть шаблон .default для sale.order.ajax, то он будет скопирован в папку .default_backup'; diff --git a/intaro.retailcrm/lib/controller/adminpanel.php b/intaro.retailcrm/lib/controller/adminpanel.php index b7a5b21a..53e804f5 100644 --- a/intaro.retailcrm/lib/controller/adminpanel.php +++ b/intaro.retailcrm/lib/controller/adminpanel.php @@ -94,24 +94,21 @@ public function createTemplateAction(array $templates, string $donor, string $re */ public function updateIdsAction(): array { - // Устанавливаем разовый агент $agentName = "RetailCrmUser::updateLoyaltyAccountIdsAgent();"; - - // Сначала удаляем существующего агента (если есть) + \CAgent::RemoveAgent($agentName, "intaro.retailcrm"); - // Добавляем нового агента для выполнения через 1 минуту $agentId = \CAgent::AddAgent( $agentName, - "intaro.retailcrm", // модуль - "N", // не периодический (разовый) - 20, // интервал в секундах (1 минута) - "", // дата начала - "Y", // активность - date("d.m.Y H:i:s", time() + 10), // дата следующего запуска (через 1 минуту) - 30 // приоритет + "intaro.retailcrm", + "N", + 20, + "", + "Y", + date("d.m.Y H:i:s", time() + 10), + 30 ); - + $success = ($agentId !== false); return ['success' => $success]; From 800ffa439cd02fe7ec6fea05f637114a1013f5ca Mon Sep 17 00:00:00 2001 From: ellynoize Date: Fri, 26 Sep 2025 15:49:32 +0500 Subject: [PATCH 5/7] remove log --- intaro.retailcrm/classes/general/user/log.txt | 1 - 1 file changed, 1 deletion(-) delete mode 100644 intaro.retailcrm/classes/general/user/log.txt diff --git a/intaro.retailcrm/classes/general/user/log.txt b/intaro.retailcrm/classes/general/user/log.txt deleted file mode 100644 index 2bbd69c2..00000000 --- a/intaro.retailcrm/classes/general/user/log.txt +++ /dev/null @@ -1 +0,0 @@ -70 From 84a94a4384075754cf381c3e86c40a130cbc00dc Mon Sep 17 00:00:00 2001 From: ellynoize Date: Fri, 26 Sep 2025 17:23:17 +0500 Subject: [PATCH 6/7] resolves --- .../classes/general/user/RetailCrmUser.php | 43 ++++++++----------- .../lib/component/configprovider.php | 20 +++++++++ .../lib/controller/adminpanel.php | 23 +++++----- 3 files changed, 48 insertions(+), 38 deletions(-) diff --git a/intaro.retailcrm/classes/general/user/RetailCrmUser.php b/intaro.retailcrm/classes/general/user/RetailCrmUser.php index edb0cdee..28581211 100644 --- a/intaro.retailcrm/classes/general/user/RetailCrmUser.php +++ b/intaro.retailcrm/classes/general/user/RetailCrmUser.php @@ -12,6 +12,7 @@ IncludeModuleLangFile(__FILE__); use Bitrix\Main\UserTable; +use Retailcrm\ApiClient; use Throwable; /** @@ -208,7 +209,7 @@ public static function fixDateCustomer(): void COption::SetOptionString(RetailcrmConstants::MODULE_ID, RetailcrmConstants::OPTION_FIX_DATE_CUSTOMER, 'Y'); $startId = COption::GetOptionInt(RetailcrmConstants::MODULE_ID, RetailcrmConstants::OPTION_FIX_DATE_CUSTOMER_LAST_ID, 0); - $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); + $api = new ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $optionsSitesList = RetailcrmConfigProvider::getSitesList(); $limit = 50; $offset = 0; @@ -222,7 +223,7 @@ public static function fixDateCustomer(): void 'limit' => $limit, 'offset' => $offset, ]); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { Logger::getInstance()->write($exception->getMessage(), 'fixDateCustomers'); break; @@ -235,14 +236,10 @@ public static function fixDateCustomer(): void } foreach ($users as $user) { - $site = null; - - if ($optionsSitesList) { - if (isset($user['LID']) && array_key_exists($user['LID'], $optionsSitesList) && $optionsSitesList[$user['LID']] !== null) { - $site = $optionsSitesList[$user['LID']]; - } else { - continue; - } + $site = RetailcrmConfigProvider::getUserSite($user, $optionsSitesList); + + if ($optionsSitesList && $site === null) { + continue; } $customer['externalId'] = $user['ID']; @@ -252,7 +249,7 @@ public static function fixDateCustomer(): void $customer['createdAt'] = $date->format('Y-m-d H:i:s'); RCrmActions::apiMethod($api, 'customersEdit', __METHOD__, $customer, $site); - } catch (\Throwable $exception) { + } catch (Throwable $exception) { Logger::getInstance()->write($exception->getMessage(), 'fixDateCustomers'); continue; } @@ -268,7 +265,7 @@ public static function fixDateCustomer(): void public static function updateLoyaltyAccountIds(): bool { - $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); + $api = new ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); $offset = 0; $limit = 50; $optionsSitesList = RetailcrmConfigProvider::getSitesList(); @@ -283,7 +280,7 @@ public static function updateLoyaltyAccountIds(): bool 'limit' => $limit, 'offset' => $offset ]); - } catch (\Exception $exception) { + } catch (Throwable $exception) { Logger::getInstance()->write($exception->getMessage(), 'loyaltyIdsUpdate'); $status = false; @@ -300,14 +297,10 @@ public static function updateLoyaltyAccountIds(): bool $offset += $limit; foreach ($users as $user) { - $site = null; + $site = RetailcrmConfigProvider::getUserSite($user, $optionsSitesList); - if ($optionsSitesList) { - if (isset($user['LID']) && array_key_exists($user['LID'], $optionsSitesList) && $optionsSitesList[$user['LID']] !== null) { - $site = $optionsSitesList[$user['LID']]; - } else { - continue; - } + if ($optionsSitesList && $site === null) { + continue; } $filter['customerExternalId'] = $user['ID']; @@ -315,7 +308,7 @@ public static function updateLoyaltyAccountIds(): bool try { $actualLoyalty = null; $crmAccounts = RCrmActions::apiMethod($api, 'getLoyaltyAccounts', __METHOD__, $filter, $site); - + foreach ($crmAccounts['loyaltyAccounts'] as $crmAccount) { $loyalty = $crmAccounts = RCrmActions::apiMethod( $api, @@ -337,13 +330,13 @@ public static function updateLoyaltyAccountIds(): bool $cardNumber = isset($actualLoyalty['cardNumber']) ? $actualLoyalty['cardNumber'] : ''; $fields = [ - "UF_LP_ID_INTARO" => $actualLoyalty['id'], - "UF_CARD_NUM_INTARO" => $cardNumber + 'UF_LP_ID_INTARO' => $actualLoyalty['id'], + 'UF_CARD_NUM_INTARO' => $cardNumber ]; if ($updateUser->Update($user['ID'], $fields)) { Logger::getInstance()->write( - sprintf('Loyalty account ID for user with id %s updated', $user['ID']), + sprintf('Обновлен идентификатор участия ПЛ для пользователя с ID %s', $user['ID']), 'loyaltyIdsUpdate' ); } @@ -365,6 +358,6 @@ public static function updateLoyaltyAccountIdsAgent() { self::updateLoyaltyAccountIds(); - return ""; + return ''; } } diff --git a/intaro.retailcrm/lib/component/configprovider.php b/intaro.retailcrm/lib/component/configprovider.php index 2102d923..cda06eeb 100644 --- a/intaro.retailcrm/lib/component/configprovider.php +++ b/intaro.retailcrm/lib/component/configprovider.php @@ -1320,4 +1320,24 @@ public static function getStatusCollector() { return static::getOption(Constants::CRM_COLLECTOR, 'N'); } + + /** + * @param array|null $optionsSitesList + * @return string|null + */ + public static function getUserSite(array $user, array $optionsSitesList): ?string + { + if (!$optionsSitesList) { + return null; + } + + if (isset($user['LID']) && + array_key_exists($user['LID'], $optionsSitesList) && + $optionsSitesList[$user['LID']] !== null + ) { + return $optionsSitesList[$user['LID']]; + } + + return null; + } } diff --git a/intaro.retailcrm/lib/controller/adminpanel.php b/intaro.retailcrm/lib/controller/adminpanel.php index 53e804f5..959f5e7c 100644 --- a/intaro.retailcrm/lib/controller/adminpanel.php +++ b/intaro.retailcrm/lib/controller/adminpanel.php @@ -6,8 +6,7 @@ use Bitrix\Main\Engine\Controller; use Intaro\RetailCrm\Component\ConfigProvider; use Intaro\RetailCrm\Component\Constants; -use RetailCrmUser; - +use CAgent; /** * @category Integration * @package Intaro\RetailCrm\Controller @@ -94,24 +93,22 @@ public function createTemplateAction(array $templates, string $donor, string $re */ public function updateIdsAction(): array { - $agentName = "RetailCrmUser::updateLoyaltyAccountIdsAgent();"; + $agentName = 'RetailCrmUser::updateLoyaltyAccountIdsAgent();'; - \CAgent::RemoveAgent($agentName, "intaro.retailcrm"); + CAgent::RemoveAgent($agentName, 'intaro.retailcrm'); - $agentId = \CAgent::AddAgent( + $agentId = CAgent::AddAgent( $agentName, - "intaro.retailcrm", - "N", + 'intaro.retailcrm', + 'N', 20, - "", - "Y", - date("d.m.Y H:i:s", time() + 10), + '', + 'Y', + date('d.m.Y H:i:s', time() + 10), 30 ); - $success = ($agentId !== false); - - return ['success' => $success]; + return ['success' => $agentId !== false]; } /** From 4384c7cdcc46229e6d17e53b572258974339d01f Mon Sep 17 00:00:00 2001 From: ellynoize Date: Fri, 26 Sep 2025 17:45:40 +0500 Subject: [PATCH 7/7] button position --- intaro.retailcrm/options.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 2f4283b4..925d167f 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -2394,7 +2394,7 @@ function updateAddressList() -
+