• Модуль: iblock
  • Путь к файлу: ~/bitrix/modules/iblock/classes/general/comp_pricetools.php
  • Класс: CIBlockPriceTools
  • Вызов: CIBlockPriceTools::CheckProductProperties
static function CheckProductProperties($iblockID, $elementID, $propertiesList, $propertiesValues, $enablePartialList = false)
{
	$propertyTypeSupport = array(
		'Y' => array(
			'N' => true,
			'S' => true,
			'L' => true,
			'G' => true,
			'E' => true
		),
		'N' => array(
			'L' => true,
			'E' => true
		)
	);
	$iblockID = (int)$iblockID;
	$elementID = (int)$elementID;
	if (0 >= $iblockID || 0 >= $elementID)
		return 6;
	$enablePartialList = (true === $enablePartialList);
	$sortIndex = 1;
	$result = array();
	if (!is_array($propertiesList))
		$propertiesList = array();
	if (empty($propertiesList))
		return $result;
	$checkProps = array_fill_keys($propertiesList, true);
	$propCodes = $checkProps;
	$existProps =  array();
	$rsProps = CIBlockElement::GetProperty($iblockID, $elementID, 'sort', 'asc', array());
	while ($oneProp = $rsProps->Fetch())
	{
		if (!isset($propCodes[$oneProp['CODE']]) && !isset($propCodes[$oneProp['ID']]))
			continue;
		$propID = (isset($propCodes[$oneProp['CODE']]) ? $oneProp['CODE'] : $oneProp['ID']);
		if (!isset($checkProps[$propID]))
			continue;

		if (!isset($propertyTypeSupport[$oneProp['MULTIPLE']][$oneProp['PROPERTY_TYPE']]))
		{
			return ($oneProp['MULTIPLE'] == 'Y' ? 2 : 3);
		}

		if (null !== $oneProp['VALUE'])
		{
			$existProps[$propID] = true;
		}

		if (!isset($propertiesValues[$propID]))
		{
			if ($enablePartialList)
			{
				continue;
			}
			return 1;
		}

		if (!is_scalar($propertiesValues[$propID]))
				return 5;

		$propertiesValues[$propID] = (string)$propertiesValues[$propID];
		$existValue = ('' != $propertiesValues[$propID]);
		if (!$existValue)
			return 1;

		$userTypeProp = false;
		$userType = null;
		if (isset($oneProp['USER_TYPE']) && !empty($oneProp['USER_TYPE']))
		{
			$userTypeDescr = CIBlockProperty::GetUserType($oneProp['USER_TYPE']);
			if (isset($userTypeDescr['GetPublicViewHTML']))
			{
				$userTypeProp = true;
				$userType = $userTypeDescr['GetPublicViewHTML'];
			}
		}

		if ($oneProp["MULTIPLE"] == "Y")
		{
			if ($userTypeProp)
			{
				if ($oneProp["VALUE"] == $propertiesValues[$propID])
				{
					$displayValue = (string)call_user_func_array($userType,
						array(
							$oneProp,
							array('VALUE' => $oneProp['VALUE']),
							array('MODE' => 'SIMPLE_TEXT')
						));
					$result[] = array(
						"NAME" => $oneProp["NAME"],
						"CODE" => $propID,
						"VALUE" => $displayValue,
						"SORT" => $sortIndex++,
					);
					unset($checkProps[$propID]);//mark as found
				}
			}
			else
			{
				switch($oneProp["PROPERTY_TYPE"])
				{
				case "S":
				case "N":
					if ($oneProp["VALUE"] == $propertiesValues[$propID])
					{
						$result[] = array(
							"NAME" => $oneProp["NAME"],
							"CODE" => $propID,
							"VALUE" => $oneProp["VALUE"],
							"SORT" => $sortIndex++,
						);
						unset($checkProps[$propID]);//mark as found
					}
					break;
				case "G":
					if ($oneProp["VALUE"] == $propertiesValues[$propID])
					{
						$rsSection = CIBlockSection::GetList(
							array(),
							array("=ID" => $oneProp["VALUE"]),
							false,
							array('ID', 'NAME')
						);
						if($arSection = $rsSection->Fetch())
						{
							$result[] = array(
								"NAME" => $oneProp["NAME"],
								"CODE" => $propID,
								"VALUE" => $arSection["NAME"],
								"SORT" => $sortIndex++,
							);
							unset($checkProps[$propID]);//mark as found
						}
					}
					break;
				case "E":
					if ($oneProp["VALUE"] == $propertiesValues[$propID])
					{
						$rsElement = CIBlockElement::GetList(
							array(),
							array("=ID" => $oneProp["VALUE"]),
							false,
							false,
							array("ID", "NAME")
						);
						if ($arElement = $rsElement->Fetch())
						{
							$result[] = array(
								"NAME" => $oneProp["NAME"],
								"CODE" => $propID,
								"VALUE" => $arElement["NAME"],
								"SORT" => $sortIndex++,
							);
							unset($checkProps[$propID]);//mark as found
						}
					}
					break;
				case "L":
					if ($oneProp["VALUE"] == $propertiesValues[$propID])
					{
						$rsEnum = CIBlockPropertyEnum::GetList(
							array(),
							array( "ID" => $propertiesValues[$propID], "IBLOCK_ID" => $iblockID, "PROPERTY_ID" => $oneProp['ID'])
						);
						if ($arEnum = $rsEnum->Fetch())
						{
							$result[] = array(
								"NAME" => $oneProp["NAME"],
								"CODE" => $propID,
								"VALUE" => $arEnum["VALUE"],
								"SORT" => $sortIndex++,
							);
							unset($checkProps[$propID]);//mark as found
						}
					}
					break;
				}
			}
		}
		else
		{
			switch ($oneProp["PROPERTY_TYPE"])
			{
			case "L":
				if (0 < (int)$propertiesValues[$propID])
				{
					$rsEnum = CIBlockPropertyEnum::GetList(
						array(),
						array("ID" => $propertiesValues[$propID], "IBLOCK_ID" => $iblockID, "PROPERTY_ID" => $oneProp['ID'])
					);
					if ($arEnum = $rsEnum->Fetch())
					{
						$result[] = array(
							"NAME" => $oneProp["NAME"],
							"CODE" => $propID,
							"VALUE" => $arEnum["VALUE"],
							"SORT" => $sortIndex++,
						);
						unset($checkProps[$propID]);//mark as found
					}
				}
				break;
			case "E":
				if (0 < (int)$propertiesValues[$propID])
				{
					$rsElement = CIBlockElement::GetList(
						array(),
						array("=ID" => $propertiesValues[$propID]),
						false,
						false,
						array("ID", "NAME")
					);
					if ($arElement = $rsElement->Fetch())
					{
						$result[] = array(
							"NAME" => $oneProp["NAME"],
							"CODE" => $propID,
							"VALUE" => $arElement["NAME"],
							"SORT" => $sortIndex++,
						);
						unset($checkProps[$propID]);//mark as found
					}
				}
				break;
			}
		}
	}

	if ($enablePartialList && !empty($checkProps))
	{
		$nonExistProps = array_keys($checkProps);
		foreach ($nonExistProps as &$oneCode)
		{
			if (!isset($existProps[$oneCode]))
				unset($checkProps[$oneCode]);
		}
		unset($oneCode);
	}

	if(!empty($checkProps))
		return 4;

	return $result;
}