public static function CreateCatalog($originatorID = '', $name = '', $siteID = null) { if (!is_string($originatorID) || strlen($originatorID) == 0) { $originatorID = null; } if ($siteID == null) { $siteID = SITE_ID; } $langID = LANGUAGE_ID; $dbSite = CSite::GetById($siteID); if ($arSite = $dbSite->Fetch()) { $langID = $arSite['LANGUAGE_ID']; } $result = true; //check type type $typeID = self::GetCatalogTypeID(); //$rsIBlockTypes = CIBlockType::GetByID($typeID); // CIBlockType::GetByID() is unstable $rsIBlockTypes = CIBlockType::GetList(array(), array("=ID" => $typeID)); if (!$rsIBlockTypes->Fetch()) { $iblocktype = new CIBlockType(); $result = $iblocktype->Add(array('ID' => $typeID, 'SECTIONS' => 'Y', 'IN_RSS' => 'N', 'SORT' => 100, 'LANG' => array($langID => array('NAME' => GetMessage('CRM_PRODUCT_CATALOG_TYPE_TITLE'), 'SECTION_NAME' => GetMessage('CRM_PRODUCT_CATALOG_SECTION_NAME'), 'ELEMENT_NAME' => GetMessage('CRM_PRODUCT_CATALOG_PRODUCT_NAME'))))); if (!$result) { self::RegisterError($iblocktype->LAST_ERROR); return false; } } //echo 'Error: '.$obBlocktype->LAST_ERROR.'<br/>'; $arSite = array(); $sites = CSite::GetList($by = 'sort', $order = 'desc', array('ACTIVE' => 'Y')); while ($site = $sites->Fetch()) { $arSite[] = $site['LID']; } //creation of iblock $iblock = new CIBlock(); $iblockID = $iblock->Add(array('NAME' => isset($name[0]) ? $name : GetMessage('CRM_PRODUCT_CATALOG_TITLE'), 'ACTIVE' => 'Y', 'IBLOCK_TYPE_ID' => $typeID, 'LID' => $siteID, 'SORT' => 100, 'XML_ID' => 'crm_external_' . $originatorID, 'INDEX_ELEMENT' => 'N', 'WORKFLOW' => 'N', 'BIZPROC' => 'N', 'VERSION' => 1, 'GROUP_ID' => array(2 => 'R'))); if ($iblockID === false) { self::RegisterError($iblock->LAST_ERROR); return false; } //echo 'Error: '.$iblock->LAST_ERROR.'<br/>'; //creation of catalog $result = CCrmCatalog::Add(array('ID' => $iblockID, 'ORIGINATOR_ID' => $originatorID)); if ($result === false) { self::RegisterError('Catalog creation error'); return false; } return $iblockID; }