public function actionDeleteImage($id, $languageId)
    {
        if (!empty($id)) {
            $image = ProductImage::find()->where(['id' => $id])->one();
            if (!empty($image)) {
                $product = Product::findOne($image->product_id);
                if (\Yii::$app->user->can('updateProduct', ['productOwner' => $product->owner])) {
                    $image->removeImage($id);

                    $this->trigger(self::EVENT_AFTER_EDIT_PRODUCT, new ProductEvent([
                        'id' => $image->product_id
                    ]));

                    return $this->redirect(['add-image', 'id' => $image->product_id, 'languageId' => $languageId]);

                } else throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to do this action.'));
            }
        } else throw new Exception();
    }
public function actionDeleteImage($id, $languageId)
    {
        if (!empty($id)) {
            $image = ProductImage::find()->where(['id' => $id])->one();
            if (!empty($image)) {
                $product = Product::findOne($image->product_id);
                if (\Yii::$app->user->can('updateProduct', ['productOwner' => $product->owner])) {
                    $image->removeImage($id);

                    $this->trigger(self::EVENT_AFTER_EDIT_PRODUCT, new ProductEvent([
                        'id' => $image->product_id
                    ]));

                    return $this->redirect(['add-image', 'id' => $image->product_id, 'languageId' => $languageId]);

                } else throw new ForbiddenHttpException(\Yii::t('shop', 'You have not permission to do this action.'));
            }
        } else throw new Exception();
    }
public function actionDeleteImage ( $ id , $ languageId ) { if ( ! empty ( $ id ) ) { $ image = ProductImage :: find ( ) -> where ( [ 'id' => $ id ] ) -> one ( ) ; if ( ! empty ( $ image ) ) { $ product = Product :: findOne ( $ image -> product_id ) ; if ( \ Yii :: $ app -> user -> can ( 'updateProduct' , [ 'productOwner' => $ product -> owner ] ) ) { $ image -> removeImage ( $ id ) ; $ this -> trigger ( self :: EVENT_AFTER_EDIT_PRODUCT , new ProductEvent ( [ 'id' => $ image -> product_id ] ) ) ; return $ this -> redirect ( [ 'add-image' , 'id' => $ image -> product_id , 'languageId' => $ languageId ] ) ; } else throw new ForbiddenHttpException ( \ Yii :: t ( 'shop' , 'You have not permission to do this action.' ) ) ; } } else throw new Exception ( ) ; }
Users which have 'updateOwnProduct' permission can delete image only from Product models that have been created by their.
Users which have 'updateProduct' permission can delete image from all Product models.

@param integer $id
@param integer $languageId
@return mixed
@throws ForbiddenHttpException
@throws Exception
Users which have updateOwnProduct permission can delete image only from Product models that have been created by their . Users which have updateProduct permission can delete image from all Product models .