applyRestriction
public static function \Bitrix\Sale\Services\Base\RestrictionManager::applyRestriction( int $serviceId, RestrictionInfo $restrictionInfo );
Метод применяет для сервиса указанное ограничение. Метод статический.
Параметры
| Параметр | Описание | Версия |
|---|---|---|
| $serviceId | Идентификатор сервиса. | |
| $restrictionInfo | Обёртка над ограничением. Содержит тип ограничения и массив опций этого ограничения. |
Примеры
public static function applyRestriction(int $serviceId, RestrictionInfo $restrictionInfo): Result
{
$result = new Result();
$restriction = static::getRestriction($restrictionInfo->getType());
$reflectionClass = new \ReflectionClass(static::class);
$methodPath = $reflectionClass->getName() . "::applyRestriction";
if (!$restriction)
{
Logger::addError("[{$methodPath}] restriction '{$restrictionInfo->getType()}' not found.");
$publicErrorMessage = Loc::getMessage(
'SALE_BASE_RSTR_MANAGER_FIND_RSTR_ERROR',
[
'#RSTR_CLASSNAME#' => htmlspecialcharsbx($restrictionInfo->getType())
]
);
$result->addError(new \Bitrix\Main\Error($publicErrorMessage));
return $result;
}
/**
* @var \Bitrix\Main\Entity\Result $restrictionApplyResult
* @var Restriction $restriction
*/
$restrictionApplyResult = $restriction::save(
[
'SERVICE_ID' => $serviceId,
'SERVICE_TYPE' => static::getServiceType(),
'PARAMS' => $restrictionInfo->getOptions()
]
);
if (!$restrictionApplyResult->isSuccess())
{
foreach ($restrictionApplyResult->getErrors() as $error)
{
Logger::addError("[{$methodPath}] " . $error->getMessage());
}
$publicErrorMessage = $restriction::getOnApplyErrorMessage();
$result->addError(new Error($publicErrorMessage));
}
return $result;
}
© «Битрикс», 2001-2025, «1С-Битрикс», 2025