Exemple #1
0
 public function Delete($ID)
 {
     global $DB;
     $ID = (int) $ID;
     foreach (GetModuleEvents("catalog", "OnBeforeCatalogDelete", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array($ID)) === false) {
             return false;
         }
     }
     foreach (GetModuleEvents("catalog", "OnCatalogDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     $bSuccess = true;
     $dbRes = CIBlockElement::GetList(array(), array("IBLOCK_ID" => $ID));
     while ($arRes = $dbRes->Fetch()) {
         if (!CCatalogProduct::Delete($arRes["ID"])) {
             $bSuccess = false;
         }
     }
     if ($bSuccess) {
         if (isset(self::$arCatalogCache[$ID])) {
             unset(self::$arCatalogCache[$ID]);
             if (defined('CATALOG_GLOBAL_VARS') && CATALOG_GLOBAL_VARS == 'Y') {
                 global $CATALOG_CATALOG_CACHE;
                 $CATALOG_CATALOG_CACHE = self::$arCatalogCache;
             }
         }
         if (isset(self::$catalogVatCache[$ID])) {
             unset(self::$catalogVatCache[$ID]);
         }
         CCatalogSKU::ClearCache();
         CCatalogProduct::ClearCache();
         return $DB->Query("DELETE FROM b_catalog_iblock WHERE IBLOCK_ID = " . $ID, true);
     }
     return false;
 }