namespace Lc\CaracoleBundle\Builder\File; | namespace Lc\CaracoleBundle\Builder\File; | ||||
use Lc\CaracoleBundle\Model\File\DocumentInterface; | use Lc\CaracoleBundle\Model\File\DocumentInterface; | ||||
use Lc\CaracoleBundle\Model\File\DocumentModel; | |||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator; | use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator; | ||||
public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface | public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface | ||||
{ | { | ||||
$merchantAddress = $orderShop->getMerchant()->getAddress(); | |||||
$merchantAddress = $orderShop->getSection()->getMerchant()->getAddress(); | |||||
$buyerAddress = $orderShop->getInvoiceAddress(); | $buyerAddress = $orderShop->getInvoiceAddress(); | ||||
$document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getMerchant())) ; | |||||
//TODO a discuter, doit on garder le lien avec merchant pr la référence ou le mettre par section ? Est-ce que le nom de cette fonction est approprié. on fait une invoice et ça s'appele initFromOrderShop | |||||
$document->setReference($this->documentReferenceGenerator->buildReference($orderShop->getSection()->getMerchant(), DocumentModel::TYPE_INVOICE)) ; | |||||
$document->setMerchantAddress($merchantAddress); | $document->setMerchantAddress($merchantAddress); | ||||
$document->setBuyerAddress($buyerAddress); | $document->setBuyerAddress($buyerAddress); | ||||
$document->setMerchantAddressText($merchantAddress->getSummary()); | $document->setMerchantAddressText($merchantAddress->getSummary()); |
public function createDocumentInvoice(OrderShopInterface $orderShop): DocumentInterface | public function createDocumentInvoice(OrderShopInterface $orderShop): DocumentInterface | ||||
{ | { | ||||
$documentFactory = new DocumentFactory(); | $documentFactory = new DocumentFactory(); | ||||
$document = $documentFactory->create(DocumentModel::TYPE_INVOICE); | |||||
$document = $documentFactory->create($orderShop->getSection(),DocumentModel::TYPE_INVOICE); | |||||
$this->documentBuilder->initFromOrderShop($document, $orderShop); | $this->documentBuilder->initFromOrderShop($document, $orderShop); | ||||
return $document; | return $document; | ||||
} | } |
namespace Lc\CaracoleBundle\Container\Order; | namespace Lc\CaracoleBundle\Container\Order; | ||||
use App\Resolver\OrderResolver; | |||||
use App\Resolver\OrderShopResolver; | |||||
use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder; | use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder; | ||||
use Lc\CaracoleBundle\Definition\Field\Order\OrderShopFieldDefinition; | use Lc\CaracoleBundle\Definition\Field\Order\OrderShopFieldDefinition; | ||||
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | ||||
protected OrderShopRepositoryQuery $repositoryQuery; | protected OrderShopRepositoryQuery $repositoryQuery; | ||||
protected OrderShopStore $store; | protected OrderShopStore $store; | ||||
protected OrderShopBuilder $builder; | protected OrderShopBuilder $builder; | ||||
protected OrderResolver $resolver; | |||||
protected OrderShopResolver $resolver; | |||||
protected OrderShopTransformer $transformer; | protected OrderShopTransformer $transformer; | ||||
protected OrderShopFieldDefinition $fieldDefinition; | protected OrderShopFieldDefinition $fieldDefinition; | ||||
OrderShopSolver $solver, | OrderShopSolver $solver, | ||||
OrderShopRepositoryQuery $repositoryQuery, | OrderShopRepositoryQuery $repositoryQuery, | ||||
OrderShopStore $store, | OrderShopStore $store, | ||||
OrderResolver $resolver, | |||||
OrderShopResolver $resolver, | |||||
OrderShopBuilder $builder, | OrderShopBuilder $builder, | ||||
OrderShopTransformer $transformer, | OrderShopTransformer $transformer, | ||||
OrderShopFieldDefinition $fieldDefinition | OrderShopFieldDefinition $fieldDefinition | ||||
return $this->store; | return $this->store; | ||||
} | } | ||||
public function getResolver(): OrderResolver | |||||
public function getResolver(): OrderShopResolver | |||||
{ | { | ||||
return $this->resolver; | return $this->resolver; | ||||
} | } |
if ($entity) { | if ($entity) { | ||||
$form = $this->createForm($formClass, $entity); | $form = $this->createForm($formClass, $entity); | ||||
dump($request); | |||||
$form->handleRequest($request); | $form->handleRequest($request); | ||||
if ($form->isSubmitted() && $form->isValid()) { | if ($form->isSubmitted() && $form->isValid()) { |
public function configureFields(): array | public function configureFields(): array | ||||
{ | { | ||||
return [ | return [ | ||||
'id' => IntegerField::new('id', 'ID'), | |||||
'userLastname' => TextareaField::new('user.lastname', 'field.default.lastname'), | |||||
'id' => IntegerField::new('id', 'ID')->setSortable(true), | |||||
'userLastname' => TextareaField::new('user.lastname', 'field.default.lastname')->setSortable(true), | |||||
//->setTemplatePath('@LcShop/backend/default/field/textorempty.html.twig'), | //->setTemplatePath('@LcShop/backend/default/field/textorempty.html.twig'), | ||||
'userFirstname' => TextareaField::new('user.firstname', 'field.default.firstname'), | |||||
'userFirstname' => TextareaField::new('user.firstname', 'field.default.firstname')->setSortable(true), | |||||
//->setTemplatePath('@LcShop/backend/default/field/textorempty.html.twig'), | //->setTemplatePath('@LcShop/backend/default/field/textorempty.html.twig'), | ||||
'userEmail' => TextareaField::new('user.email', 'field.default.email'), | |||||
'userEmail' => TextareaField::new('user.email', 'field.default.email')->setSortable(true), | |||||
//->setTemplatePath('@LcShop/backend/default/field/user.html.twig'), | //->setTemplatePath('@LcShop/backend/default/field/user.html.twig'), | ||||
'total' => NumberField::new('total') | 'total' => NumberField::new('total') | ||||
->setTemplatePath('@LcCaracole/admin/order/field/total.html.twig'), | ->setTemplatePath('@LcCaracole/admin/order/field/total.html.twig'), | ||||
'orderStatus' => AssociationField::new('orderStatus') | |||||
'orderStatus' => AssociationField::new('orderStatus')->setSortable(true) | |||||
->setTemplatePath('@LcCaracole/admin/order/field/order_status.html.twig'), | ->setTemplatePath('@LcCaracole/admin/order/field/order_status.html.twig'), | ||||
'createdAt' => DateTimeField::new('createdAt', 'field.OrderShop.createdAt'), | |||||
'updatedAt' => DateTimeField::new('updatedAt', 'field.OrderShop.updatedAt'), | |||||
'orderShopCreatedAt' => DateTimeField::new('orderShopCreatedAt', 'field.OrderShop.createdAt'), | |||||
'cycleNumber' => IntegerField::new('cycleNumber'), | |||||
'cycleDeliveryId' => IntegerField::new('cycleDeliveryId'), | |||||
'cycleId' => IntegerField::new('cycleId'), | |||||
'deliveryType' => Field::new('deliveryType'), | |||||
'createdAt' => DateTimeField::new('createdAt')->setSortable(true), | |||||
'updatedAt' => DateTimeField::new('updatedAt')->setSortable(true), | |||||
'orderShopCreatedAt' => DateTimeField::new('orderShopCreatedAt')->setSortable(true), | |||||
'cycleNumber' => IntegerField::new('cycleNumber')->setSortable(true), | |||||
'cycleDeliveryId' => IntegerField::new('cycleDeliveryId')->setSortable(true), | |||||
'cycleId' => IntegerField::new('cycleId')->setSortable(true), | |||||
'deliveryType' => Field::new('deliveryType')->setSortable(true), | |||||
//->setTemplatePath('@LcShop/backend/default/field/options_translatable.html.twig'), | //->setTemplatePath('@LcShop/backend/default/field/options_translatable.html.twig'), | ||||
'reference' => TextField::new('reference'), | |||||
'reference' => TextField::new('reference')->setSortable(true), | |||||
'complementaryOrderShops' => AssociationField::new('complementaryOrderShops')->setFormTypeOption('mapped', false) | 'complementaryOrderShops' => AssociationField::new('complementaryOrderShops')->setFormTypeOption('mapped', false) | ||||
->setTemplatePath('@LcCaracole/admin/order/field/complementary.html.twig'), | ->setTemplatePath('@LcCaracole/admin/order/field/complementary.html.twig'), | ||||
'orderPayments' => AssociationField::new('orderPayments') | 'orderPayments' => AssociationField::new('orderPayments') | ||||
->setTemplatePath('@LcCaracole/admin/order/field/order_payment.html.twig') | |||||
->setTemplatePath('@LcCaracole/admin/order/field/order_payment.html.twig'), | |||||
'user'=> AssociationField::new('user')->setSortable(true) | |||||
]; | ]; | ||||
} | } |
{ | { | ||||
public function create(OrderShopInterface $orderShop, string $meanPayment, float $amount): OrderPaymentInterface | public function create(OrderShopInterface $orderShop, string $meanPayment, float $amount): OrderPaymentInterface | ||||
{ | { | ||||
$orderPayment = new OrderPayment(); | |||||
$orderPayment->setOrderShop($orderShop); | |||||
$orderPayment = $this->createBase($orderShop); | |||||
$orderPayment->setMeanPayment($meanPayment); | $orderPayment->setMeanPayment($meanPayment); | ||||
$orderPayment->setAmount($amount); | $orderPayment->setAmount($amount); | ||||
$orderPayment->setPaidAt(new \DateTime()); | $orderPayment->setPaidAt(new \DateTime()); | ||||
return $orderPayment; | return $orderPayment; | ||||
} | } | ||||
public function createBase($orderShop){ | |||||
$orderPayment = new OrderPayment(); | |||||
$orderPayment->setOrderShop($orderShop); | |||||
return $orderPayment; | |||||
} | |||||
} | } |
{ | { | ||||
public function create( | public function create( | ||||
SectionInterface $section, | |||||
UserInterface $user = null, | |||||
VisitorInterface $visitor = null | |||||
): OrderShopInterface { | |||||
$orderShop = new OrderShop(); | |||||
$orderShop->setSection($section); | |||||
SectionInterface $section, | |||||
UserInterface $user = null, | |||||
VisitorInterface $visitor = null | |||||
): OrderShopInterface | |||||
{ | |||||
$orderShop = $this->createBase($section); | |||||
$orderShopBelongTo = false; | $orderShopBelongTo = false; | ||||
if (!is_null($user)) { | if (!is_null($user)) { | ||||
return $orderShop; | return $orderShop; | ||||
} | } | ||||
public function createBase(SectionInterface $section): OrderShopInterface | |||||
{ | |||||
$orderShop = new OrderShop(); | |||||
$orderShop->setSection($section); | |||||
return $orderShop; | |||||
} | |||||
} | } |
<?php | |||||
namespace Lc\CaracoleBundle\Notification; | |||||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; | |||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||||
use Lc\SovBundle\Solver\Setting\SettingSolver; | |||||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||||
use Twig\Environment; | |||||
class MailMailjetNotification | |||||
{ | |||||
const SUBJECT = 'subject'; | |||||
const SUBJECT_PREFIX = 'subject-prefix'; | |||||
const TO_EMAIL = 'to-email'; | |||||
const COPY_TO = 'copy-to'; | |||||
const COPY_HIDDEN_TO = 'copy-hidden-to'; | |||||
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'; | |||||
const ATTACHMENT_FILENAME = 'attachment-filename'; | |||||
const ATTACHMENT_CONTENT_TYPE = 'attachment-content-type'; | |||||
//const DISPOSITION_NOTIFICATION_TO = 'disposition-notification-to' ; | |||||
protected MailjetTransport $transport; | |||||
protected Environment $templating; | |||||
protected ParameterBagInterface $parameterBag; | |||||
protected MerchantResolver $merchantResolver; | |||||
protected SettingSolver $settingSolver; | |||||
public function __construct( | |||||
MailjetTransport $mailjetTransport, | |||||
Environment $templating, | |||||
ParameterBagInterface $parameterBag, | |||||
MerchantResolver $merchantResolver, | |||||
SettingSolver $settingSolver | |||||
) { | |||||
$this->transport = $mailjetTransport; | |||||
$this->templating = $templating; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->merchantResolver = $merchantResolver; | |||||
$this->settingSolver = $settingSolver; | |||||
} | |||||
public function send($params = []) | |||||
{ | |||||
$merchantCurrent = $this->merchantResolver->getCurrent(); | |||||
$merchantConfigEmailFrom = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_FROM); | |||||
$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL])) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom; | |||||
$merchantConfigEmailFromName = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME); | |||||
$emailFromName = isset($params[self::FROM_NAME]) ?? $merchantConfigEmailFromName; | |||||
$merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX); | |||||
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ?? $merchantConfigEmailSubjectPrefix; | |||||
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) { | |||||
$emailSubjectPrefix .= ' '; | |||||
} | |||||
$message = new \Swift_Message($emailSubjectPrefix . $params[self::SUBJECT]); | |||||
if ($this->parameterBag->get('mailjet.dev.redirect.active')==1) { | |||||
$message->addTo($this->parameterBag->get('mailjet.dev.redirect.email'), | |||||
isset($params[self::TO_NAME]) ?? null); | |||||
} else { | |||||
$message->addTo( | |||||
$params[self::TO_EMAIL], | |||||
isset($params[self::TO_NAME]) ?? null); | |||||
} | |||||
$contentData = [] ; | |||||
if(isset($params[self::CONTENT_DATA])) { | |||||
$contentData = $params[self::CONTENT_DATA] ; | |||||
} | |||||
$message->addFrom($emailFrom, $emailFromName) | |||||
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $contentData), 'text/html') | |||||
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $contentData)); | |||||
if(isset($params[self::COPY_TO]) && strlen($params[self::COPY_TO])) { | |||||
$message->addCc($params[self::COPY_TO]); | |||||
} | |||||
if(isset($params[self::COPY_HIDDEN_TO]) && strlen($params[self::COPY_HIDDEN_TO])) { | |||||
$message->addBcc($params[self::COPY_HIDDEN_TO]); | |||||
} | |||||
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], | |||||
$params[self::ATTACHMENT_FILENAME], | |||||
$params[self::ATTACHMENT_CONTENT_TYPE] | |||||
)); | |||||
} | |||||
/*if(isset($params[self::DISPOSITION_NOTIFICATION_TO]) && $params[self::DISPOSITION_NOTIFICATION_TO]) { | |||||
$emailFromDispositionNotificationTo = $emailFrom ; | |||||
if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) { | |||||
$emailFromDispositionNotificationTo = $params[self::REPLY_TO] ; | |||||
} | |||||
$message->getHeaders()->addTextHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo) ; | |||||
$message->getHeaders()->addMailboxHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo); | |||||
}*/ | |||||
return $this->transport->send($message); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\CaracoleBundle\Notification; | |||||
use Lc\SovBundle\Component\StringComponent; | |||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||||
use Symfony\Contracts\HttpClient\HttpClientInterface; | |||||
use Twig\Environment; | |||||
class SmsFactorNotification | |||||
{ | |||||
const TO_USER = 'to-user' ; | |||||
const CONTENT_MESSAGE = 'content-message' ; | |||||
const CONTENT_TEMPLATE = 'content-template' ; | |||||
const CONTENT_DATA = 'content-data' ; | |||||
protected HttpClientInterface $client; | |||||
protected ParameterBagInterface $parameterBag; | |||||
protected MailMailjetNotification $mailMailjetNotification ; | |||||
protected StringComponent $stringComponent ; | |||||
protected Environment $templating ; | |||||
public function __construct( | |||||
HttpClientInterface $client, | |||||
ParameterBagInterface $parameterBag, | |||||
MailMailjetNotification $mailMailjetNotification, | |||||
StringComponent $stringComponent, | |||||
Environment $templating | |||||
) { | |||||
$this->client = $client; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->mailMailjetNotification = $mailMailjetNotification ; | |||||
$this->stringComponent = $stringComponent ; | |||||
$this->templating = $templating ; | |||||
} | |||||
public function send($params = []) | |||||
{ | |||||
$user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null ; | |||||
if($user) { | |||||
$phone = $this->stringComponent->formatPhoneNumber($user->getPhone()) ; | |||||
$message = '' ; | |||||
if(isset($params[self::CONTENT_MESSAGE])) { | |||||
$message = $params[self::CONTENT_MESSAGE] ; | |||||
} | |||||
elseif(isset($params[self::CONTENT_TEMPLATE])) { | |||||
$template = $params[self::CONTENT_TEMPLATE] ; | |||||
$paramsTemplate = [] ; | |||||
if(isset($params[self::CONTENT_DATA]) && is_array($params[self::CONTENT_DATA])) { | |||||
$paramsTemplate = $params[self::CONTENT_DATA] ; | |||||
} | |||||
$message = $this->templating->render($template, $paramsTemplate) ; | |||||
} | |||||
if($this->parameterBag->get('mailjet.dev.redirect.active') == 1) { | |||||
$this->mailMailjetNotification->send([ | |||||
MailMailjetNotification::SUBJECT => 'Notification par SMS à '.$phone, | |||||
MailMailjetNotification::TO_EMAIL => $user->getEmail(), | |||||
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/notification', | |||||
MailMailjetNotification::CONTENT_DATA => [ | |||||
'message' => $message | |||||
], | |||||
]); | |||||
return true ; | |||||
} | |||||
else { | |||||
$token = $this->parameterBag->get('smsfactor.token'); | |||||
$from = $this->parameterBag->get('smsfactor.from'); | |||||
if ($token && strlen($token) > 0) { | |||||
$response = $this->client->request( | |||||
'GET', | |||||
'https://api.smsfactor.com/send', | |||||
[ | |||||
'headers' => [ | |||||
'Authorization' => 'Bearer ' . $token, | |||||
'Content-Type' => 'application/json; charset=utf-8', | |||||
'Accept' => 'application/json' | |||||
], | |||||
'query' => [ | |||||
'sender' => $from, | |||||
'to' => $phone, | |||||
'text' => $message, | |||||
], | |||||
] | |||||
); | |||||
return $response ; | |||||
} | |||||
else { | |||||
throw new \ErrorException('Le token SMS SmsFactor n\'est pas défini.'); | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} |
{% set item = entity.instance %} | {% set item = entity.instance %} | ||||
{% for val in value %} | {% for val in value %} | ||||
<span class="badge badge-success"> | <span class="badge badge-success"> | ||||
{% set trad = 'field.default.meanPaymentChoices.'~val.meanPayment %} | |||||
{{ trad|trans({}, 'lcshop') }} | |||||
{{ val.meanPayment|sov_trans_admin_choice('meanPayment', 'OrderPayment') }} | |||||
</span> | </span> | ||||
{% endfor %} | {% endfor %} | ||||
return false; | return false; | ||||
} | } | ||||
public function isCartAllowToBeOrder(OrderShopInterface $orderShop): bool | |||||
{ | |||||
return true; | |||||
} | |||||
// getProductQuantityMaxAddCart | // getProductQuantityMaxAddCart | ||||
public function getProductQuantityMaxAddCart(ProductInterface $product, OrderShopInterface $orderShop) | public function getProductQuantityMaxAddCart(ProductInterface $product, OrderShopInterface $orderShop) | ||||
{ | { |
{ | { | ||||
$data = array(); | $data = array(); | ||||
foreach ($order->getOrderPayments() as $orderPayment) { | foreach ($order->getOrderPayments() as $orderPayment) { | ||||
dump($orderPayment->getEditable()); | |||||
$data[$orderPayment->getId()] = array( | $data[$orderPayment->getId()] = array( | ||||
'id' => $orderPayment->getId(), | 'id' => $orderPayment->getId(), | ||||
'reference' => $orderPayment->getReference(), | 'reference' => $orderPayment->getReference(), | ||||
'orderReference' => $order->getReference(), | 'orderReference' => $order->getReference(), | ||||
'comment' => $orderPayment->getComment(), | 'comment' => $orderPayment->getComment(), | ||||
'meanPayment' => $orderPayment->getMeanPayment(), | 'meanPayment' => $orderPayment->getMeanPayment(), | ||||
'meanPaymentText' => $this->translatorAdmin->trans( | |||||
'field.default.meanPaymentOptions.' . $orderPayment->getMeanPayment() | |||||
'meanPaymentText' => $this->translatorAdmin->transChoice( | |||||
'OrderPayment', 'meanPayment',$orderPayment->getMeanPayment() | |||||
), | ), | ||||
'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'), | 'paidAtText' => $orderPayment->getPaidAt()->format('d/m/Y'), | ||||
'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'), | 'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'), |