Browse Source

[Backend] Correctif newsletter

master
Guillaume 4 years ago
parent
commit
eb3a3a18ad
1 changed files with 29 additions and 28 deletions
  1. +29
    -28
      ShopBundle/Controller/Backend/NewsController.php

+ 29
- 28
ShopBundle/Controller/Backend/NewsController.php View File

@@ -67,43 +67,42 @@ class NewsController extends AdminController
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ;
$countUsers = count($users) ;
$toArray = [];
$messagesArray = [];

$paramsTemplate = [
'news' => $news,
'newsletter' => $newsletter,
'user' => $this->security->getUser()
] ;

foreach ($users as $user) {
$toArray[] = [
'Email' => $user->getEmail(),
'Name' => $user->getFirstname().' '.$user->getLastname(),
] ;
if($user->getEmail() && strlen($user->getEmail())) {
$messagesArray[] = [
'To' => [
[
'Email' => $user->getEmail(),
'Name' => $user->getFirstname().' '.$user->getLastname(),
]
],
'From' => [
'Email' => $this->getParameter('app.noreply_email'),
'Name' => $this->getParameter('app.site_name')
],
'Subject' => $currentMerchant->getMerchantConfig('email-subject-prefix').' '.$news->getTitle(),
'TextPart' => $this->renderView('mail/news-text.html.twig', $paramsTemplate),
'HTMLPart' => $this->renderView('mail/news-html.html.twig', $paramsTemplate),
'CustomCampaign' => $news->getTitle(),
'DeduplicateCampaign' => true
] ;
}
}

if($countUsers > 0) {

$mj = new \Mailjet\Client($this->mailjetTransport->getApiKey(), $this->mailjetTransport->getApiSecret(),true,['version' => 'v3.1']);

$paramsTemplate = [
'news' => $news,
'newsletter' => $newsletter,
'user' => $this->security->getUser()
] ;

$body = [
'Messages' => [
[
'From' => [
'Email' => $this->getParameter('app.noreply_email'),
'Name' => $this->getParameter('app.site_name')
],
'To' => $toArray,
'Subject' => $currentMerchant->getMerchantConfig('email-subject-prefix').' '.$news->getTitle(),
'TextPart' => $this->renderView('mail/news-text.html.twig', $paramsTemplate),
'HTMLPart' => $this->renderView('mail/news-html.html.twig', $paramsTemplate),
'CustomCampaign' => $news->getTitle(),
'DeduplicateCampaign' => true
]
]
'Messages' => $messagesArray
];


$response = $mj->post(Resources::$Email, ['body' => $body]);

if($response->success()) {
@@ -114,6 +113,8 @@ class NewsController extends AdminController
$this->em->flush() ;
}
else {
print_r($response->getBody()) ;
die() ;
$this->addFlash('error', "Une erreur est survenue lors de l'envoi de l'actualité.");
}
}

Loading…
Cancel
Save