• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/businessvalue.php
  • Класс: BitrixSaleBusinessValue
  • Вызов: BusinessValue::getMapping
static function getMapping($codeKey, $consumerKey = null, $personTypeId = null, array $options = array())
{
	$mapping = array();
	$codeKeyUp = ToUpper($codeKey);

	if ((int)$personTypeId === 0)
	{
		$personTypeId = null;
	}

	$match = isset($options['MATCH']) && is_int($options['MATCH']) ? $options['MATCH'] : self::MATCH_ALL;

	$consumerCodePersonMapping =
		isset($options['consumerCodePersonMapping']) && is_array($options['consumerCodePersonMapping']) // internal, do not use!
			? $options['consumerCodePersonMapping']
			: self::getConsumerCodePersonMapping()
	;

	if ($match & self::MATCH_EXACT && isset($consumerCodePersonMapping[$consumerKey][$codeKeyUp][$personTypeId]))
	{
		$mapping = $consumerCodePersonMapping[$consumerKey][$codeKeyUp][$personTypeId];
	}
	else
	{
		if ($match & self::MATCH_COMMON)
		{
			if ($personTypeId && isset($consumerCodePersonMapping[$consumerKey][$codeKeyUp]['']))
				$mapping = $consumerCodePersonMapping[$consumerKey][$codeKeyUp][''];
			elseif ($consumerKey && isset($consumerCodePersonMapping[''][$codeKeyUp][$personTypeId]))
				$mapping = $consumerCodePersonMapping[''][$codeKeyUp][$personTypeId];
			elseif ($consumerKey && $personTypeId && isset($consumerCodePersonMapping[''][$codeKeyUp]['']))
				$mapping = $consumerCodePersonMapping[''][$codeKeyUp][''];
		}

		if (! $mapping && $match & self::MATCH_DEFAULT && ($consumers = self::getConsumers()))
		{
			$mappingValue = $consumers[$consumerKey]['CODES'][$codeKey]['DEFAULT'] ?? null;
			if (is_array($mappingValue))
			{
				$mapping = $mappingValue;
			}
//				elseif ($consumerKey && is_array($consumers['']['CODES'][$codeKey]['DEFAULT']))
//				{
//					$mapping = $consumers['']['CODES'][$codeKey]['DEFAULT'];
//				}
		}
	}

	// TODO universal approach maybe later
	if ($mapping
		&& $mapping['PROVIDER_KEY'] == 'PROPERTY'
		&& $mapping['PROVIDER_VALUE']
		&& ($providers = BusinessValue::getProviders())
		&& is_callable($providers['PROPERTY']['GET_VALUE']))
	{
		$mapping['PROVIDER_VALUE'] = call_user_func($providers['PROPERTY']['GET_VALUE'],
			$mapping['PROVIDER_VALUE'],
			$personTypeId,
			$options['GET_VALUE']['PROPERTY'] ?? null,
			$options['GET_VALUE']['PROVIDER'] ?? null
		);
	}

	return $mapping;
}