@@ -3,6 +3,7 @@ | |||
namespace Lc\CaracoleBundle\Builder\File; | |||
use Lc\CaracoleBundle\Model\File\DocumentInterface; | |||
use Lc\CaracoleBundle\Model\File\DocumentModel; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator; | |||
@@ -17,10 +18,10 @@ class DocumentBuilder | |||
public function initFromOrderShop(DocumentInterface $document, OrderShopInterface $orderShop) :DocumentInterface | |||
{ | |||
$merchantAddress = $orderShop->getMerchant()->getAddress(); | |||
$merchantAddress = $orderShop->getSection()->getMerchant()->getAddress(); | |||
$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->setBuyerAddress($buyerAddress); | |||
$document->setMerchantAddressText($merchantAddress->getSummary()); |
@@ -372,7 +372,7 @@ class OrderShopBuilder | |||
public function createDocumentInvoice(OrderShopInterface $orderShop): DocumentInterface | |||
{ | |||
$documentFactory = new DocumentFactory(); | |||
$document = $documentFactory->create(DocumentModel::TYPE_INVOICE); | |||
$document = $documentFactory->create($orderShop->getSection(),DocumentModel::TYPE_INVOICE); | |||
$this->documentBuilder->initFromOrderShop($document, $orderShop); | |||
return $document; | |||
} |
@@ -2,7 +2,7 @@ | |||
namespace Lc\CaracoleBundle\Container\Order; | |||
use App\Resolver\OrderResolver; | |||
use App\Resolver\OrderShopResolver; | |||
use Lc\CaracoleBundle\Builder\Order\OrderShopBuilder; | |||
use Lc\CaracoleBundle\Definition\Field\Order\OrderShopFieldDefinition; | |||
use Lc\CaracoleBundle\Factory\Order\OrderShopFactory; | |||
@@ -18,7 +18,7 @@ class OrderShopContainer | |||
protected OrderShopRepositoryQuery $repositoryQuery; | |||
protected OrderShopStore $store; | |||
protected OrderShopBuilder $builder; | |||
protected OrderResolver $resolver; | |||
protected OrderShopResolver $resolver; | |||
protected OrderShopTransformer $transformer; | |||
protected OrderShopFieldDefinition $fieldDefinition; | |||
@@ -27,7 +27,7 @@ class OrderShopContainer | |||
OrderShopSolver $solver, | |||
OrderShopRepositoryQuery $repositoryQuery, | |||
OrderShopStore $store, | |||
OrderResolver $resolver, | |||
OrderShopResolver $resolver, | |||
OrderShopBuilder $builder, | |||
OrderShopTransformer $transformer, | |||
OrderShopFieldDefinition $fieldDefinition | |||
@@ -62,7 +62,7 @@ class OrderShopContainer | |||
return $this->store; | |||
} | |||
public function getResolver(): OrderResolver | |||
public function getResolver(): OrderShopResolver | |||
{ | |||
return $this->resolver; | |||
} |
@@ -61,7 +61,7 @@ class SettingAdminController extends SovSettingController | |||
if ($entity) { | |||
$form = $this->createForm($formClass, $entity); | |||
dump($request); | |||
$form->handleRequest($request); | |||
if ($form->isSubmitted() && $form->isValid()) { |
@@ -24,30 +24,31 @@ class OrderShopFieldDefinition extends AbstractFieldDefinition | |||
public function configureFields(): array | |||
{ | |||
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'), | |||
'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'), | |||
'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'), | |||
'total' => NumberField::new('total') | |||
->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'), | |||
'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'), | |||
'reference' => TextField::new('reference'), | |||
'reference' => TextField::new('reference')->setSortable(true), | |||
'complementaryOrderShops' => AssociationField::new('complementaryOrderShops')->setFormTypeOption('mapped', false) | |||
->setTemplatePath('@LcCaracole/admin/order/field/complementary.html.twig'), | |||
'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) | |||
]; | |||
} |
@@ -11,9 +11,7 @@ class OrderPaymentFactory extends AbstractFactory | |||
{ | |||
public function create(OrderShopInterface $orderShop, string $meanPayment, float $amount): OrderPaymentInterface | |||
{ | |||
$orderPayment = new OrderPayment(); | |||
$orderPayment->setOrderShop($orderShop); | |||
$orderPayment = $this->createBase($orderShop); | |||
$orderPayment->setMeanPayment($meanPayment); | |||
$orderPayment->setAmount($amount); | |||
$orderPayment->setPaidAt(new \DateTime()); | |||
@@ -22,4 +20,9 @@ class OrderPaymentFactory extends AbstractFactory | |||
return $orderPayment; | |||
} | |||
public function createBase($orderShop){ | |||
$orderPayment = new OrderPayment(); | |||
$orderPayment->setOrderShop($orderShop); | |||
return $orderPayment; | |||
} | |||
} |
@@ -18,15 +18,13 @@ class OrderShopFactory extends AbstractFactory | |||
{ | |||
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; | |||
if (!is_null($user)) { | |||
@@ -46,4 +44,11 @@ class OrderShopFactory extends AbstractFactory | |||
return $orderShop; | |||
} | |||
public function createBase(SectionInterface $section): OrderShopInterface | |||
{ | |||
$orderShop = new OrderShop(); | |||
$orderShop->setSection($section); | |||
return $orderShop; | |||
} | |||
} |
@@ -1,118 +0,0 @@ | |||
<?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); | |||
} | |||
} |
@@ -1,103 +0,0 @@ | |||
<?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; | |||
} | |||
} |
@@ -2,8 +2,7 @@ | |||
{% set item = entity.instance %} | |||
{% for val in value %} | |||
<span class="badge badge-success"> | |||
{% set trad = 'field.default.meanPaymentChoices.'~val.meanPayment %} | |||
{{ trad|trans({}, 'lcshop') }} | |||
{{ val.meanPayment|sov_trans_admin_choice('meanPayment', 'OrderPayment') }} | |||
</span> | |||
{% endfor %} | |||
@@ -341,11 +341,6 @@ class OrderShopSolver | |||
return false; | |||
} | |||
public function isCartAllowToBeOrder(OrderShopInterface $orderShop): bool | |||
{ | |||
return true; | |||
} | |||
// getProductQuantityMaxAddCart | |||
public function getProductQuantityMaxAddCart(ProductInterface $product, OrderShopInterface $orderShop) | |||
{ |
@@ -98,14 +98,15 @@ class OrderShopTransformer | |||
{ | |||
$data = array(); | |||
foreach ($order->getOrderPayments() as $orderPayment) { | |||
dump($orderPayment->getEditable()); | |||
$data[$orderPayment->getId()] = array( | |||
'id' => $orderPayment->getId(), | |||
'reference' => $orderPayment->getReference(), | |||
'orderReference' => $order->getReference(), | |||
'comment' => $orderPayment->getComment(), | |||
'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'), | |||
'paidAt' => $orderPayment->getPaidAt()->format('Y-m-d'), |