Documentation

Add

Description and parameters

bool
CCatalog::Add(
 array arFields
);

Method adds a new table entry for binding iblock to the catalog module. Non-static method.

Call parameters

ParameterDescription
arFields Array with binding parameters containing the following keys:
  • IBLOCK_ID - iblock code (ID) (required);
  • SUBSCRIPTION - flag "Content selling" (Y/N) (optional), default value - N;
  • VAT_ID - VAT type code (ID) (optional), default value - 0;
  • PRODUCT_IBLOCK_ID - product iblock code (ID) (for SKU iblock) (optional, only jointly with SKU_PROPERTY_ID), default value - 0;
  • SKU_PROPERTY_ID - property code (ID) product binding (for SKU iblock), (optional, only jointly with PRODUCT_IBLOCK_ID), default value - 0;
Optional keys, missing in the array get default values.

Returned values

Returns true on successfully added record and false otherwise. Error text message can be retrieved using $APPLICATION->GetException().

Before adding an entry/record to the table, checks binding parameters using the method CCatalog::CheckFields (correct parameters are described inside). On successful check, records to database. Attempting to add more than one record with the identical IBLOCK_ID causes database error.

See Also

Examples

Binding iblock to the Catalog module

$arFields = array(
	'IBLOCK_ID' => 2,			// product iblock code (ID)
	'YANDEX_EXPORT' => 'Y',		//
);
$boolResult = CCatalog::Add($arFields);
if ($boolResult == false)
{
	if ($ex = $APPLICATION->GetException())
	{
		$strError = $ex->GetString();
		ShowError($strError);
	}
}

Binding iblock to the Catalog module as SKU iblock

$arFields = array(
	'IBLOCK_ID' => 2,			// SKU iblock code (ID)
	'VAT_ID' => 2,				// VAT type code (ID) 
	'PRODUCT_IBLOCK_ID' => 10,	// product iblock code (ID) (can be bound or not bound to the Catalog module)
	'SKU_PROPERTY_ID' => 14		// binding code (ID) for iblock property with ID=2 to the iblock with ID=10 (property type - SKU)
);
$boolResult = CCatalog::Add($arFields);
if ($boolResult == false)
{
	if ($ex = $APPLICATION->GetException())
	{
		$strError = $ex->GetString();
		ShowError($strError);
	}
}

© «Bitrix24», 2001-2024
Up