modules/api/v1/controllers/ProductController.php
/**
     * Deletes an existing Product model.
     * If deletion is successful, the browser will be redirected to the 'index' page.
     * @param integer $id
     * @return mixed
     * @throws NotFoundHttpException if the model cannot be found
     */
Deletes an existing Product model.
If deletion is successful, the browser will be redirected to the 'index' page.
@param integer $id
@return mixed
@throws NotFoundHttpException if the model cannot be found
Deletes an existing Product model . If deletion is successful the browser will be redirected to the ' index ' page . @param integer $id @return mixed @throws NotFoundHttpException if the model cannot be found
public function actionDelete($id)
    {
        $model = Product::findOne($id);
        if (!$model instanceof Product) {
            throw new NotFoundHttpException('Product doesn\'t exist.');
        }
        if (!empty($model) && !empty($model->productImages)) {
            foreach ($model->productImages as $key => $imageRow) {
                if ($imageRow instanceof ProductImage) {
                    if (!empty($imageRow->name) && file_exists(Yii::getAlias('@productImageRelativePath') . "/" . $imageRow->name)) {
                        unlink(Yii::getAlias('@productImageRelativePath') . "/" . $imageRow->name);
                    }
                    if (!empty($imageRow->name) && file_exists(Yii::getAlias('@productImageThumbRelativePath') . "/" . $imageRow->name)) {
                        unlink(Yii::getAlias('@productImageThumbRelativePath') . "/" . $imageRow->name);
                    }
                    $imageRow->delete();
                }
            }
        }
        $model->delete();
    }
public function actionDelete ( $ id ) { $ model = Product :: findOne ( $ id ) ; if ( ! $ model instanceof Product ) { throw new NotFoundHttpException ( 'Product doesn\'t exist.' ) ; } if ( ! empty ( $ model ) && ! empty ( $ model -> productImages ) ) { foreach ( $ model -> productImages as $ key => $ imageRow ) { if ( $ imageRow instanceof ProductImage ) { if ( ! empty ( $ imageRow -> name ) && file_exists ( Yii :: getAlias ( '@productImageRelativePath' ) . " / " . $ imageRow -> name ) ) { unlink ( Yii :: getAlias ( '@productImageRelativePath' ) . " / " . $ imageRow -> name ) ; } if ( ! empty ( $ imageRow -> name ) && file_exists ( Yii :: getAlias ( '@productImageThumbRelativePath' ) . " / " . $ imageRow -> name ) ) { unlink ( Yii :: getAlias ( '@productImageThumbRelativePath' ) . " / " . $ imageRow -> name ) ; } $ imageRow -> delete ( ) ; } } } $ model -> delete ( ) ; }
Deletes an existing Product model.
Deletes an existing Product model .