/** * 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) { if ($model = $this->findModel($id)) { foreach (ProductTranslation::findAll(['product_id' => $model->id]) as $item) { $item->delete(); } foreach (ProductImage::findAll(['product_id' => $model->id]) as $item) { $item->delete(); } foreach (ProductCategoryToProduct::findAll(['product_id' => $model->id]) as $item) { $item->delete(); } foreach (ProductCollectionToProduct::findAll(['product_id' => $model->id]) as $item) { $item->delete(); } $model->delete(); return $this->goBack(Url::previous()); } else { throw new NotFoundHttpException(); } }