CCrmProductSection::Add

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmProductSection
  4. Add
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_product_section.php
  • Класс: \CCrmProductSection
  • Вызов: CCrmProductSection::Add
static function Add(&$arFields)
{
	if (!CModule::IncludeModule('iblock'))
	{
		return false;
	}

	if(!(isset($arFields['NAME']) && is_string($arFields['NAME']) && $arFields['NAME'] !== ''))
	{
		self::$LAST_ERROR_CODE = self::ERR_SECTION_NAME_EMPTY;
		self::$LAST_ERROR = GetMessage('CRM_PRODUCT_SECTION_ERR_SECTION_NAME_EMPTY');
		return false;
	}

	$catalogID = isset($arFields['CATALOG_ID']) ? (int)$arFields['CATALOG_ID'] : 0;
	if(!($catalogID > 0 && CCrmCatalog::Exists($catalogID)))
	{
		$catalogID = (int)CCrmCatalog::EnsureDefaultExists();
	}
	$arFields['CATALOG_ID'] = $catalogID;

	$sectionFields = CCrmProductSectionDbResult::MapKeys($arFields);
	$sectionFields['CHECK_PERMISSIONS'] = 'N';

	$section = new CIBlockSection();
	if (!isset($sectionFields['CODE']))
	{
		$mnemonicCode = $section->generateMnemonicCode($sectionFields['NAME'], $sectionFields['IBLOCK_ID']);
		if ($mnemonicCode !== null)
		{
			$sectionFields['CODE'] = $mnemonicCode;
		}
	}
	$result = $section->Add($sectionFields);

	if(!(is_int($result) && $result > 0))
	{
		self::$LAST_ERROR_CODE = self::ERR_IBLOCK_SECTION_ADD;
		self::$LAST_ERROR = $section->LAST_ERROR;
	}

	return $result;
}

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