Product::addPropertyAction

  1. Bitrix24 API (v. 23.675.0)
  2. catalog
  3. Product
  4. addPropertyAction
  • Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/controller/product.php
  • Класс: BitrixCatalogControllerProduct
  • Вызов: Product::addPropertyAction
public function addPropertyAction($fields)
{
	$r = $this->checkPermissionIBlockModify($fields['IBLOCK_ID']);
	if(!$r->isSuccess())
	{
		$this->addErrors($r->getErrors());
		return null;
	}

	$iblockProperty = new CIBlockProperty();

	$propertyFields = array(
		'ACTIVE' => 'Y',
		'IBLOCK_ID' => $fields['IBLOCK_ID'],
		'NAME' => $fields['NAME'],
		'SORT' => $fields['SORT'] ?? 100,
		'CODE' => $fields['CODE'] ?? '',
		'MULTIPLE' => ($fields['MULTIPLE'] === 'Y') ? 'Y' : 'N',
		'IS_REQUIRED'=> ($fields['IS_REQUIRED'] === 'Y') ? 'Y' : 'N',
		'SECTION_PROPERTY'=> 'N',
	);

	$newID = (int)($iblockProperty->Add($propertyFields));
	if ($newID === 0)
	{
		$this->addError(new BitrixMainError($iblockProperty->LAST_ERROR));
		return null;
	}

	return [
		'ID' => $newID,
		'CONTROL_ID' => 'PROPERTY_'.$newID
	];
}

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