Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
userimportbase.php
1
<?php
2
namespace
Bitrix\Sale\Exchange\Entity
;
3
4
5
use
Bitrix\Main\ArgumentException
;
6
use
Bitrix\Main\UserTable
;
7
use
Bitrix\Sale\Exchange\ImportBase
;
8
use
Bitrix\Sale\IBusinessValueProvider
;
9
use
Bitrix\Sale\Order
;
10
11
abstract
class
UserImportBase
extends
ImportBase
12
{
13
const
EXTERNAL_AUTH_ID
=
'sale'
;
14
16
protected
$entity
;
17
21
public
function
setEntity
(
ImportBase
$entity
)
22
{
23
$this->entity =
$entity
;
24
}
25
29
public
function
getEntity
()
30
{
31
return
$this->entity
;
32
}
33
40
public
function
getPropertyOrdersByConfig
($personalTypeId, $profile, $property)
41
{
42
$result = array();
43
44
if
($fieldsConfig = $this->
getFieldsConfig
($personalTypeId, $profile))
45
{
46
if
(is_array($fieldsConfig))
47
{
48
foreach
($fieldsConfig as $k => $v)
49
{
50
if
(!isset($v[
'VALUE'
]))
51
continue
;
52
53
if
(!empty($property[$k]))
54
{
55
$result[$v[
"VALUE"
]] = $property[$k];
56
}
57
58
if
(empty($result[$v[
"VALUE"
]]) && !empty($profile[$v[
"VALUE"
]]))
59
{
60
$result[$v[
"VALUE"
]] = $profile[$v[
"VALUE"
]];
61
}
62
}
63
}
64
}
65
return
$result;
66
}
67
73
public
function
getFieldsConfig
($orgFormId, $userProps=array())
74
{
75
if
(intval($orgFormId)<=0)
76
return
false
;
77
78
$config = $this->
getConfig
();
79
80
if
(empty($config[$orgFormId]))
81
return
false
;
82
83
$fields
= $config[$orgFormId];
84
foreach
(
$fields
as $k => $v)
85
{
86
if
(empty($v) ||
87
((empty($v[
"VALUE"
]) || $v[
"TYPE"
] !=
"PROPERTY"
) &&
88
(empty($userProps) || (is_array($v) && is_string($v[
"VALUE"
]) && empty($userProps[$v[
"VALUE"
]])))
89
)
90
)
91
{
92
unset(
$fields
[$k]);
93
}
94
95
}
96
return
$fields
;
97
}
98
102
public
function
getConfig
()
103
{
104
static
$config =
null
;
105
106
if
($config ===
null
)
107
{
108
if
($personTypes = $this->
getListPersonType
($this->settings->getSiteId()))
109
{
110
$r = \CSaleExport::GetList(array(), array(
"PERSON_TYPE_ID"
=> $personTypes));
111
while
($ar = $r->Fetch())
112
{
113
$config[$ar[
"PERSON_TYPE_ID"
]] = unserialize($ar[
"VARS"
], [
'allowed_classes'
=>
false
]);
114
}
115
}
116
}
117
return
$config;
118
}
119
124
public
function
getListPersonType
($siteId)
125
{
126
static
$personType =
null
;
127
128
if
($personType ===
null
)
129
{
130
$registry = \Bitrix\Sale\Registry::getInstance(\
Bitrix
\
Sale
\
Registry::REGISTRY_TYPE_ORDER
);
131
$class = $registry->getPersonTypeClassName();
132
$r = $class::getlist([
'filter'
=> [
"=ACTIVE"
=>
"Y"
,
"=PERSON_TYPE_SITE.SITE_ID"
=> $siteId]]);
133
while
($ar = $r->fetch())
134
{
135
$personType[] = $ar[
"ID"
];
136
}
137
}
138
return
$personType;
139
}
140
144
public
function
isFiz
()
145
{
146
$fields
= $this->
getFieldValues
();
147
return
(
$fields
[
"TRAITS"
][
"TYPE"
] ==
"FIZ"
);
148
}
149
154
public
function
resolvePersonTypeId
(
$fields
)
155
{
156
$config = $this->
getConfig
();
157
158
if
(is_array($config))
159
{
160
foreach
($config as $id => $value)
161
{
162
if
(($value[
"IS_FIZ"
] ==
"Y"
&& $this->
isFiz
()) ||
163
($value[
"IS_FIZ"
] ==
"N"
&& !$this->
isFiz
()))
164
{
165
return
$id;
166
}
167
}
168
}
169
170
return
null
;
171
}
172
177
public
static
function
getPropertyOrdersByPersonalTypeId
($personTypeId)
178
{
179
static
$result =
null
;
180
181
if
($result[$personTypeId] ===
null
)
182
{
183
$dbOrderProperties = \CSaleOrderProps::GetList(
184
array(
"SORT"
=>
"ASC"
),
185
array(
186
"PERSON_TYPE_ID"
=> $personTypeId,
187
"ACTIVE"
=>
"Y"
,
188
"UTIL"
=>
"N"
,
189
"USER_PROPS"
=>
"Y"
,
190
),
191
false
,
192
false
,
193
array(
"ID"
,
"TYPE"
,
"NAME"
,
"CODE"
,
"USER_PROPS"
,
"SORT"
,
"MULTIPLE"
)
194
);
195
while
($arOrderProperties = $dbOrderProperties->Fetch())
196
$result[$personTypeId][] = $arOrderProperties;
197
}
198
199
return
$result[$personTypeId];
200
}
201
207
public
function
registerUser
(
$fields
, &$arErrors)
208
{
209
$userFields = array(
210
"NAME"
=>
$fields
[
"ITEM_NAME"
],
211
"EMAIL"
=>
$fields
[
"CONTACT"
][
"MAIL_NEW"
],
212
);
213
214
if
($userFields[
"NAME"
] ==
''
)
215
$userFields[
"NAME"
] =
$fields
[
"CONTACT"
][
"CONTACT_PERSON"
];
216
217
$userFields[
"NAME"
] = ($this->
isFiz
() ? $userFields[
"NAME"
]:array(
"NAME"
=>$userFields[
"NAME"
]));
218
219
$emServer = $_SERVER[
"SERVER_NAME"
];
220
if
(mb_strpos($_SERVER[
"SERVER_NAME"
],
"."
) ===
false
)
221
$emServer .=
".bx"
;
222
223
if
($userFields[
"EMAIL"
] ==
''
)
224
$userFields[
"EMAIL"
] =
"buyer"
. time() . GetRandomCode(2) .
"@"
. $emServer;
225
226
$id = \CSaleUser::DoAutoRegisterUser($userFields[
"EMAIL"
], $userFields[
"NAME"
], $this->settings->getSiteId(), $arErrors, array(
"XML_ID"
=>
$fields
[
"XML_ID"
],
"EXTERNAL_AUTH_ID"
=>self::EXTERNAL_AUTH_ID));
227
228
$obUser = new \CUser;
229
if
(
$fields
[
"CONTACT"
][
"PHONE"
] <>
''
)
230
$obUser->Update($id, array(
'WORK_PHONE'
=>
$fields
[
"CONTACT"
][
"PHONE"
]),
true
);
231
232
return
$id;
233
}
234
242
static
public
function
updateEmptyXmlId
($id, $xmlId)
243
{
244
$result =
false
;
245
246
if
(intval($id)>0)
247
{
248
$user = UserTable::getById($id);
249
if
(
$fields
= $user->fetch())
250
{
251
if
(
$fields
[
'XML_ID'
] ==
''
&&
$fields
[
'XML_ID'
] <> $xmlId)
252
{
253
$user = new \CUser;
254
$result = $user->Update($id, array(
'XML_ID'
=>$xmlId),
true
);
255
}
256
}
257
}
258
259
return
$result;
260
}
261
262
public
function
initFields
()
263
{
264
$this->
setFields
(array(
265
'TRAITS'
=> $this->
getFieldsTraits
(),
266
));
267
}
268
273
static
protected
function
getBusinessValueOrderProvider
(
IBusinessValueProvider
$entity
)
274
{
275
if
(!(
$entity
instanceof
Order
))
276
throw
new
ArgumentException
(
"entity must be instanceof Order"
);
277
278
return
$entity
;
279
}
280
}
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\UserTable
Definition
user.php:46
Bitrix\Sale\Exchange\Entity\UserImportBase
Definition
userimportbase.php:12
Bitrix\Sale\Exchange\Entity\UserImportBase\getEntity
getEntity()
Definition
userimportbase.php:29
Bitrix\Sale\Exchange\Entity\UserImportBase\getListPersonType
getListPersonType($siteId)
Definition
userimportbase.php:124
Bitrix\Sale\Exchange\Entity\UserImportBase\getPropertyOrdersByConfig
getPropertyOrdersByConfig($personalTypeId, $profile, $property)
Definition
userimportbase.php:40
Bitrix\Sale\Exchange\Entity\UserImportBase\getPropertyOrdersByPersonalTypeId
static getPropertyOrdersByPersonalTypeId($personTypeId)
Definition
userimportbase.php:177
Bitrix\Sale\Exchange\Entity\UserImportBase\getConfig
getConfig()
Definition
userimportbase.php:102
Bitrix\Sale\Exchange\Entity\UserImportBase\EXTERNAL_AUTH_ID
const EXTERNAL_AUTH_ID
Definition
userimportbase.php:13
Bitrix\Sale\Exchange\Entity\UserImportBase\updateEmptyXmlId
static updateEmptyXmlId($id, $xmlId)
Definition
userimportbase.php:242
Bitrix\Sale\Exchange\Entity\UserImportBase\getFieldsConfig
getFieldsConfig($orgFormId, $userProps=array())
Definition
userimportbase.php:73
Bitrix\Sale\Exchange\Entity\UserImportBase\$entity
$entity
Definition
userimportbase.php:16
Bitrix\Sale\Exchange\Entity\UserImportBase\getBusinessValueOrderProvider
static getBusinessValueOrderProvider(IBusinessValueProvider $entity)
Definition
userimportbase.php:273
Bitrix\Sale\Exchange\Entity\UserImportBase\resolvePersonTypeId
resolvePersonTypeId($fields)
Definition
userimportbase.php:154
Bitrix\Sale\Exchange\Entity\UserImportBase\registerUser
registerUser($fields, &$arErrors)
Definition
userimportbase.php:207
Bitrix\Sale\Exchange\Entity\UserImportBase\initFields
initFields()
Definition
userimportbase.php:262
Bitrix\Sale\Exchange\Entity\UserImportBase\isFiz
isFiz()
Definition
userimportbase.php:144
Bitrix\Sale\Exchange\Entity\UserImportBase\setEntity
setEntity(ImportBase $entity)
Definition
userimportbase.php:21
Bitrix\Sale\Exchange\ImportBase
Definition
importbase.php:9
Bitrix\Sale\Exchange\ImportBase\setFields
setFields(array $values)
Definition
importbase.php:132
Bitrix\Sale\Exchange\ImportBase\getFieldsTraits
getFieldsTraits()
Definition
importbase.php:174
Bitrix\Sale\Exchange\ImportBase\getFieldValues
getFieldValues()
Definition
importbase.php:161
Bitrix\Sale\Exchange\ImportBase\$fields
$fields
Definition
importbase.php:18
Bitrix\Sale\Helpers\Order
Definition
order.php:10
Bitrix\Sale\Registry\REGISTRY_TYPE_ORDER
const REGISTRY_TYPE_ORDER
Definition
registry.php:16
Bitrix\Sale\IBusinessValueProvider
Definition
businessvalueproviderinterface.php:6
Bitrix\Sale\Exchange\Entity
Definition
entityimport.php:2
Bitrix
Sale
modules
sale
lib
exchange
entity
userimportbase.php
Создано системой
1.10.0