• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/helpers/admin/blocks/orderbuyer.php
  • Класс: BitrixSaleHelpersAdminBlocksOrderBuyer
  • Вызов: OrderBuyer::getProfileValuesFromPrevOrder
static function getProfileValuesFromPrevOrder($userId, $personTypeId)
{
	if(intval($personTypeId) <= 0)
		throw new ArgumentNullException('userId');

	if(intval($personTypeId) <= 0)
		throw new ArgumentNullException('personTypeId');

	$registry = SaleRegistry::getInstance(SaleRegistry::REGISTRY_TYPE_ORDER);
	/** @var SaleOrder $orderClass */
	$orderClass = $registry->getOrderClassName();

	$res = $orderClass::getList(array(
		'filter' => array(
			'USER_ID' => $userId
		),
		'order' => array('DATE_INSERT' => 'DESC'),
		'select' => array('ID')
	));

	if(!$order = $res->fetch())
	{
		return array();
	}

	/** @var BitrixSaleOrder $order */
	$order = $orderClass::load($order['ID']);

	if(!$order)
		return array();

	$propCollection = $order->getPropertyCollection();

	if(!$propCollection)
		return array();

	$result = array();

	$pRes = OrderPropsTable::getList(array(
		'filter' => array(
			'PERSON_TYPE_ID' => $personTypeId,
			'ACTIVE' => 'Y',
			'USER_PROPS' => 'Y'
		)
	));

	while($prop = $pRes->fetch())
	{
		if($prop['DEFAULT_VALUE'] <> '')
		{
			$result[$prop['ID']] = $prop['DEFAULT_VALUE'];
		}
		else
		{
			$property = null;

			if($prop['IS_EMAIL'] == 'Y')
				$property = $propCollection->getUserEmail();
			elseif($prop['IS_PAYER'] == 'Y')
				$property = $propCollection->getPayerName();
			elseif($prop['IS_PHONE'] == 'Y')
				$property = $propCollection->getPhone();
			elseif($prop['IS_ADDRESS'] == 'Y')
				$property = $propCollection->getAddress();

			if($property)
				$result[$prop['ID']] = $property->getValue();
		}
	}

	return $result;
}