modules/admin/controllers/ProductCategoryController.php
/**
     * Deletes an existing ProductCategory model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
Deletes an existing ProductCategory model.
If deletion is successful, the browser will be redirected to the 'index' page.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
Deletes an existing ProductCategory model . If deletion is successful the browser will be redirected to the ' index ' page . @param integer $id @return mixed @throws NotFoundHttpException if the model cannot be found
public function actionDelete($id)
    {
        $model = $this->findModel($id);
        $modelReference = $model;
        $image = $model->image;
        $uploadDirPath = Yii::getAlias('@productCategoryImageRelativePath');
        $uploadThumbDirPath = Yii::getAlias('@productCategoryImageThumbRelativePath');
        if (file_exists($uploadDirPath . '/' . $image) && !empty($image)) {
            unlink($uploadDirPath . '/' . $image);
        }
        if (file_exists($uploadThumbDirPath . '/' . $image) && !empty($image)) {
            unlink($uploadThumbDirPath . '/' . $image);
        }
        if ($model->delete()) {
            if (!empty($modelReference) && $modelReference instanceof ProductCategory) {
                if (empty($modelReference->parent_category_id)) {
                    $subCategories = $modelReference->children;
                    if (!empty($subCategories)) {
                        foreach ($subCategories as $key => $subCategoriesRow) {
                            if (!empty($subCategoriesRow) && $subCategoriesRow instanceof ProductCategory) {
                                $subCategoriesRow->delete();
                            }
                        }
                    }
                }
                $categoryProducts = $modelReference->products;
                if (!empty($categoryProducts)) {
                    foreach ($categoryProducts as $keys => $categoryProductsRow) {
                        if (!empty($categoryProductsRow) && $categoryProductsRow instanceof Product) {
                            $categoryProductsRow->delete();
                        }
                    }
                }
            }
            Yii::$app->session->setFlash(Growl::TYPE_SUCCESS, "Category/Subcategory deleted successfully.");
        } else {
            Yii::$app->session->setFlash(Growl::TYPE_DANGER, "Error while deleting Category/Subcategory.");
        }
        return $this->redirect(['index']);
    }
public function actionDelete ( $ id ) { $ model = $ this -> findModel ( $ id ) ; $ modelReference = $ model ; $ image = $ model -> image ; $ uploadDirPath = Yii :: getAlias ( '@productCategoryImageRelativePath' ) ; $ uploadThumbDirPath = Yii :: getAlias ( '@productCategoryImageThumbRelativePath' ) ; if ( file_exists ( $ uploadDirPath . '/' . $ image ) && ! empty ( $ image ) ) { unlink ( $ uploadDirPath . '/' . $ image ) ; } if ( file_exists ( $ uploadThumbDirPath . '/' . $ image ) && ! empty ( $ image ) ) { unlink ( $ uploadThumbDirPath . '/' . $ image ) ; } if ( $ model -> delete ( ) ) { if ( ! empty ( $ modelReference ) && $ modelReference instanceof ProductCategory ) { if ( empty ( $ modelReference -> parent_category_id ) ) { $ subCategories = $ modelReference -> children ; if ( ! empty ( $ subCategories ) ) { foreach ( $ subCategories as $ key => $ subCategoriesRow ) { if ( ! empty ( $ subCategoriesRow ) && $ subCategoriesRow instanceof ProductCategory ) { $ subCategoriesRow -> delete ( ) ; } } } } $ categoryProducts = $ modelReference -> products ; if ( ! empty ( $ categoryProducts ) ) { foreach ( $ categoryProducts as $ keys => $ categoryProductsRow ) { if ( ! empty ( $ categoryProductsRow ) && $ categoryProductsRow instanceof Product ) { $ categoryProductsRow -> delete ( ) ; } } } } Yii :: $ app -> session -> setFlash ( Growl :: TYPE_SUCCESS , " Category/Subcategory deleted successfully. " ) ; } else { Yii :: $ app -> session -> setFlash ( Growl :: TYPE_DANGER , " Error while deleting Category/Subcategory. " ) ; } return $ this -> redirect ( [ 'index' ] ) ; }
Deletes an existing ProductCategory model.
Deletes an existing ProductCategory model .
// unlink images with thumb // Delete sub category // Delete Product