CAllCrmCatalog::Delete

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CAllCrmCatalog
  4. Delete
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_catalog.php
  • Класс: \CAllCrmCatalog
  • Вызов: CAllCrmCatalog::Delete
static function Delete($ID)
{
	if (!Loader::includeModule('catalog'))
	{
		return false;
	}

	self::$LAST_ERROR = '';
	global $DB;
	$tableName = CCrmCatalog::TABLE_NAME;

	$ID = intval($ID);

	if(!is_array(self::GetByID($ID)))
	{
		// Is no exists
		return true;
	}

	$events = GetModuleEvents('crm', 'OnBeforeCrmCatalogDelete');
	while ($arEvent = $events->Fetch())
	{
		if (ExecuteModuleEventEx($arEvent, array($ID)) === false)
		{
			return false;
		}
	}

	$dbRes = CCrmProduct::GetList(array(), array('CATALOG_ID' => $ID), array('ID'));
	while ($arRes = $dbRes->Fetch())
	{
		$productID = $arRes['ID'];
		if (!CCrmProduct::Delete($productID))
		{
			self::RegisterError(sprintf('Deletion of CrmCatalog(ID=%d) is canceled. Could not delete CrmProduct(ID = %d).', $ID, $productID));
			return false;
		}
	}

	if(!$DB->Query('DELETE FROM '.$tableName.' WHERE ID = '.$ID, true))
	{
		return false;
	}

	// -------------- remove from catalog module -------------->
	$CCatalog = new CCatalog();
	if (!$CCatalog->Delete($ID))
	{
		return false;
	}
	// <-------------- remove from catalog module --------------

	CCrmEntityHelper::RemoveCached(self::CACHE_NAME, $ID);

	$events = GetModuleEvents('crm', 'OnCrmCatalogDelete');
	while ($arEvent = $events->Fetch())
	{
		ExecuteModuleEventEx($arEvent, array($ID));
	}

	return true;
}

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