Пример #1
0
 public function actionDeleteProduct()
 {
     $errors = array();
     if (!isset($_GET['value'])) {
         $errors[] = 'A product ID must be supplied';
     } else {
         if (!is_numeric($_GET['value'])) {
             $errors[] = "Provided product ID must be an integer";
         } else {
             if ($product = product::model()->getbyPK($_GET['value'])) {
                 if ($product->delete()) {
                     $data = array();
                 } else {
                     $errors[] = 'Could not delete the product';
                 }
             } else {
                 $errors[] = 'Could not find product with ID of ' . $_GET['value'];
             }
         }
     }
     if (count($errors) > 0) {
         $this->renderApi(false, null, $errors);
     } else {
         $this->renderApi(true, $data);
     }
 }
 public function actionDeleteAll($id)
 {
     $arrIdNew = explode(",", $id);
     for ($i = 0; $i < count($arrIdNew); $i++) {
         // Delete all news of category new
         $model = $this->loadModel($arrIdNew[$i]);
         if (!empty($model)) {
             $criteria = new CDBCriteria();
             $criteria->addCondition("product_category_id = {$arrIdNew[$i]}");
             $criteria->select = "id";
             $arrProduct = Product::model()->findALl($criteria);
             foreach ($arrProduct as $product) {
                 $modelProduct = product::model()->find($product->id);
                 // delete all images
                 if (!empty($modelProduct)) {
                     $criteria = new CDBCriteria();
                     $criteria->addCondition("product_id = {$modelProduct->id}");
                     $criteria->select = "id";
                     $arrImage = ProductImage::model()->findALl($criteria);
                     foreach ($arrImage as $ProductImage) {
                         $modelImage = ProductImage::model()->find($ProductImage->id);
                         $path = "/../upload/images/";
                         $name = $modelImage->image;
                         $this->unlink($path, $name);
                         $modelImage->delete();
                     }
                 }
                 $modelProduct->delete();
             }
         }
         // Delete category new
         $model->delete();
     }
     if (!isset($_GET['ajax'])) {
         $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
     }
 }