@@ -108,7 +108,7 @@ class SiteController extends BackendController | |||
/** | |||
* Affiche le tableau de bord du backend avec les dernières commandes | |||
* réalisée, les dernières inscriptions, la liste des clients ayant un crédit | |||
* réalisées, les dernières inscriptions, la liste des clients ayant un crédit | |||
* négatif etc. | |||
* | |||
* @return mixed | |||
@@ -137,7 +137,6 @@ class SiteController extends BackendController | |||
$queryDistributions->andWhere(['>=', 'distribution.date', date('Y-m-d')]); | |||
} | |||
$distributionsArray = $queryDistributions->andWhere([ | |||
'distribution.id_producer' => GlobalParam::getCurrentProducerId(), | |||
'distribution.active' => 1 |
@@ -218,20 +218,17 @@ class UserController extends BackendController | |||
$producer = $this->getProducerCurrent(); | |||
Mailjet::sendMail([ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $model->email, | |||
'to_name' => $userManager->getUsername($user), | |||
'subject' => '[' . $producer->name . '] Nouveau mot de passe', | |||
'content_view_text' => '@common/mail/newPasswordUserAdmin-text.php', | |||
'content_view_html' => '@common/mail/newPasswordUserAdmin-html.php', | |||
'content_params' => [ | |||
\Yii::$app->mailerService->sendFromProducer( | |||
'Nouveau mot de passe', | |||
'newPasswordUserAdmin', | |||
[ | |||
'user' => $user, | |||
'producer' => $producer, | |||
'password' => $password, | |||
] | |||
]); | |||
], | |||
$model->email, | |||
$producer | |||
); | |||
$this->setFlash('success', 'Nouveau mot de passe envoyé à <strong>'.Html::encode($userManager->getUsername($model)).'</strong>.'); | |||
@@ -117,23 +117,18 @@ class CreditForm extends Model | |||
$producer = GlobalParam::getCurrentProducer() ; | |||
$userProducer = $userProducerManager->findOneUserProducer($user); | |||
$paramsEmail = [ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $user->email, | |||
'to_name' => $userManager->getUsername($user), | |||
'subject' => '['.$producer->name.'] Mouvement de crédit', | |||
'content_view_text' => '@common/mail/creditUser-text.php', | |||
'content_view_html' => '@common/mail/creditUser-html.php', | |||
'content_params' => [ | |||
'user' => $user, | |||
'producer' => $producer, | |||
'userProducer' => $userProducer, | |||
'creditForm' => $this | |||
] | |||
] ; | |||
Mailjet::sendMail($paramsEmail); | |||
\Yii::$app->mailerService->sendFromProducer( | |||
'Mouvement de crédit', | |||
'creditUser', | |||
[ | |||
'user' => $user, | |||
'producer' => $producer, | |||
'userProducer' => $userProducer, | |||
'creditForm' => $this | |||
], | |||
$user->email, | |||
$producer | |||
); | |||
} | |||
} | |||
} |
@@ -0,0 +1,64 @@ | |||
<?php | |||
namespace common\components; | |||
use common\logic\Producer\Producer\Model\Producer; | |||
use yii\mail\MessageInterface; | |||
class MailerService | |||
{ | |||
public function sendFromProducer(string $subject, string $view, array $params, string $toEmail, Producer $producer) | |||
{ | |||
$message = $this->composeBase($toEmail, $view, $params); | |||
$this->initMessageFromProducer($message, $subject, $producer); | |||
$message->send(); | |||
} | |||
public function sendFromSite(string $subject, string $view, array $params, string $toEmail) | |||
{ | |||
$message = $this->composeBase($toEmail, $view, $params); | |||
$this->initMessageFromSite($message, $subject); | |||
$message->send(); | |||
} | |||
public function sendAdmin(string $subject, string $view, array $params = []) | |||
{ | |||
$message = $this->composeBase(\Yii::$app->params['adminEmail'], $view, $params); | |||
$this->initMessageFromSite($message, $subject); | |||
$message->send(); | |||
} | |||
private function composeBase(string $toEmail, string $view, array $params = []) | |||
{ | |||
return \Yii::$app->mailer | |||
->compose([ | |||
'html' => '@common/mail/'.$view.'-html.php', | |||
'text' => '@common/mail/'.$view.'-text.php' | |||
], $params) | |||
->setTo($toEmail); | |||
} | |||
private function initMessageFromSite(MessageInterface $message, string $subject) | |||
{ | |||
$message->setFrom([\Yii::$app->params['adminEmail'] => \Yii::$app->params['siteName']]); | |||
$message->setSubject($this->buildSubject(\Yii::$app->params['siteName'], $subject)); | |||
return $message; | |||
} | |||
private function initMessageFromProducer(MessageInterface $message, string $subject, Producer $producer) | |||
{ | |||
$message->setFrom([$this->getEmailOpendistrib($producer) => $producer->name]); | |||
$message->setSubject($this->buildSubject($producer->name, $subject)); | |||
return $message; | |||
} | |||
private function getEmailOpendistrib(Producer $producer): string | |||
{ | |||
return $producer->slug . '@opendistrib.net'; | |||
} | |||
private function buildSubject(string $prefix, string $subject) | |||
{ | |||
return '['.$prefix.'] '.$subject; | |||
} | |||
} |
@@ -88,6 +88,9 @@ return [ | |||
'class' => 'yii\image\ImageDriver', | |||
'driver' => 'GD', //GD or Imagick | |||
], | |||
'mailerService' => [ | |||
'class' => 'common\components\MailerService' | |||
], | |||
'urlManagerProducer' => [ | |||
'class' => 'producer\components\UrlManagerProducer', | |||
'subDomain' => Yii::getAlias('@producerSubdomain'), |
@@ -38,6 +38,7 @@ | |||
return [ | |||
'version' => '23.8.B', | |||
'siteName' => 'Opendistrib', | |||
'adminEmail' => 'contact@opendistrib.net', | |||
'supportEmail' => 'contact@opendistrib.net', | |||
'user.passwordResetTokenExpire' => 3600, | |||
@@ -93,5 +94,4 @@ return [ | |||
] | |||
] | |||
]; |
@@ -59,6 +59,9 @@ class ProducerSolver extends AbstractService implements SolverInterface | |||
return \Yii::$app->urlManagerProducer->getHostInfo() . '/' . \Yii::$app->urlManagerProducer->baseUrl . '/uploads/' . $producer->logo; | |||
} | |||
/** | |||
* @deprecated Déplacé dans MailerService | |||
*/ | |||
public function getEmailOpendistrib(Producer $producer): string | |||
{ | |||
return $producer->slug . '@opendistrib.net'; |
@@ -21,19 +21,15 @@ class UserUtils extends AbstractService implements UtilsInterface | |||
public function sendEmailSignup(User $user, Producer $producer) | |||
{ | |||
Mailjet::sendMail([ | |||
'from_email' => \Yii::$app->params['adminEmail'], | |||
'from_name' => 'Opendistrib', | |||
'to_email' => $user->email, | |||
'to_name' => $this->userSolver->getUsername($user), | |||
'subject' => '[Opendistrib] Inscription', | |||
'content_view_text' => '@common/mail/signup-text.php', | |||
'content_view_html' => '@common/mail/signup-html.php', | |||
'content_params' => [ | |||
\Yii::$app->mailerService->sendFromSite( | |||
'Inscription', | |||
'signup', | |||
[ | |||
'user' => $user, | |||
'producer' => $producer | |||
] | |||
]); | |||
], | |||
$user->email | |||
); | |||
} | |||
/** | |||
@@ -44,32 +40,28 @@ class UserUtils extends AbstractService implements UtilsInterface | |||
{ | |||
if (strlen($user->email)) { | |||
$producer = Producer::findOne(GlobalParam::getCurrentProducerId()); | |||
\Yii::$app->mailer->compose(); | |||
$mail = \Yii::$app->mailer->compose( | |||
['html' => 'createUserAdmin-html', 'text' => 'createUserAdmin-text'], ['user' => $user, 'producer' => $producer, 'password' => $password] | |||
) | |||
->setTo($user->email) | |||
->setFrom(['contact@opendistrib.net' => 'distrib']) | |||
->setSubject('[Opendistrib] Inscription') | |||
->send(); | |||
\Yii::$app->mailerService->sendFromProducer( | |||
'Inscription', | |||
'createUserAdmin', | |||
[ | |||
'user' => $user, | |||
'producer' => $producer, | |||
'password' => $password | |||
], | |||
$user->email, | |||
$producer | |||
); | |||
} | |||
} | |||
public function sendMailNewTicketAdmin(Ticket $ticket) | |||
{ | |||
$adminEmail = \Yii::$app->params['adminEmail']; | |||
Mailjet::sendMail([ | |||
'from_email' => $adminEmail, | |||
'from_name' => 'Opendistrib', | |||
'to_email' => $adminEmail, | |||
'to_name' => 'Opendistrib', | |||
'subject' => '[Opendistrib] Nouveau ticket', | |||
'content_view_text' => '@common/mail/newTicketAdmin-text.php', | |||
'content_view_html' => '@common/mail/newTicketAdmin-html.php', | |||
'content_params' => [ | |||
\Yii::$app->mailerService->sendAdmin( | |||
'Nouveau ticket', | |||
'newTicketAdmin', | |||
[ | |||
'ticket' => $ticket, | |||
] | |||
]); | |||
); | |||
} | |||
} |
@@ -33,7 +33,8 @@ | |||
"stripe/stripe-php": "^7.95", | |||
"loveorigami/yii2-bootstrap-toggle": "*", | |||
"justcoded/yii2-event-listener": "*", | |||
"ext-pdo": "*" | |||
"ext-pdo": "*", | |||
"weluse/yii2-mailjet": "^0.2.0" | |||
}, | |||
"require-dev": { | |||
"yiisoft/yii2-codeception": "*", |
@@ -4,7 +4,7 @@ | |||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", | |||
"This file is @generated automatically" | |||
], | |||
"content-hash": "7da17be4685def1e9635cc5ab5e5a7d9", | |||
"content-hash": "cf81ea895f037844a4e20f4780fd7e7e", | |||
"packages": [ | |||
{ | |||
"name": "2amigos/yii2-chartjs-widget", | |||
@@ -2464,6 +2464,40 @@ | |||
], | |||
"time": "2022-11-03T14:55:06+00:00" | |||
}, | |||
{ | |||
"name": "weluse/yii2-mailjet", | |||
"version": "v0.2.0", | |||
"source": { | |||
"type": "git", | |||
"url": "https://github.com/weluse/yii2-mailjet.git", | |||
"reference": "ec68afa94a5f9cef2b1ed6197b733b7a9fa8f601" | |||
}, | |||
"dist": { | |||
"type": "zip", | |||
"url": "https://api.github.com/repos/weluse/yii2-mailjet/zipball/ec68afa94a5f9cef2b1ed6197b733b7a9fa8f601", | |||
"reference": "ec68afa94a5f9cef2b1ed6197b733b7a9fa8f601", | |||
"shasum": "" | |||
}, | |||
"require": { | |||
"mailjet/mailjet-apiv3-php": "^1.1.5" | |||
}, | |||
"type": "library", | |||
"autoload": { | |||
"psr-4": { | |||
"weluse\\mailjet\\": "" | |||
} | |||
}, | |||
"notification-url": "https://packagist.org/downloads/", | |||
"license": [ | |||
"MIT" | |||
], | |||
"description": "Mailjet client", | |||
"support": { | |||
"issues": "https://github.com/weluse/yii2-mailjet/issues", | |||
"source": "https://github.com/weluse/yii2-mailjet/tree/v0.2.0" | |||
}, | |||
"time": "2019-06-19T21:18:00+00:00" | |||
}, | |||
{ | |||
"name": "yidas/yii2-bower-asset", | |||
"version": "2.0.13.1", |
@@ -241,58 +241,48 @@ class CreditController extends ProducerBaseController | |||
$creditHistoryManager->payOrder($order, $user, true); | |||
// client : envoi d'un email de confirmation de paiement | |||
$paramsEmail = [ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $user->email, | |||
'to_name' => $userManager->getUsername($user), | |||
'subject' => '[' . $producer->name . '] Confirmation de paiement', | |||
'content_view_text' => '@common/mail/paymentOrderConfirm-text.php', | |||
'content_view_html' => '@common/mail/paymentOrderConfirm-html.php', | |||
'content_params' => [ | |||
/*\Yii::$app->mailerService->sendFromProducer( | |||
'Confirmation de commande', | |||
'paymentOrderConfirm', | |||
[ | |||
'amount' => $amount, | |||
'user' => $user, | |||
'producer' => $producer, | |||
] | |||
]; | |||
//Mailjet::sendMail($paramsEmail); | |||
], | |||
$user->email, | |||
$producer | |||
);*/ | |||
// producteur : mail de confirmation | |||
Mailjet::sendMail([ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $contactProducer->email, | |||
'to_name' => $contactProducer->name, | |||
'subject' => '[' . $producer->name . '] Confirmation de commande', | |||
'content_view_text' => '@common/mail/orderConfirmProducer-text.php', | |||
'content_view_html' => '@common/mail/orderConfirmProducer-html.php', | |||
'content_params' => [ | |||
\Yii::$app->mailerService->sendFromSite( | |||
'Confirmation de commande', | |||
'orderConfirmProducer', | |||
[ | |||
'order' => $order, | |||
'pointSale' => $pointSale, | |||
'distribution' => $distribution, | |||
'user' => $user, | |||
'producer' => $producer | |||
] | |||
]); | |||
], | |||
$contactProducer->email | |||
); | |||
} else { | |||
$userProducer = $this->getUserProducerManager()->findOneUserProducer($user); | |||
Mailjet::sendMail([ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $user->email, | |||
'to_name' => $userManager->getUsername($user), | |||
'subject' => '[' . $producer->name . '] Alimentation de votre crédit', | |||
'content_view_text' => '@common/mail/creditConfirm-text.php', | |||
'content_view_html' => '@common/mail/creditConfirm-html.php', | |||
'content_params' => [ | |||
\Yii::$app->mailerService->sendFromProducer( | |||
'Alimentation de votre crédit', | |||
'creditConfirm', | |||
[ | |||
'user' => $user, | |||
'userProducer' => $userProducer, | |||
'producer' => $producer, | |||
'amount' => $amount, | |||
] | |||
]); | |||
], | |||
$user->email, | |||
$producer | |||
); | |||
} | |||
} | |||
@@ -301,39 +291,32 @@ class CreditController extends ProducerBaseController | |||
case 'charge.failed': | |||
// client | |||
Mailjet::sendMail([ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $user->email, | |||
'to_name' => $userManager->getUsername($user), | |||
'subject' => '[' . $producer->name . '] Erreur de paiement', | |||
'content_view_text' => '@common/mail/paymentError-text.php', | |||
'content_view_html' => '@common/mail/paymentError-html.php', | |||
'content_params' => [ | |||
\Yii::$app->mailerService->sendFromProducer( | |||
'Erreur de paiement', | |||
'paymentError', | |||
[ | |||
'amount' => $amount, | |||
'user' => $user, | |||
'producer' => $producer, | |||
] | |||
]); | |||
], | |||
$user->email, | |||
$producer | |||
); | |||
// producteur | |||
if (isset($order) && $order) { | |||
Mailjet::sendMail([ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $contactProducer->email, | |||
'to_name' => $contactProducer->name, | |||
'subject' => '[' . $producer->name . '] Erreur de paiement', | |||
'content_view_text' => '@common/mail/paymentErrorProducer-text.php', | |||
'content_view_html' => '@common/mail/paymentErrorProducer-html.php', | |||
'content_params' => [ | |||
\Yii::$app->mailerService->sendFromSite( | |||
'Erreur de paiement', | |||
'paymentErrorProducer', | |||
[ | |||
'amount' => $amount, | |||
'user' => $user, | |||
'producer' => $producer, | |||
'order' => $order, | |||
'distribution' => $distribution | |||
] | |||
]); | |||
], | |||
$contactProducer->email, | |||
); | |||
} | |||
break; |
@@ -462,30 +462,30 @@ class OrderController extends ProducerBaseController | |||
} | |||
} | |||
$paramsEmail = [ | |||
'from_email' => $producerManager->getEmailOpendistrib($producer), | |||
'from_name' => $producer->name, | |||
'to_email' => $user->email, | |||
'to_name' => $userManager->getUsername($user), | |||
'subject' => '[' . $producer->name . '] Confirmation de commande', | |||
'content_view_text' => '@common/mail/orderConfirm-text.php', | |||
'content_view_html' => '@common/mail/orderConfirm-html.php', | |||
'content_params' => [ | |||
/* | |||
* Envoi email de confirmation | |||
*/ | |||
if ($isNewOrder) { | |||
$emailSubject = 'Confirmation de commande'; | |||
$emailContentParams = [ | |||
'order' => $order, | |||
'pointSale' => $pointSale, | |||
'distribution' => $distribution, | |||
'user' => $user, | |||
'producer' => $producer | |||
] | |||
]; | |||
]; | |||
/* | |||
* Envoi email de confirmation | |||
*/ | |||
if ($isNewOrder) { | |||
// au client | |||
if ($producerManager->getConfig('option_email_confirm')) { | |||
Mailjet::sendMail($paramsEmail); | |||
\Yii::$app->mailerService->sendFromProducer( | |||
$emailSubject, | |||
'orderConfirm', | |||
$emailContentParams, | |||
$user->email, | |||
$producer | |||
); | |||
} | |||
// au producteur | |||
@@ -493,11 +493,13 @@ class OrderController extends ProducerBaseController | |||
if ($producerManager->getConfig('option_email_confirm_producer') && $contactProducer && strlen( | |||
$contactProducer->email | |||
)) { | |||
$paramsEmail['to_email'] = $contactProducer->email; | |||
$paramsEmail['to_name'] = $contactProducer->name; | |||
$paramsEmail['content_view_text'] = '@common/mail/orderConfirmProducer-text.php'; | |||
$paramsEmail['content_view_html'] = '@common/mail/orderConfirmProducer-html.php'; | |||
Mailjet::sendMail($paramsEmail); | |||
\Yii::$app->mailerService->sendFromSite( | |||
$emailSubject, | |||
'orderConfirmProducer', | |||
$emailContentParams, | |||
$contactProducer->email | |||
); | |||
} | |||
} | |||