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

ref #91040 переработка передачи состояния подписки пользователя

This commit is contained in:
Ivan Chaplygin 2023-07-18 11:38:24 +03:00
parent a94df189d0
commit acb553eb0c
6 changed files with 11 additions and 33 deletions

View file

@ -81,8 +81,7 @@
"default": false
},
"subscribed": {
"type": "bool",
"default": false
"type": "string"
},
"commentary": {
"type": "string"

View file

@ -68,25 +68,6 @@ 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 true;
}
if (empty($arFields['UF_SUBSCRIBE_USER_EMAIL'])) {
$arFields['UF_SUBSCRIBE_USER_EMAIL'] = false;
}
return true;
}
/**
* onUpdateOrder
*

View file

@ -90,7 +90,7 @@ class RetailCrmUser
if ($found) {
$normalizer = new RestNormalizer();
$customer = $normalizer->normalize($customer, 'customers');
$customer = self::getBooleanFields($customer);
$customer = self::getBooleanFields($customer, $arFields);
if (function_exists('retailCrmBeforeCustomerSend')) {
$newResCustomer = retailCrmBeforeCustomerSend($customer);
@ -128,10 +128,6 @@ class RetailCrmUser
$customer['address']['text'] = $arFields['PERSONAL_STREET'] ?? null;
$customer['address']['index'] = $arFields['PERSONAL_ZIP'] ?? null;
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'];
}
@ -139,10 +135,14 @@ class RetailCrmUser
return $customer;
}
private static function getBooleanFields($customer)
private static function getBooleanFields($customer, $arFields)
{
if (empty($customer['subscribed'])) {
$customer['subscribed'] = false;
if (isset($arFields['UF_SUBSCRIBE_USER_EMAIL'])) {
if ($arFields['UF_SUBSCRIBE_USER_EMAIL'] === "1") {
$customer['subscribed'] = true;
} else {
$customer['subscribed'] = false;
}
}
return $customer;

View file

@ -117,7 +117,8 @@ 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="UF_SUBSCRIBE_USER_EMAIL" id="main-profile-subscribe" <?if($arResult["arUser"]["UF_SUBSCRIBE_USER_EMAIL"] == true) echo "checked";?>/>
<input type="hidden" name="UF_SUBSCRIBE_USER_EMAIL" value="0">
<input class="form-check-input" type="checkbox" name="UF_SUBSCRIBE_USER_EMAIL" value="1" 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

@ -1066,7 +1066,6 @@ 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');
@ -1265,7 +1264,6 @@ 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

@ -1140,7 +1140,6 @@ class UpdateSubscribe
RegisterModuleDependences('main', 'OnAfterUserRegister', 'intaro.retailcrm', 'RetailCrmEvent', 'OnAfterUserRegister');
RegisterModuleDependences('main', 'OnAfterUserAdd', 'intaro.retailcrm', 'RetailCrmEvent', 'OnAfterUserAdd');
RegisterModuleDependences('main', 'OnBeforeUserUpdate', 'intaro.retailcrm', 'RetailCrmEvent', 'OnBeforeUserUpdate');
return $this;
}