Browse Source

[Administration] Utilisateurs > Crédit : problème envoi mail lors de l'ajout de crédit si email vide #1257

feature/souke
Guillaume Bourgeois 1 year ago
parent
commit
6aa9b0575b
2 changed files with 27 additions and 18 deletions
  1. +5
    -2
      backend/controllers/UserController.php
  2. +22
    -16
      common/logic/Payment/Service/PaymentNotifier.php

+ 5
- 2
backend/controllers/UserController.php View File

if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) { if ($creditForm->load(\Yii::$app->request->post()) && $creditForm->validate()) {


$paymentContainer->getUtils() $paymentContainer->getUtils()
->creditOrDebitUser($creditForm->type, $user, $creditForm->amount, $creditForm->mean_payment, $user);
->creditOrDebitUser($creditForm->type, $user, $creditForm->amount, $creditForm->mean_payment, $this->getUserCurrent());


if($creditForm->send_mail) { if($creditForm->send_mail) {
$paymentContainer->getNotifier() $paymentContainer->getNotifier()
->notifyUserCreditMovement($user, $creditForm->type, $creditForm->amount); ->notifyUserCreditMovement($user, $creditForm->type, $creditForm->amount);
if(!$user->email) {
$this->addFlash('error', "L'utilisateur n'a pas pu être prévenu car son adresse email n'est pas définie.");
}
} }


$this->setFlash('success', 'Crédit mis à jour.');
$this->addFlash('success', 'Crédit mis à jour.');


return $this->refresh(); return $this->refresh();
} }

+ 22
- 16
common/logic/Payment/Service/PaymentNotifier.php View File



public function notifyUserCreditMovement(User $user, string $type, float $amount) public function notifyUserCreditMovement(User $user, string $type, float $amount)
{ {
$producer = $this->getProducerContext();
$credit = $this->userRepository->getCredit($user, true);

$this->mailer->sendFromProducer(
'Mouvement de crédit',
'creditUser',
[
'user' => $user,
'producer' => $producer,
'credit' => $credit,
'type' => $type,
'amount' => $amount
],
$user->email,
$producer
);
if($user->email) {
$producer = $this->getProducerContext();
$credit = $this->userRepository->getCredit($user, true);

$this->mailer->sendFromProducer(
'Mouvement de crédit',
'creditUser',
[
'user' => $user,
'producer' => $producer,
'credit' => $credit,
'type' => $type,
'amount' => $amount
],
$user->email,
$producer
);

return true;
}

return false;
} }
} }

Loading…
Cancel
Save