Browse Source

[backend] Demande de confirmation avant la suppression d'un produit

refactoring
Guillaume Bourgeois 5 years ago
parent
commit
b8e94ec418
1 changed files with 11 additions and 5 deletions
  1. +11
    -5
      backend/controllers/ProductController.php

+ 11
- 5
backend/controllers/ProductController.php View File

@@ -174,13 +174,19 @@ class ProductController extends BackendController
* @param integer $id
* @return mixed
*/
public function actionDelete($id)
public function actionDelete($id, $confirm = false)
{
$model = $this->findModel($id) ;
$model->delete();
ProductDistribution::deleteAll(['id_product' => $id]) ;
$product = $this->findModel($id) ;
Yii::$app->getSession()->setFlash('success', 'Produit <strong>'.Html::encode($model->name).'</strong> supprimé');
if($confirm) {
$product->delete();
ProductDistribution::deleteAll(['id_product' => $id]) ;
Yii::$app->getSession()->setFlash('success', 'Produit <strong>'.Html::encode($product->name).'</strong> supprimé');
}
else {
Yii::$app->getSession()->setFlash('info', 'Souhaitez-vous vraiment supprimer le produit <strong>'.Html::encode($product->name).'</strong> ? '
. Html::a('Oui',['product/delete','id' => $id, 'confirm' => 1], ['class' => 'btn btn-default']).' '.Html::a('Non', ['product/index'], ['class' => 'btn btn-default']));
}
return $this->redirect(['index']);
}

Loading…
Cancel
Save