/** * Deletes product model. * * Users which have 'deleteProduct' permission can delete all Product models. * Users which have 'deleteOwnProduct' permission can delete only Product models that have been created by their. * * @param integer $id * @return mixed * @throws ForbiddenHttpException */ public function actionDelete($id) { if (\Yii::$app->user->can('deleteProduct', ['productOwner' => Product::findOne($id)->owner])) { $this->trigger(self::EVENT_BEFORE_DELETE_PRODUCT, new ProductEvent(['productId' => $id, 'userId' => Yii::$app->user->id])); Product::deleteAll(['id' => $id]); $this->trigger(self::EVENT_AFTER_DELETE_PRODUCT, new ProductEvent(['productId' => $id, 'userId' => Yii::$app->user->id])); return $this->redirect('index'); } else { throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to delete this product.')); } }