Example #1
0
 public function getproduct_files()
 {
     return $this->hasMany(ProductFiles::className(), ['product_id' => 'id']);
 }
 /**
  * Deletes an existing Product model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     ProductCategoryRel::deleteAll(['product_id' => $id]);
     $images = ProductImageRel::findAll(['product_id' => $id]);
     if (!empty($images)) {
         foreach ($images as $key => $value) {
             unlink(\Yii::getAlias('@webroot') . '/product_uploads/' . $value->image);
         }
     }
     ProductImageRel::deleteAll(['product_id' => $id]);
     $files = ProductFiles::findAll(['product_id' => $id]);
     if (!empty($files)) {
         foreach ($files as $key => $value) {
             unlink(\Yii::getAlias('@webroot') . '/product_files/' . $value->file_name);
         }
     }
     ProductFiles::deleteAll(['product_id' => $id]);
     ProductSpecification::deleteAll(['product_id' => $id]);
     $this->findModel($id)->delete();
     return $this->redirect(['index']);
 }