@@ -34,6 +34,20 @@ class TicketType extends AbstractType | |||
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 | |||
->add('type', ChoiceType::class, [ | |||
'label' => 'field.Ticket.type', | |||
@@ -46,8 +60,11 @@ class TicketType extends AbstractType | |||
'field.Ticket.typeOptions.'.Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM, | |||
], | |||
'translation_domain' => 'lcshop', | |||
]) | |||
->add('orderShop', EntityType::class, [ | |||
]) ; | |||
if($isConnected) { | |||
$builder->add('orderShop', EntityType::class, [ | |||
'class' => $this->em->getClassMetadata(OrderShop::class)->getName(), | |||
'multiple' => false, | |||
'expanded' => false, | |||
@@ -62,8 +79,10 @@ class TicketType extends AbstractType | |||
return 'Commande du '.$orderShop->getValidationDate()->format('d/m/Y').' ('.number_format($this->priceUtils->getTotalWithTax($orderShop), 2).' €)' ; | |||
}, | |||
'translation_domain' => 'lcshop', | |||
]) | |||
->add('subject', TextType::class, [ | |||
]) ; | |||
} | |||
$builder->add('subject', TextType::class, [ | |||
'label' => 'Sujet' | |||
]) | |||
->add('message', TextareaType::class, [ |
@@ -217,6 +217,7 @@ field: | |||
emailFrom: "Email (From) : email" | |||
emailFromName: "Email (From) : nom" | |||
emailSubjectPrefix: "Email : préfixe" | |||
emailContact: Email (contact) | |||
order: Commande | |||
PointSale: | |||
code: Code |
@@ -16,6 +16,7 @@ class MailUtils | |||
const TO_NAME = 'to-name' ; | |||
const FROM_EMAIL = 'from-email' ; | |||
const FROM_NAME = 'from-name' ; | |||
const REPLY_TO = 'reply-to' ; | |||
const CONTENT_TEMPLATE = 'content-template' ; | |||
const CONTENT_DATA = 'content-data' ; | |||
const ATTACHMENT_DATA = 'attachment-data' ; | |||
@@ -59,6 +60,10 @@ class MailUtils | |||
->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])); | |||
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])) { | |||
$message->attach(\Swift_Attachment::newInstance( | |||
$params[self::ATTACHMENT_DATA], |
@@ -0,0 +1,60 @@ | |||
<?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 ; | |||
} | |||
} | |||
@@ -20,6 +20,7 @@ class UtilsManager | |||
protected $creditUtils ; | |||
protected $documentUtils ; | |||
protected $mailUtils ; | |||
protected $ticketUtils ; | |||
public function __construct( | |||
Utils $utils, | |||
@@ -31,7 +32,8 @@ class UtilsManager | |||
DeliveryUtilsInterface $deliveryUtils, | |||
CreditUtils $creditUtils, | |||
DocumentUtils $documentUtils, | |||
MailUtils $mailUtils | |||
MailUtils $mailUtils, | |||
TicketUtils $ticketUtils | |||
) | |||
{ | |||
$this->utils = $utils ; | |||
@@ -44,6 +46,7 @@ class UtilsManager | |||
$this->creditUtils = $creditUtils ; | |||
$this->documentUtils = $documentUtils ; | |||
$this->mailUtils = $mailUtils ; | |||
$this->ticketUtils = $ticketUtils ; | |||
} | |||
public function getUtils(): Utils | |||
@@ -95,4 +98,9 @@ class UtilsManager | |||
{ | |||
return $this->mailUtils ; | |||
} | |||
public function getTicketUtils(): TicketUtils | |||
{ | |||
return $this->ticketUtils ; | |||
} | |||
} |