Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
persontype.php
1
<?php
2
3
namespace
Bitrix\Sale
;
4
5
use
Bitrix\Main\ArgumentException
;
6
use
Bitrix\Sale\Internals
;
7
use
Bitrix\Main\Entity
;
8
use
Bitrix\Main\Localization\Loc
;
9
10
Loc::loadMessages
(__FILE__);
11
16
class
PersonType
17
{
19
protected
$siteId
;
20
22
private
$personTypeList = array();
23
27
protected
function
__construct
() {}
28
32
public
static
function
getRegistryType
()
33
{
34
return
Registry::REGISTRY_TYPE_ORDER
;
35
}
36
41
private
static
function
createPersonTypeObject()
42
{
43
$registry =
Registry::getInstance
(static::getRegistryType());
44
$personTypeClassName = $registry->getPersonTypeClassName();
45
46
return
new
$personTypeClassName();
47
}
48
57
public
static
function
load
(
$siteId
=
null
, $id =
null
)
58
{
59
if
(strval(
$siteId
) ==
""
&& intval($id) <= 0)
60
{
61
throw
new
ArgumentException
();
62
}
63
64
$personType = static::createPersonTypeObject();
65
$personType->siteId =
$siteId
;
66
67
$filter = array(
"=ACTIVE"
=>
"Y"
);
68
69
if
(strval(
$siteId
) !=
""
)
70
{
71
$filter[
'=PERSON_TYPE_SITE.SITE_ID'
] =
$siteId
;
72
}
73
74
if
($id > 0)
75
{
76
$filter[
'ID'
] = $id;
77
}
78
79
$personTypeList = static::getList([
'order'
=>[
"SORT"
=>
"ASC"
,
"ID"
=>
"ASC"
],
'filter'
=> $filter])
80
->fetchAll();
81
82
if
($personTypeList)
83
{
84
foreach
($personTypeList as $personTypeData)
85
{
86
$personType->personTypeList[$personTypeData[
'ID'
]] = $personTypeData;
87
}
88
}
89
90
return
$personType->personTypeList;
91
}
92
100
public
static
function
getList
(array $parameters = [])
101
{
102
if
(!isset($parameters[
'filter'
]))
103
{
104
$parameters[
'filter'
] = [];
105
}
106
107
$parameters[
'filter'
][
'=ENTITY_REGISTRY_TYPE'
] = static::getRegistryType();
108
109
return
Internals\PersonTypeTable::getList($parameters);
110
}
111
119
public
static
function
doCalculate
(
OrderBase
$order)
120
{
121
$result =
new
Result
();
122
123
if
($order->
getPersonTypeId
() !==
null
)
124
{
125
if
(!($personTypeList = static::load($order->
getSiteId
(), $order->
getPersonTypeId
())))
126
{
127
$result->addError(
new
Entity
\
EntityError
(GetMessage(
'SKGP_PERSON_TYPE_NOT_FOUND'
),
'PERSON_TYPE_ID'
));
128
}
129
130
return
$result;
131
}
132
133
if
(($personTypeList = static::load($order->
getSiteId
())) && !empty($personTypeList) && is_array($personTypeList))
134
{
135
$firstPersonType = reset($personTypeList);
136
$order->
setPersonTypeId
($firstPersonType[
"ID"
]);
137
}
138
else
139
{
140
$result->addError(
new
Entity
\
EntityError
(GetMessage(
'SKGP_PERSON_TYPE_EMPTY'
),
'PERSON_TYPE_ID'
));
141
}
142
143
return
$result;
144
}
145
149
public
static
function
generateXmlId
()
150
{
151
return
uniqid(
'bx_'
);
152
}
153
160
public
static
function
isIndividual
($personTypeId)
161
{
162
$row =
BusinessValue::getPersonTypes
()[$personTypeId] ??
null
;
163
if
($row)
164
{
165
return
$row[
'DOMAIN'
] ===
BusinessValue::INDIVIDUAL_DOMAIN
;
166
}
167
return
false
;
168
}
169
176
public
static
function
isEntity
($personTypeId)
177
{
178
$row =
BusinessValue::getPersonTypes
()[$personTypeId] ??
null
;
179
if
($row)
180
{
181
return
$row[
'DOMAIN'
] ===
BusinessValue::ENTITY_DOMAIN
;
182
}
183
return
false
;
184
}
185
}
Bitrix\Catalog\Model\Entity
Definition
entity.php:12
Bitrix\Main\ArgumentException
Definition
exception.php:34
Bitrix\Main\DB\Result
Definition
result.php:19
Bitrix\Main\Localization\Loc
Definition
loc.php:11
Bitrix\Main\Localization\Loc\loadMessages
static loadMessages($file)
Definition
loc.php:64
Bitrix\Main\ORM\EntityError
Definition
entityerror.php:12
Bitrix\Main\ORM\Entity
Definition
entity.php:26
Bitrix\Sale\BusinessValue\INDIVIDUAL_DOMAIN
const INDIVIDUAL_DOMAIN
Definition
businessvalue.php:17
Bitrix\Sale\BusinessValue\getPersonTypes
static getPersonTypes($all=false, array $resetAllPersonTypes=null)
Definition
businessvalue.php:627
Bitrix\Sale\BusinessValue\ENTITY_DOMAIN
const ENTITY_DOMAIN
Definition
businessvalue.php:16
Bitrix\Sale\OrderBase
Definition
orderbase.php:24
Bitrix\Sale\OrderBase\getSiteId
getSiteId()
Definition
orderbase.php:855
Bitrix\Sale\OrderBase\getPersonTypeId
getPersonTypeId()
Definition
orderbase.php:700
Bitrix\Sale\OrderBase\setPersonTypeId
setPersonTypeId($personTypeId)
Definition
orderbase.php:712
Bitrix\Sale\PersonType
Definition
persontype.php:17
Bitrix\Sale\PersonType\__construct
__construct()
Definition
persontype.php:27
Bitrix\Sale\PersonType\doCalculate
static doCalculate(OrderBase $order)
Definition
persontype.php:119
Bitrix\Sale\PersonType\load
static load($siteId=null, $id=null)
Definition
persontype.php:57
Bitrix\Sale\PersonType\isIndividual
static isIndividual($personTypeId)
Definition
persontype.php:160
Bitrix\Sale\PersonType\isEntity
static isEntity($personTypeId)
Definition
persontype.php:176
Bitrix\Sale\PersonType\$siteId
$siteId
Definition
persontype.php:19
Bitrix\Sale\PersonType\generateXmlId
static generateXmlId()
Definition
persontype.php:149
Bitrix\Sale\PersonType\getRegistryType
static getRegistryType()
Definition
persontype.php:32
Bitrix\Sale\PersonType\getList
static getList(array $parameters=[])
Definition
persontype.php:100
Bitrix\Sale\Registry\getInstance
static getInstance($type)
Definition
registry.php:183
Bitrix\Sale\Registry\REGISTRY_TYPE_ORDER
const REGISTRY_TYPE_ORDER
Definition
registry.php:16
Bitrix\Sale\Internals
Definition
accountnumber.php:3
Bitrix\Sale
modules
sale
lib
persontype.php
Создано системой
1.10.0