ProductForm::createBrandAction

  1. Bitrix24 API (v. 23.675.0)
  2. catalog
  3. ProductForm
  4. createBrandAction
  • Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/controller/productform.php
  • Класс: BitrixCatalogControllerProductForm
  • Вызов: ProductForm::createBrandAction
public function createBrandAction(array $fields): ?array
{
	$iblockId = (int)$fields['iblockId'];
	$name = $fields['name'];

	if (empty($name))
	{
		$this->addError(new Error("Empty name"));

		return null;
	}

	if (!Loader::includeModule('highloadblock') || !Loader::includeModule('iblock'))
	{
		$this->addError(new Error("Modules is not included"));

		return null;
	}

	if (!CIBlockSectionRights::UserHasRightTo($iblockId, 0, 'section_element_bind'))
	{
		$this->addError(new Error("User has no permissions to create product"));

		return null;
	}

	$propertySettings = PropertyTable::getList([
		'select' => ['ID', 'USER_TYPE_SETTINGS'],
		'filter' => [
			'=IBLOCK_ID' => $iblockId,
			'=ACTIVE' => 'Y',
			'=CODE' => 'BRAND_FOR_FACEBOOK',
		],
		'limit' => 1,
	])
		->fetch()
	;

	if (!$propertySettings)
	{
		return null;
	}

	$propertySettings['USER_TYPE_SETTINGS'] = (
	$userTypeSettings = CheckSerializedData($propertySettings['USER_TYPE_SETTINGS'])
		? unserialize($propertySettings['USER_TYPE_SETTINGS'], ['allowed_classes' => false])
		: array()
	);

	if (empty($userTypeSettings['TABLE_NAME']))
	{
		return null;
	}

	$table = HLHighloadBlockTable::getList(
		array(
			'select' => array('TABLE_NAME', 'NAME', 'ID'),
			'filter' => array('=TABLE_NAME' => $userTypeSettings['TABLE_NAME'])
		)
	)->fetch();

	$xmlId = Random::getString(16);
	$brandEntity = HLHighloadBlockTable::compileEntity($table);
	$brandEntityClass = $brandEntity->getDataClass();
	$resultAdd = $brandEntityClass::add([
		'UF_NAME' => $name,
		'UF_XML_ID' => $xmlId,
	]);

	if (!$resultAdd->isSuccess())
	{
		$this->addErrors($resultAdd->getErrors());

		return null;
	}

	return [
		'id' => $xmlId,
	];
}

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