CCrmDealRestProxy::setProductRows

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmDealRestProxy
  4. setProductRows
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/restservice.php
  • Класс: \CCrmDealRestProxy
  • Вызов: CCrmDealRestProxy::setProductRows
public function setProductRows($ID, $rows)
{
	global $APPLICATION;

	$ID = intval($ID);
	if($ID <= 0)
	{
		throw new RestException('The parameter id is invalid or not defined.');
	}

	if(!is_array($rows))
	{
		throw new RestException('The parameter rows must be array.');
	}

	$userPermissions = CCrmPerms::GetCurrentUserPermissions();
	$categoryID = CCrmDeal::GetCategoryID($ID);
	if($categoryID < 0)
	{
		throw new RestException(
			!CCrmDeal::CheckUpdatePermission(0, $userPermissions) ? 'Access denied' : 'Not found'
		);
	}
	elseif(!CCrmDeal::CheckUpdatePermission($ID, $userPermissions, $categoryID))
	{
		throw new RestException('Access denied.');
	}

	if(!CCrmDeal::Exists($ID))
	{
		throw new RestException('Not found.');
	}

	$proxy = new CCrmProductRowRestProxy();

	$rows = array_values($rows);
	$actualRows = array();
	for($i = 0, $qty = count($rows); $i < $qty; $i++)
	{
		$row = $rows[$i];
		if(!is_array($row))
		{
			continue;
		}

		$proxy->prepareForSave($row);
		if(isset($row['OWNER_TYPE']))
		{
			unset($row['OWNER_TYPE']);
		}

		if(isset($row['OWNER_ID']))
		{
			unset($row['OWNER_ID']);
		}

		$actualRows[] = $row;
	}

	$result = CCrmDeal::SaveProductRows($ID, $actualRows, true, true, true);
	if(!$result)
	{
		$exp = $APPLICATION->GetException();
		if($exp)
		{
			throw new RestException($exp->GetString());
		}
	}
	return $result;
}

Добавить комментарий