• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/services/base/restrictionmanager.php
  • Класс: BitrixSaleServicesBaseRestrictionManager
  • Вызов: RestrictionManager::applyRestriction
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 BitrixMainError($publicErrorMessage));

		return $result;
	}

	/**
	 *	@var BitrixMainEntityResult $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;
}