public function buildForm(FormBuilderInterface $builder, array $options) | public function buildForm(FormBuilderInterface $builder, array $options) | ||||
{ | { | ||||
$isConnected = $this->security->getUser() ; | |||||
if(!$isConnected) { | |||||
$builder->add('visitorFirstname', TextType::class, [ | |||||
'label' => 'Prénom' | |||||
]) | |||||
->add('visitorLastname', TextType::class, [ | |||||
'label' => 'Nom' | |||||
]) | |||||
->add('visitorEmail', EmailType::class, [ | |||||
'label' => 'Email' | |||||
]) ; | |||||
} | |||||
$builder | $builder | ||||
->add('type', ChoiceType::class, [ | ->add('type', ChoiceType::class, [ | ||||
'label' => 'field.Ticket.type', | 'label' => 'field.Ticket.type', | ||||
'field.Ticket.typeOptions.'.Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM, | 'field.Ticket.typeOptions.'.Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM, | ||||
], | ], | ||||
'translation_domain' => 'lcshop', | 'translation_domain' => 'lcshop', | ||||
]) | |||||
->add('orderShop', EntityType::class, [ | |||||
]) ; | |||||
if($isConnected) { | |||||
$builder->add('orderShop', EntityType::class, [ | |||||
'class' => $this->em->getClassMetadata(OrderShop::class)->getName(), | 'class' => $this->em->getClassMetadata(OrderShop::class)->getName(), | ||||
'multiple' => false, | 'multiple' => false, | ||||
'expanded' => false, | 'expanded' => false, | ||||
return 'Commande du '.$orderShop->getValidationDate()->format('d/m/Y').' ('.number_format($this->priceUtils->getTotalWithTax($orderShop), 2).' €)' ; | return 'Commande du '.$orderShop->getValidationDate()->format('d/m/Y').' ('.number_format($this->priceUtils->getTotalWithTax($orderShop), 2).' €)' ; | ||||
}, | }, | ||||
'translation_domain' => 'lcshop', | 'translation_domain' => 'lcshop', | ||||
]) | |||||
->add('subject', TextType::class, [ | |||||
]) ; | |||||
} | |||||
$builder->add('subject', TextType::class, [ | |||||
'label' => 'Sujet' | 'label' => 'Sujet' | ||||
]) | ]) | ||||
->add('message', TextareaType::class, [ | ->add('message', TextareaType::class, [ |
emailFrom: "Email (From) : email" | emailFrom: "Email (From) : email" | ||||
emailFromName: "Email (From) : nom" | emailFromName: "Email (From) : nom" | ||||
emailSubjectPrefix: "Email : préfixe" | emailSubjectPrefix: "Email : préfixe" | ||||
emailContact: Email (contact) | |||||
order: Commande | order: Commande | ||||
PointSale: | PointSale: | ||||
code: Code | code: Code |
const TO_NAME = 'to-name' ; | const TO_NAME = 'to-name' ; | ||||
const FROM_EMAIL = 'from-email' ; | const FROM_EMAIL = 'from-email' ; | ||||
const FROM_NAME = 'from-name' ; | const FROM_NAME = 'from-name' ; | ||||
const REPLY_TO = 'reply-to' ; | |||||
const CONTENT_TEMPLATE = 'content-template' ; | const CONTENT_TEMPLATE = 'content-template' ; | ||||
const CONTENT_DATA = 'content-data' ; | const CONTENT_DATA = 'content-data' ; | ||||
const ATTACHMENT_DATA = 'attachment-data' ; | const ATTACHMENT_DATA = 'attachment-data' ; | ||||
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE].'-html.html.twig', $params[self::CONTENT_DATA]), 'text/html') | ->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])); | ->addPart($this->templating->render($params[self::CONTENT_TEMPLATE].'-text.html.twig', $params[self::CONTENT_DATA])); | ||||
if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) { | |||||
$message->addReplyTo($params[self::REPLY_TO]) ; | |||||
} | |||||
if(isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) { | if(isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) { | ||||
$message->attach(\Swift_Attachment::newInstance( | $message->attach(\Swift_Attachment::newInstance( | ||||
$params[self::ATTACHMENT_DATA], | $params[self::ATTACHMENT_DATA], |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\OrderShopInterface; | |||||
use Lc\ShopBundle\Context\TicketInterface; | |||||
use Lc\ShopBundle\Context\TicketMessageInterface; | |||||
use Lc\ShopBundle\Model\Ticket; | |||||
class TicketUtils | |||||
{ | |||||
protected $em ; | |||||
protected $merchantUtils ; | |||||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) | |||||
{ | |||||
$this->em = $em ; | |||||
$this->merchantUtils = $merchantUtils ; | |||||
} | |||||
public function createTicket($params): TicketInterface | |||||
{ | |||||
$classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName() ; | |||||
$ticket = new $classTicket ; | |||||
$ticket->setMerchant($this->merchantUtils->getMerchantCurrent()) ; | |||||
$ticket->setStatus(1) ; | |||||
if(isset($params['user'])) { | |||||
$ticket->setUser($params['user']) ; | |||||
} | |||||
else { | |||||
$ticket->setVisitorFirstname($params['visitorFirstname']) ; | |||||
$ticket->setVisitorLastname($params['visitorLastname']) ; | |||||
$ticket->setVisitorEmail($params['visitorEmail']) ; | |||||
$ticket->setVisitorToken(uniqid()) ; | |||||
} | |||||
$ticket->setTicketStatus(Ticket::TICKET_STATUS_OPEN) ; | |||||
$ticket->setType($params['type']) ; | |||||
if(isset($params['orderShop']) && $params['orderShop'] && $params['orderShop'] instanceof OrderShopInterface) { | |||||
$ticket->setOrderShop($params['orderShop']) ; | |||||
} | |||||
$ticket->setSubject($params['subject']) ; | |||||
$this->em->persist($ticket); | |||||
$classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ; | |||||
$ticketMessage = new $classTicketMessage ; | |||||
$ticketMessage->setStatus(1) ; | |||||
$ticketMessage->setTicket($ticket) ; | |||||
$ticketMessage->setMessage($params['message']) ; | |||||
$this->em->persist($ticketMessage); | |||||
$this->em->flush() ; | |||||
return $ticket ; | |||||
} | |||||
} | |||||
protected $creditUtils ; | protected $creditUtils ; | ||||
protected $documentUtils ; | protected $documentUtils ; | ||||
protected $mailUtils ; | protected $mailUtils ; | ||||
protected $ticketUtils ; | |||||
public function __construct( | public function __construct( | ||||
Utils $utils, | Utils $utils, | ||||
DeliveryUtilsInterface $deliveryUtils, | DeliveryUtilsInterface $deliveryUtils, | ||||
CreditUtils $creditUtils, | CreditUtils $creditUtils, | ||||
DocumentUtils $documentUtils, | DocumentUtils $documentUtils, | ||||
MailUtils $mailUtils | |||||
MailUtils $mailUtils, | |||||
TicketUtils $ticketUtils | |||||
) | ) | ||||
{ | { | ||||
$this->utils = $utils ; | $this->utils = $utils ; | ||||
$this->creditUtils = $creditUtils ; | $this->creditUtils = $creditUtils ; | ||||
$this->documentUtils = $documentUtils ; | $this->documentUtils = $documentUtils ; | ||||
$this->mailUtils = $mailUtils ; | $this->mailUtils = $mailUtils ; | ||||
$this->ticketUtils = $ticketUtils ; | |||||
} | } | ||||
public function getUtils(): Utils | public function getUtils(): Utils | ||||
{ | { | ||||
return $this->mailUtils ; | return $this->mailUtils ; | ||||
} | } | ||||
public function getTicketUtils(): TicketUtils | |||||
{ | |||||
return $this->ticketUtils ; | |||||
} | |||||
} | } |