27 public static function check($params, array $restrictionParams, $serviceId = 0)
29 if (is_array($restrictionParams) && isset($restrictionParams[
'PERSON_TYPE_ID']))
31 return in_array($params, $restrictionParams[
'PERSON_TYPE_ID']);
40 public static function validateRestriction($fields)
45 $serviceId = $fields[
'SERVICE_ID'] ??
null;
46 $needPersonTypeIds = (array) ($fields[
'PARAMS'][
'PERSON_TYPE_ID'] ?? []);
47 if ($serviceId && $needPersonTypeIds)
49 $paySystemFields = \Bitrix\Sale\PaySystem\Manager::getById($serviceId);
52 $paySystem =
new Service($paySystemFields);
54 $hasIndividualTypes =
false;
55 $hasLegalEntityTypes =
false;
57 $registryType = $paySystem->getField(
'ENTITY_REGISTRY_TYPE') ?? \Bitrix\Sale\PersonType::getRegistryType();
63 foreach ($needPersonTypeIds as $personTypeId)
65 if (!$hasIndividualTypes && $personTypeClass::isIndividual($personTypeId))
67 $hasIndividualTypes =
true;
70 if (!$hasLegalEntityTypes && $personTypeClass::isEntity($personTypeId))
72 $hasLegalEntityTypes =
true;
76 $clientType = $paySystem->getClientType();
77 if ($clientType === ClientType::B2B && $hasIndividualTypes)
83 elseif ($clientType === ClientType::B2C && $hasLegalEntityTypes)
86 new Error(
Loc::getMessage(
'SALE_PS_RESTRICTIONS_BY_PERSON_TYPE_ERROR_B2C_HAS_ENTITY'))
101 if ($entity instanceof CollectableEntity)
104 $collection = $entity->getCollection();
107 $order = $collection->getOrder();
109 elseif ($entity instanceof Order)
117 $personTypeId = $order->getPersonTypeId();
118 return $personTypeId;
139 return Loc::getMessage(
'SALE_PS_RESTRICTIONS_BY_PERSON_TYPE_ON_APPLY_ERROR_MSG');
149 $personTypeList = array();
151 $dbRes = \Bitrix\Sale\PersonType::getList();
153 while ($personType = $dbRes->fetch())
154 $personTypeList[$personType[
"ID"]] = $personType[
"NAME"].
" (".$personType[
"ID"].
")";
157 "PERSON_TYPE_ID" => array(
160 "LABEL" =>
Loc::getMessage(
"SALE_SALE_PS_RESTRICTIONS_BY_PERSON_TYPE_NAME"),
161 "OPTIONS" => $personTypeList
172 return Manager::SEVERITY_STRICT;
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)