CAllCrmCatalog::GetCatalogId

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmCatalog
  4. GetCatalogId
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_catalog.php
  • Класс: \CAllCrmCatalog
  • Вызов: CAllCrmCatalog::GetCatalogId
static function GetCatalogId($externalName = "", $originatorID = 0, $siteID = null)
{
	$iblockType = self::GetCatalogTypeID();
	$iblockId = 0;
	$catalogId = 0;

	if ($siteID == null)
		$siteID = SITE_ID;

	$dbIBlockType = CIBlockType::GetList(array(), array("=ID" => $iblockType));
	if (!($arIBlockType = $dbIBlockType->Fetch()))
	{
		$langTmp = "";
		$dbSite = CSite::GetByID($siteID);
		if ($arSite = $dbSite->Fetch())
			$langTmp = $arSite["LANGUAGE_ID"];

		$ib = new CIBlockType;
		$arFields = Array(
			"ID" => $iblockType,
			"LANG" => array($langTmp => array("NAME" => GetMessage("CRM_PROCUCT_CATALOG_TITLE")))
		);
		$ib->Add($arFields);
	}

	$dbIBlock = CIBlock::GetList(array(), array("XML_ID" => "crm_external_".$originatorID, "IBLOCK_TYPE_ID" => $iblockType));
	if ($arIBlock = $dbIBlock->Fetch())
		$iblockId = $arIBlock["ID"];

	if ($iblockId == 0)
	{
		$ib = new CIBlock();
		$arFields = array(
			"IBLOCK_TYPE_ID" => $iblockType,
			"XML_ID" => "crm_external_".$originatorID,
			"LID" => $siteID,
			"NAME" => $externalName,
			"ACTIVE" => 'Y',
			"SORT" => 100,
			"INDEX_ELEMENT" => "N",
			"WORKFLOW" => 'N',
			"BIZPROC" => 'N',
			"VERSION" => 1,
			"GROUP_ID" => array(1 => "X", 2 => "R"),
			"LIST_MODE" => 'S'
		);

		$iblockId = $ib->Add($arFields);
		$iblockId = intval($iblockId);
		if ($iblockId <= 0)
		{
			self::RegisterError($ib->LAST_ERROR);
			return false;
		}
	}

	$dbCatalog = CCrmCatalog::GetList(array(), array("IBLOCK_ID" => $iblockId));
	if ($arCatalog = $dbCatalog->Fetch())
		$catalogId = $arCatalog["ID"];

	if ($catalogId == 0)
	{
		$res = CCrmCatalog::Add(array(
			"ID" => $iblockId,
			"ORIGINATOR_ID" => $originatorID,
		));
		if (!$res)
		{
			/** @var $ex \CAdminException */
			if (($ex = $GLOBALS["APPLICATION"]->GetException()) !== false)
				self::RegisterError($ex->GetString());
			else
				self::RegisterError('Catalog creation error');

			return false;
		}

		$catalogId = $iblockId;
	}

	return $catalogId;
}

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