if (!$user instanceof UserInterface) return $user; | if (!$user instanceof UserInterface) return $user; | ||||
else { | else { | ||||
//TODO Utiliser getCartByUserOrCreateIt ds OrderUtils | |||||
$orderShopUser = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]); | $orderShopUser = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]); | ||||
if ($orderShopUser) { | if ($orderShopUser) { | ||||
$this->utils->addFlash('info', 'error.order.otherOrderAlreadyExist'); | $this->utils->addFlash('info', 'error.order.otherOrderAlreadyExist'); |
<?php | |||||
namespace Lc\ShopBundle\Form\Backend\Common; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Doctrine\ORM\EntityRepository; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\ProductInterface; | |||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\Form\FormEvent; | |||||
use Symfony\Component\Form\FormEvents; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class ProductType extends AbstractType | |||||
{ | |||||
protected $em; | |||||
protected $merchantUtils; | |||||
public function __construct(EntityManagerInterface $entityManager, MerchantUtilsInterface $merchantUtils) | |||||
{ | |||||
$this->em = $entityManager; | |||||
$this->merchantUtils = $merchantUtils; | |||||
} | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$productClass = $this->em->getClassMetadata(ProductInterface::class); | |||||
$currentMerchant = $this->merchantUtils->getMerchantUser(); | |||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($productClass, $options, $currentMerchant) { | |||||
$builder = $event->getForm()->getParent(); | |||||
$builder->add('product', EntityType::class, array_merge($options,[ | |||||
'class' => $productClass->name, | |||||
'query_builder' => function (EntityRepository $er) use ($currentMerchant) { | |||||
return $er->createQueryBuilder('p') | |||||
->join('p.productFamily', 'pFamily') | |||||
->where('pFamily.merchant = :currentMerchant') | |||||
->andWhere('pFamily.status = 1') | |||||
->setParameter('currentMerchant', $currentMerchant); | |||||
}, | |||||
'choice_label' => function ($product) { | |||||
return $product->getProductFamily()->getTitle() . ' - ' . $product->getTitle(); | |||||
} | |||||
])); | |||||
}); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'translation_domain' => 'lcshop', | |||||
]); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Form\Backend\Common; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Doctrine\ORM\EntityRepository; | |||||
use Lc\ShopBundle\Context\ReductionCatalogInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | |||||
use Lc\ShopBundle\Repository\GroupUserRepository; | |||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\Form\FormEvent; | |||||
use Symfony\Component\Form\FormEvents; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class UserType extends AbstractType | |||||
{ | |||||
protected $em; | |||||
public function __construct(EntityManagerInterface $entityManager) | |||||
{ | |||||
$this->em = $entityManager; | |||||
} | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$userClass = $this->em->getClassMetadata(UserInterface::class); | |||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) use ($userClass, $options) { | |||||
$builder = $event->getForm()->getParent(); | |||||
$builder->add('user', EntityType::class, array_merge($options,[ | |||||
'class' => $userClass->name, | |||||
'query_builder'=> function (EntityRepository $er) { | |||||
$query = $er->findByMerchantQuery(); | |||||
return $query; | |||||
}, | |||||
'expanded' => false, | |||||
'translation_domain'=>'lcshop', | |||||
])); | |||||
}); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
'translation_domain' => 'lcshop', | |||||
]); | |||||
} | |||||
} |
self::ALIAS_DONE | self::ALIAS_DONE | ||||
] ; | ] ; | ||||
static $statusAliasWaitingDelivery = [ | |||||
self::ALIAS_WAITING_DELIVERY, | |||||
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, | |||||
]; | |||||
static $statusAliasAsCart = [ | static $statusAliasAsCart = [ | ||||
self::ALIAS_CART, | self::ALIAS_CART, | ||||
self::ALIAS_WAITING_PAYMENT_ONLINE, | self::ALIAS_WAITING_PAYMENT_ONLINE, |
$result = $this->findByMerchantQuery() | $result = $this->findByMerchantQuery() | ||||
->orderBy('e.date', 'DESC') ; | ->orderBy('e.date', 'DESC') ; | ||||
$result->andWhere('e.status = 1') ; | |||||
if($maxResults) { | if($maxResults) { | ||||
$result->setMaxResults($maxResults) ; | $result->setMaxResults($maxResults) ; | ||||
} | } |
public function filterOrderValid(?QueryBuilder $query): QueryBuilder | public function filterOrderValid(?QueryBuilder $query): QueryBuilder | ||||
{ | { | ||||
$query->leftJoin('e.orderStatus', 'os'); | |||||
$query->andWhere('os.alias IN (:alias)'); | |||||
$query->setParameter('alias', OrderStatus::$statusAliasAsValid); | |||||
return $this->_filterOrderStatus($query, OrderStatus::$statusAliasAsValid) ; | |||||
} | |||||
return $query; | |||||
public function filterOrderWaitingDelivery($query) | |||||
{ | |||||
return $this->_filterOrderStatus($query, OrderStatus::$statusAliasWaitingDelivery) ; | |||||
} | } | ||||
public function filterOrderCart($query) | public function filterOrderCart($query) | ||||
{ | { | ||||
return $this->_filterOrderStatus($query, OrderStatus::$statusAliasAsCart) ; | |||||
} | |||||
private function _filterOrderStatus($query, $statusArray) { | |||||
$query->leftJoin('e.orderStatus', 'os'); | $query->leftJoin('e.orderStatus', 'os'); | ||||
$query->andWhere('os.alias IN (:alias)'); | $query->andWhere('os.alias IN (:alias)'); | ||||
$query->setParameter('alias', OrderStatus::$statusAliasAsCart); | |||||
return $query; | |||||
$query->setParameter('alias',$statusArray); | |||||
return $query ; | |||||
} | } | ||||
public function findCartCurrent($params) | public function findCartCurrent($params) | ||||
$query = $this->filterOrderValid($query); | $query = $this->filterOrderValid($query); | ||||
} | } | ||||
if (isset($params['isWaitingDelivery'])) { | |||||
$query = $this->filterOrderWaitingDelivery($query); | |||||
} | |||||
if (isset($params['orderStatus'])) { | if (isset($params['orderStatus'])) { | ||||
$query->leftJoin('e.orderStatus', 'os'); | $query->leftJoin('e.orderStatus', 'os'); | ||||
$query->andWhere('os.alias LIKE :alias'); | $query->andWhere('os.alias LIKE :alias'); |
conditions: Conditions d'applications | conditions: Conditions d'applications | ||||
actions: Actions | actions: Actions | ||||
OrderShop: | OrderShop: | ||||
redelivery: Relivraison | |||||
resume: Résumé de commande | resume: Résumé de commande | ||||
addProduct: Ajout de produit à la commande | addProduct: Ajout de produit à la commande | ||||
orderPayment: Ajouter un règlement | orderPayment: Ajouter un règlement | ||||
typeOptions: | typeOptions: | ||||
individual: Particulier | individual: Particulier | ||||
legal-person: Professionnel | legal-person: Professionnel | ||||
OrderProductRedelivery: | |||||
quantityOrder: Quantité commandé | |||||
quantityProduct: Quantité (en rapport à l'unité) | |||||
unit: Unité | |||||
OrderShop: | OrderShop: | ||||
save: Sauvegarder | save: Sauvegarder | ||||
reference: Référence | reference: Référence | ||||
quantityOrder: Quantité commandé | quantityOrder: Quantité commandé | ||||
quantityProduct: Quantité (en rapport à l'unité) | quantityProduct: Quantité (en rapport à l'unité) | ||||
unit: Unité | unit: Unité | ||||
redeliverySupplier: Erreur producteur | |||||
redeliverySupplierOrder: A recommander au producteur | |||||
redeliverySupplierShort: Erreur producteur | |||||
redeliverySupplier: Erreur producteur (Aura un prix à 0€ dans le prohain bon de commande producteur - vous devez cocher à recommander) | |||||
redeliverySupplierOrderShort: À recommander au producteur | |||||
redeliverySupplierOrder: À recommander au producteur (Sera affiché dans le prohain bon de commande producteur) | |||||
deliveryType: Type de livraison | deliveryType: Type de livraison | ||||
deliveryTypeOptions: | deliveryTypeOptions: | ||||
point-sale: En ambassade | point-sale: En ambassade |
{% block label %}{{ "field.default.deliveryAvailabilty"|trans({}, 'lcshop') }}{% endblock %} | {% block label %}{{ "field.default.deliveryAvailabilty"|trans({}, 'lcshop') }}{% endblock %} | ||||
{% block value %} | {% block value %} | ||||
<div v-if="order.deliveryType == 'home'"> | <div v-if="order.deliveryType == 'home'"> | ||||
<div v-html="order.deliveryAvailabilityZone"> | |||||
<div v-html="order.deliveryAvailabilityZone != null ? order.deliveryAvailabilityZone : order.deliveryDate"> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div v-else-if="order.deliveryType == 'point-sale'"> | <div v-else-if="order.deliveryType == 'point-sale'"> | ||||
<div v-html="order.deliveryAvailabilityPointSale"> | |||||
<div v-html="order.deliveryAvailabilityPointSale != null ? order.deliveryAvailabilityPointSale : order.deliveryDate"> | |||||
</div> | </div> | ||||
</div> | </div> | ||||
<div v-else> | <div v-else> |
<?php | <?php | ||||
namespace Lc\ShopBundle\Services ; | |||||
namespace Lc\ShopBundle\Services; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | use Lc\ShopBundle\Context\MerchantUtilsInterface; | ||||
use Lc\ShopBundle\Model\Merchant; | use Lc\ShopBundle\Model\Merchant; | ||||
class MailUtils | class MailUtils | ||||
{ | { | ||||
const SUBJECT = 'subject' ; | |||||
const SUBJECT_PREFIX = 'subject-prefix' ; | |||||
const TO_EMAIL = 'to-email' ; | |||||
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' ; | |||||
protected $transport ; | |||||
protected $templating ; | |||||
protected $parameterBag ; | |||||
protected $merchantUtils ; | |||||
public function __construct(MailjetTransport $mailjetTransport, Environment $templating,ParameterBagInterface $parameterBag, MerchantUtilsInterface $merchantUtils) | |||||
const SUBJECT = 'subject'; | |||||
const SUBJECT_PREFIX = 'subject-prefix'; | |||||
const TO_EMAIL = 'to-email'; | |||||
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'; | |||||
protected $transport; | |||||
protected $templating; | |||||
protected $parameterBag; | |||||
protected $merchantUtils; | |||||
public function __construct(MailjetTransport $mailjetTransport, Environment $templating, ParameterBagInterface $parameterBag, MerchantUtilsInterface $merchantUtils) | |||||
{ | { | ||||
$this->transport = $mailjetTransport ; | |||||
$this->templating = $templating ; | |||||
$this->parameterBag = $parameterBag ; | |||||
$this->merchantUtils = $merchantUtils ; | |||||
$this->transport = $mailjetTransport; | |||||
$this->templating = $templating; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->merchantUtils = $merchantUtils; | |||||
} | } | ||||
public function send($params = []) | public function send($params = []) | ||||
{ | { | ||||
$merchantCurrent = $this->merchantUtils->getMerchantCurrent() ; | |||||
$merchantCurrent = $this->merchantUtils->getMerchantCurrent(); | |||||
$merchantConfigEmailFrom = $merchantCurrent->getMerchantConfig('email-from') ; | |||||
$emailFrom = isset($params[self::FROM_EMAIL]) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom ; | |||||
$merchantConfigEmailFrom = $merchantCurrent->getMerchantConfig('email-from'); | |||||
$emailFrom = isset($params[self::FROM_EMAIL]) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom; | |||||
$merchantConfigEmailFromName = $merchantCurrent->getMerchantConfig('email-from-name') ; | |||||
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName ; | |||||
$merchantConfigEmailFromName = $merchantCurrent->getMerchantConfig('email-from-name'); | |||||
$emailFromName = isset($params[self::FROM_NAME]) ? $params[self::FROM_NAME] : $merchantConfigEmailFromName; | |||||
$merchantConfigEmailSubjectPrefix = $merchantCurrent->getMerchantConfig('email-subject-prefix') ; | |||||
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix ; | |||||
if($emailSubjectPrefix && strlen($emailSubjectPrefix)) { | |||||
$emailSubjectPrefix .= ' ' ; | |||||
$merchantConfigEmailSubjectPrefix = $merchantCurrent->getMerchantConfig('email-subject-prefix'); | |||||
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ? $params[self::SUBJECT_PREFIX] : $merchantConfigEmailSubjectPrefix; | |||||
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) { | |||||
$emailSubjectPrefix .= ' '; | |||||
} | } | ||||
$message = new \Swift_Message($emailSubjectPrefix.$params[self::SUBJECT]); | |||||
$message->addTo( | |||||
$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]) ? $params[self::TO_NAME] : null); | |||||
} else { | |||||
$message->addTo( | |||||
$params[self::TO_EMAIL], | $params[self::TO_EMAIL], | ||||
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null) | |||||
->addFrom($emailFrom, $emailFromName) | |||||
->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])); | |||||
isset($params[self::TO_NAME]) ? $params[self::TO_NAME] : null); | |||||
} | |||||
$message->addFrom($emailFrom, $emailFromName) | |||||
->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::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], | ||||
$params[self::ATTACHMENT_FILENAME], | $params[self::ATTACHMENT_FILENAME], | ||||
)); | )); | ||||
} | } | ||||
$this->transport->send($message) ; | |||||
$this->transport->send($message); | |||||
} | } | ||||
} | } |
namespace Lc\ShopBundle\Services\Order; | namespace Lc\ShopBundle\Services\Order; | ||||
use Lc\ShopBundle\Context\OrderShopInterface; | |||||
use Lc\ShopBundle\Model\OrderStatus; | use Lc\ShopBundle\Model\OrderStatus; | ||||
trait OrderUtilsCartTrait | trait OrderUtilsCartTrait | ||||
{ | { | ||||
public function getCartByUserOrCreateIt($user){ | |||||
$newOrderShop= $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]); | |||||
if ($newOrderShop === null) { | |||||
$newOrderShop = $this->createOrderShop(array( | |||||
'user' => $user, | |||||
'merchant' => $this->merchantUtils->getMerchantUser() | |||||
)); | |||||
} | |||||
return $newOrderShop; | |||||
} | |||||
public function getCartCurrent() | public function getCartCurrent() | ||||
{ | { | ||||
$paramsSearchOrderShop = []; | $paramsSearchOrderShop = []; |