1
0
Fork 0
mirror of synced 2025-04-04 14:23:33 +03:00

ref #91040 удален не используемый сервис

Создано событие OnBeforeUserUpdate
Исправлена передача булевых типов данные в CRM
Исправлена форма
This commit is contained in:
Ivan Chaplygin 2023-07-13 15:28:40 +03:00
parent 08a068e7bd
commit abef997fc3
8 changed files with 37 additions and 51 deletions

View file

@ -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
*

View file

@ -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;
}
}

View file

@ -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 = [

View file

@ -1,29 +0,0 @@
<?php
use Intaro\RetailCrm\Service\SubscriberService;
global $USER;
Loc::loadMessages(__FILE__);
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true || !$USER->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();
}

View file

@ -117,7 +117,7 @@ use Bitrix\Main\Localization\Loc;
</div>
<div class="form-check row">
<div class="col-sm-8 col-md-9">
<input class="form-check-input" type="checkbox" name="SUBSCRIBE_CUSTOM" id="main-profile-subscribe" <?if($arResult["arUser"]["SUBSCRIBE"] === "Y") echo "checked";?>/>
<input class="form-check-input" type="checkbox" name="UF_SUBSCRIBE_USER_EMAIL" id="main-profile-subscribe" <?if($arResult["arUser"]["UF_SUBSCRIBE_USER_EMAIL"] == true) echo "checked";?>/>
<label class="form-check-label" for="main-profile-subscribe"><?=Loc::getMessage('SUBSCRIBE_EMAIL')?></label>
</div>
</div>

View file

@ -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');

View file

@ -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']

View file

@ -1,16 +0,0 @@
<?php
namespace Intaro\RetailCrm\Service;
class SubscriberService
{
public static function getSubscribeStatusUser(): bool
{
global $USER;
$userFields = CUser::GetByID($USER->GetID())->Fetch();
return isset($userFields['UF_SUBSCRIBE_EMAIL']) && $userFields['UF_SUBSCRIBE_EMAIL'] == '1';
}
}