Beispiel #1
0
 public static function OnIBlockElementDelete($ID)
 {
     return CCrmProduct::Delete($ID);
 }
Beispiel #2
0
                    if (isset($_POST['saveAndAdd'])) {
                        $redirectUrl = CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_EDIT'], array('product_id' => 0));
                    } else {
                        $redirectUrl = $arResult['BACK_URL'];
                    }
                }
                LocalRedirect(CHTTP::urlAddParams($redirectUrl, array('list_section_id' => isset($arResult['LIST_SECTION_ID']) ? $arResult['LIST_SECTION_ID'] : 0)));
            }
        }
    } else {
        if ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['delete'])) {
            $err = '';
            $productID = isset($arParams['PRODUCT_ID']) ? intval($arParams['PRODUCT_ID']) : 0;
            $product = $productID > 0 ? CCrmProduct::GetByID($productID, true) : null;
            if ($product) {
                if (!CCrmProduct::Delete($productID)) {
                    $err = CCrmProduct::GetLastError();
                    if (!isset($err[0])) {
                        $err = GetMessage('CRM_PRODUCT_DELETE_UNKNOWN_ERROR');
                    }
                }
            }
            if (isset($err[0])) {
                ShowError($err);
                $bVarsFromForm = true;
            } else {
                LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_PRODUCT_LIST'], array('section_id' => isset($arResult['LIST_SECTION_ID']) ? $arResult['LIST_SECTION_ID'] : 0)));
            }
        }
    }
}
Beispiel #3
0
 public static function Delete($ID)
 {
     if (!CModule::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;
 }
Beispiel #4
0
 protected function innerDelete($ID, &$errors)
 {
     if (!(CCrmProduct::CheckDeletePermission($ID) && CCrmProduct::EnsureDefaultCatalogScope($ID))) {
         $errors[] = 'Access denied.';
         return false;
     }
     $result = CCrmProduct::Delete($ID);
     if ($result !== true) {
         $errors[] = CCrmProduct::GetLastError();
     }
     return $result;
 }
Beispiel #5
0
     }
     if (!$actionData['AJAX_CALL']) {
         LocalRedirect($APPLICATION->GetCurPage());
     }
 } else {
     $errorMessage = '';
     if ($actionData['NAME'] == 'delete' && isset($actionData['ID']) && $arResult['CAN_DELETE']) {
         $sId = $actionData['ID'];
         $elementType = '';
         if (is_string($sId) && strlen($sId) > 2) {
             $elementType = $sId[0];
             $ID = intval(substr($sId, 1));
             $DB->StartTransaction();
             $result = true;
             if ($elementType === 'P') {
                 $result = CCrmProduct::Delete($ID);
             } else {
                 if ($elementType === 'S') {
                     $result = CCrmProductSection::Delete($ID) || CCrmProductSection::GetLastErrorCode() === CCrmProductSection::ERR_SECTION_NOT_FOUND;
                 }
             }
             if ($result) {
                 $DB->Commit();
             } else {
                 if ($errorMessage !== '') {
                     $errorMessage .= '<br />';
                 }
                 if ($elementType === 'P') {
                     $errorMessage .= CCrmProduct::GetLastError();
                 } else {
                     if ($elementType === 'S') {
Beispiel #6
0
 protected function innerDelete($ID, &$errors)
 {
     if (!CModule::IncludeModule('iblock')) {
         throw new RestException('Could not load iblock module.');
     }
     if (!(CCrmProduct::CheckDeletePermission($ID) && CCrmProduct::EnsureDefaultCatalogScope($ID))) {
         $errors[] = 'Access denied.';
         return false;
     }
     $result = CCrmProduct::Delete($ID);
     if ($result !== true) {
         $errors[] = CCrmProduct::GetLastError();
     }
     return $result;
 }