Browse Source

Merge branch 'develop' of https://gitea.laclic.fr/Laclic/LcShopBundle into develop

feature/export_comptable
Fab 4 years ago
parent
commit
6b6f133f2e
6 changed files with 57 additions and 42 deletions
  1. +47
    -33
      ShopBundle/Controller/Backend/NewsController.php
  2. +1
    -1
      ShopBundle/Model/MerchantConfig.php
  3. +1
    -1
      ShopBundle/Resources/public/js/backend/script/supplier/vuejs-supplier.js
  4. +1
    -1
      ShopBundle/Resources/views/backend/default/block/form_address.html.twig
  5. +0
    -3
      ShopBundle/Resources/views/backend/supplier/panel_general.html.twig
  6. +7
    -3
      ShopBundle/Services/CsvGenerator.php

+ 47
- 33
ShopBundle/Controller/Backend/NewsController.php View File



public function sendAction() public function sendAction()
{ {
ini_set('memory_limit', '-1');

$currentMerchant = $this->merchantUtils->getMerchantCurrent() ; $currentMerchant = $this->merchantUtils->getMerchantCurrent() ;
$newsletter = $this->getNewsletter() ; $newsletter = $this->getNewsletter() ;
$news = $this->getNews() ; $news = $this->getNews() ;
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; $users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ;
$countUsers = count($users) ; $countUsers = count($users) ;
$toArray = [];


$packageMessagesArray = [];
$packageMessageLimit = 50 ;

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

$i = 0 ;
foreach ($users as $user) { foreach ($users as $user) {
$toArray[] = [
'Email' => $user->getEmail(),
'Name' => $user->getFirstname().' '.$user->getLastname(),
] ;
if(!isset($packageMessagesArray[$i])) {
$packageMessagesArray[$i] = [] ;
}

if($user->getEmail() && strlen($user->getEmail())) {
$packageMessagesArray[$i][] = [
'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(count($packageMessagesArray[$i]) >= $packageMessageLimit) {
$i ++ ;
}
}
} }


if($countUsers > 0) { if($countUsers > 0) {

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


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

if($response->success()) {
foreach($packageMessagesArray as $messagesArray) {
$body = [
'Messages' => $messagesArray
];
$response = $mj->post(Resources::$Email, ['body' => $body]);
}

if(isset($response) && $response->success()) {
$this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.'); $this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.');


$news->setIsSent(true) ; $news->setIsSent(true) ;

+ 1
- 1
ShopBundle/Model/MerchantConfig.php View File

return $this->value; return $this->value;
} }


public function setValue(string $value): self
public function setValue($value): self
{ {
$this->value = $value; $this->value = $value;



+ 1
- 1
ShopBundle/Resources/public/js/backend/script/supplier/vuejs-supplier.js View File

nameDisplay: 'SEO' nameDisplay: 'SEO'
} }
] ]
});
}, window.addressValues);
}, },
mounted: function () {}, mounted: function () {},
methods: { methods: {

+ 1
- 1
ShopBundle/Resources/views/backend/default/block/form_address.html.twig View File

<div id="lc-user-address" class="row"> <div id="lc-user-address" class="row">
<script> <script>
window.addressValues = { window.addressValues = {
{% if form.type.vars.value %}addressType: "{{ form.type.vars.value }}",{% endif %}
{% if form.type.vars.value %}addressType: '{{ form.type.vars.value }}'{% endif %}
}; };
</script> </script>



+ 0
- 3
ShopBundle/Resources/views/backend/supplier/panel_general.html.twig View File

<div class="col-12"> <div class="col-12">
{{ form_row(form.description) }} {{ form_row(form.description) }}
</div> </div>
<div class="col-12">
{{ form_row(form.user) }}
</div>
{{ macros.card_end() }} {{ macros.card_end() }}
</div> </div>
</div> </div>

+ 7
- 3
ShopBundle/Services/CsvGenerator.php View File



public function encodeArray($array) public function encodeArray($array)
{ {
return array_map(function($value) {
return $this->encode($value) ;
}, $array) ;
if($array && is_array($array)) {
return array_map(function($value) {
return $this->encode($value) ;
}, $array) ;
}

return $array ;
} }


public function setTitle($title, $displayHeader = false){ public function setTitle($title, $displayHeader = false){

Loading…
Cancel
Save