Browse Source

MailUtils

feature/export_comptable
Guillaume 4 years ago
parent
commit
00e6f3201b
2 changed files with 53 additions and 1 deletions
  1. +45
    -0
      ShopBundle/Services/MailUtils.php
  2. +8
    -1
      ShopBundle/Services/UtilsManager.php

+ 45
- 0
ShopBundle/Services/MailUtils.php View File

<?php

namespace Lc\ShopBundle\Services ;

use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Twig\Environment;

class MailUtils
{
const SUBJECT = 'subject' ;
const TO_EMAIL = 'to-email' ;
const TO_NAME = 'to-name' ;
const FROM_EMAIL = 'from-email' ;
const FROM_NAME = 'from-name' ;
const CONTENT_TEMPLATE = 'content-template' ;
const CONTENT_DATA = 'content-data' ;

protected $transport ;
protected $templating ;
protected $parameterBag ;

public function __construct(MailjetTransport $mailjetTransport, Environment $templating,ParameterBagInterface $parameterBag)
{
$this->transport = $mailjetTransport ;
$this->templating = $templating ;
$this->parameterBag = $parameterBag ;
}

public function send($params = [])
{
$message = new \Swift_Message($params[self::SUBJECT]);
$message->addTo(
$params[self::TO_EMAIL],
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null)
->addFrom(
isset($params[self::FROM_EMAIL]) ? $params[self::FROM_EMAIL] : $this->parameterBag->get('app.noreply_email'),
isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $this->parameterBag->get('app.site_name'))
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE].'-html.html.twig', $params[self::CONTENT_DATA]), 'text/html')
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE].'-text.html.twig', $params[self::CONTENT_DATA]))
;

$this->transport->send($message) ;
}
}

+ 8
- 1
ShopBundle/Services/UtilsManager.php View File

protected $deliveryUtils ; protected $deliveryUtils ;
protected $creditUtils ; protected $creditUtils ;
protected $documentUtils ; protected $documentUtils ;
protected $mailUtils ;


public function __construct( public function __construct(
Utils $utils, Utils $utils,
PriceUtilsInterface $priceUtils, PriceUtilsInterface $priceUtils,
DeliveryUtilsInterface $deliveryUtils, DeliveryUtilsInterface $deliveryUtils,
CreditUtils $creditUtils, CreditUtils $creditUtils,
DocumentUtils $documentUtils
DocumentUtils $documentUtils,
MailUtils $mailUtils
) )
{ {
$this->utils = $utils ; $this->utils = $utils ;
$this->deliveryUtils = $deliveryUtils ; $this->deliveryUtils = $deliveryUtils ;
$this->creditUtils = $creditUtils ; $this->creditUtils = $creditUtils ;
$this->documentUtils = $documentUtils ; $this->documentUtils = $documentUtils ;
$this->mailUtils = $mailUtils ;
} }


public function getUtils(): Utils public function getUtils(): Utils
return $this->documentUtils ; return $this->documentUtils ;
} }


public function getMailUtils(): MailUtils
{
return $this->mailUtils ;
}
} }

Loading…
Cancel
Save