@@ -182,7 +182,6 @@ class AdminController extends EasyAdminController | |||
$dqlFilter = $this->commonDqlFilterQueryBuilder($entityClass, $dqlFilter); | |||
$queryBuilder = parent::createListQueryBuilder($entityClass, $sortDirection, $sortField, $dqlFilter); | |||
$this->commonQueryFilter($entityClass, $queryBuilder); | |||
$listFields = $this->entity['list']['fields']; | |||
$this->filtersForm = $this->createForm(ListFilterType::class, null, array( | |||
@@ -213,8 +212,8 @@ class AdminController extends EasyAdminController | |||
if ($filter !== null) { | |||
if ($this->utils->hasFilterAssociation($field['initProperty'])) { | |||
$aliasRelation = $this->utils->getFilterAssociationAlias($field['initProperty']); | |||
if(array_search($aliasRelation, $queryBuilder->getAllAliases())===false){ | |||
$queryBuilder->innerJoin('entity.'.$aliasRelation, $aliasRelation); | |||
if (array_search($aliasRelation, $queryBuilder->getAllAliases()) === false) { | |||
$queryBuilder->innerJoin('entity.' . $aliasRelation, $aliasRelation); | |||
} | |||
$queryBuilder->andWhere($field['initProperty'] . ' LIKE :' . $field['property'] . ''); | |||
$queryBuilder->setParameter($field['property'], '%' . $filter . '%'); | |||
@@ -232,23 +231,20 @@ class AdminController extends EasyAdminController | |||
if ($filter !== null) { | |||
//TODO Faut généraliser avec TreeInterface, ça ne doit pas être ici | |||
if($field['property'] == 'productCategories') { | |||
if ($field['property'] == 'productCategories') { | |||
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'].' OR product_categories.parent = :' . $field['property']); | |||
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . ' OR product_categories.parent = :' . $field['property']); | |||
$queryBuilder->setParameter($field['property'], $filter); | |||
} | |||
else { | |||
} else { | |||
if ($field['type_options']['multiple']) { | |||
$queryBuilder->andWhere(':' . $field['property'] . ' MEMBER OF entity.' . $field['property'] . ''); | |||
} | |||
else { | |||
} else { | |||
$queryBuilder->andWhere('entity.' . $field['property'] . ' = :' . $field['property'] . ''); | |||
} | |||
if ($filter instanceof TreeInterface && $filter->getParent() == null) { | |||
$queryBuilder->setParameter($field['property'], array_merge(array($filter), $filter->getChildrens()->toArray())); | |||
} | |||
else { | |||
} else { | |||
$queryBuilder->setParameter($field['property'], $filter); | |||
} | |||
} | |||
@@ -604,7 +600,8 @@ class AdminController extends EasyAdminController | |||
$isFilterMerchantInterface = in_array('Lc\ShopBundle\Context\FilterMerchantInterface', $classImplements); | |||
$isFilterMultipleMerchantsInterface = in_array('Lc\ShopBundle\Context\FilterMultipleMerchantsInterface', $classImplements); | |||
if ($isFilterMerchantInterface || $isFilterMultipleMerchantsInterface) { | |||
if (($isFilterMerchantInterface || $isFilterMultipleMerchantsInterface) && (!isset($passedOptions['merchant_filter']) || $passedOptions['merchant_filter'] === true)) { | |||
if (in_array('Lc\ShopBundle\Context\StatusInterface', $classImplements)) { | |||
$statusInterface = true; |
@@ -31,28 +31,31 @@ class NewsController extends AdminController | |||
public function sendTestAction() | |||
{ | |||
$newsletter = $this->getNewsletter() ; | |||
$news = $this->getNews() ; | |||
$merchantCurrent = $this->merchantUtils->getMerchantCurrent() ; | |||
$merchantConfigEmailContact = $merchantCurrent->getMerchantConfig('email-contact'); | |||
if($newsletter) { | |||
$news = $this->getNews() ; | |||
$merchantCurrent = $this->merchantUtils->getMerchantCurrent() ; | |||
$merchantConfigEmailContact = $merchantCurrent->getMerchantConfig('email-contact'); | |||
if($merchantConfigEmailContact && strlen($merchantConfigEmailContact)) { | |||
if($merchantConfigEmailContact && strlen($merchantConfigEmailContact)) { | |||
$this->mailUtils->send([ | |||
MailUtils::SUBJECT => $news->getTitle(), | |||
MailUtils::TO_EMAIL => $merchantConfigEmailContact, | |||
MailUtils::TO_NAME => $this->parameterBag->get('app.site_name'), | |||
MailUtils::CONTENT_TEMPLATE => 'mail/news', | |||
MailUtils::CONTENT_DATA => [ | |||
'news' => $news, | |||
'newsletter' => $newsletter, | |||
'user' => $this->security->getUser() | |||
], | |||
MailUtils::SUBJECT => $news->getTitle(), | |||
MailUtils::TO_EMAIL => $merchantConfigEmailContact, | |||
MailUtils::TO_NAME => $this->parameterBag->get('app.site_name'), | |||
MailUtils::CONTENT_TEMPLATE => 'mail/news', | |||
MailUtils::CONTENT_DATA => [ | |||
'news' => $news, | |||
'newsletter' => $newsletter, | |||
'user' => $this->security->getUser() | |||
], | |||
]); | |||
$this->addFlash('success', 'Actualité de test envoyée à '.$merchantConfigEmailContact); | |||
} | |||
else { | |||
} | |||
else { | |||
throw new \ErrorException("L'email de contact n'est pas défini pour ce Merchant.") ; | |||
} | |||
} | |||
return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ; | |||
@@ -65,77 +68,80 @@ class NewsController extends AdminController | |||
$currentMerchant = $this->merchantUtils->getMerchantCurrent() ; | |||
$newsletter = $this->getNewsletter() ; | |||
$news = $this->getNews() ; | |||
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; | |||
$countUsers = count($users) ; | |||
if($newsletter) { | |||
$news = $this->getNews() ; | |||
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; | |||
$packageMessagesArray = []; | |||
$packageMessageLimit = 50 ; | |||
$countUsers = count($users) ; | |||
$paramsTemplate = [ | |||
$packageMessagesArray = []; | |||
$packageMessageLimit = 50 ; | |||
$paramsTemplate = [ | |||
'news' => $news, | |||
'newsletter' => $newsletter, | |||
'user' => $this->security->getUser() | |||
] ; | |||
] ; | |||
$i = 0 ; | |||
$i = 0 ; | |||
foreach ($users as $user) { | |||
foreach ($users as $user) { | |||
$paramsTemplate['user'] =$user; | |||
if(!isset($packageMessagesArray[$i])) { | |||
$packageMessagesArray[$i] = [] ; | |||
$packageMessagesArray[$i] = [] ; | |||
} | |||
if($user->getEmail() && strlen($user->getEmail())) { | |||
$packageMessagesArray[$i][] = [ | |||
'To' => [ | |||
[ | |||
'Email' => $user->getEmail(), | |||
'Name' => $user->getFirstname().' '.$user->getLastname(), | |||
] | |||
], | |||
'From' => [ | |||
'Email' => $this->getParameter('app.noreply_email'), | |||
'Name' => $this->getParameter('app.site_name') | |||
], | |||
'Subject' => $currentMerchant->getMerchantConfig('email-subject-prefix').' '.$news->getTitle(), | |||
'TextPart' => $this->renderView('mail/news-text.html.twig', $paramsTemplate), | |||
'HTMLPart' => $this->renderView('mail/news-html.html.twig', $paramsTemplate), | |||
'CustomCampaign' => $news->getTitle(), | |||
'DeduplicateCampaign' => true | |||
] ; | |||
if(count($packageMessagesArray[$i]) >= $packageMessageLimit) { | |||
$i ++ ; | |||
} | |||
$packageMessagesArray[$i][] = [ | |||
'To' => [ | |||
[ | |||
'Email' => $user->getEmail(), | |||
'Name' => $user->getFirstname().' '.$user->getLastname(), | |||
] | |||
], | |||
'From' => [ | |||
'Email' => $this->getParameter('app.noreply_email'), | |||
'Name' => $this->getParameter('app.site_name') | |||
], | |||
'Subject' => $currentMerchant->getMerchantConfig('email-subject-prefix').' '.$news->getTitle(), | |||
'TextPart' => $this->renderView('mail/news-text.html.twig', $paramsTemplate), | |||
'HTMLPart' => $this->renderView('mail/news-html.html.twig', $paramsTemplate), | |||
'CustomCampaign' => $news->getTitle(), | |||
'DeduplicateCampaign' => true | |||
] ; | |||
if(count($packageMessagesArray[$i]) >= $packageMessageLimit) { | |||
$i ++ ; | |||
} | |||
} | |||
} | |||
} | |||
if($countUsers > 0) { | |||
if($countUsers > 0) { | |||
$mj = new \Mailjet\Client($this->mailjetTransport->getApiKey(), $this->mailjetTransport->getApiSecret(),true,['version' => 'v3.1']); | |||
foreach($packageMessagesArray as $messagesArray) { | |||
$body = [ | |||
'Messages' => $messagesArray | |||
]; | |||
$response = $mj->post(Resources::$Email, ['body' => $body]); | |||
$body = [ | |||
'Messages' => $messagesArray | |||
]; | |||
$response = $mj->post(Resources::$Email, ['body' => $body]); | |||
} | |||
if(isset($response) && $response->success()) { | |||
$this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.'); | |||
$this->addFlash('success', 'Actualité envoyée à '.$countUsers.' utilisateurs.'); | |||
$news->setIsSent(true) ; | |||
$this->em->persist($news); | |||
$this->em->flush() ; | |||
$news->setIsSent(true) ; | |||
$this->em->persist($news); | |||
$this->em->flush() ; | |||
} | |||
else { | |||
$this->addFlash('error', "Une erreur est survenue lors de l'envoi de l'actualité."); | |||
$this->addFlash('error', "Une erreur est survenue lors de l'envoi de l'actualité."); | |||
} | |||
} | |||
else { | |||
} | |||
else { | |||
$this->addFlash('error', 'Aucun utilisateur inscrit à la newsletter.'); | |||
} | |||
} | |||
return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ; | |||
@@ -143,13 +149,17 @@ class NewsController extends AdminController | |||
public function getNewsletter() | |||
{ | |||
$newsletter = $this->merchantUtils->getMerchantCurrent()->getNewsletter() ; | |||
$news = $this->getNews() ; | |||
if($newsletter) { | |||
return $newsletter ; | |||
if($news) { | |||
$newsletter = $news->getNewsletter() ; | |||
} | |||
if(isset($newsletter) && $newsletter) { | |||
return $newsletter ; | |||
} | |||
else { | |||
throw new \ErrorException('Aucune newsletter n\'est liée à ce Merchant.') ; | |||
$this->utils->addFlash('error', 'Aucune newsletter n\'est liée à l\'actualité.'); | |||
} | |||
} | |||
@@ -459,7 +459,6 @@ class OrderController extends AdminController | |||
$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView(); | |||
break; | |||
case OrderStatus::ALIAS_ERROR_PAYMENT_ONLINE : | |||
case OrderStatus::ALIAS_WAITING_PAYMENT_CREDIT : | |||
case OrderStatus::ALIAS_WAITING_PAYMENT_ONLINE : | |||
$parameters['form_order_send_payment_link'] = $this->createCustomForm(OrderSendPaymentLink::class, 'orderSendPaymentLink', $parameters)->createView(); | |||
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); | |||
@@ -467,8 +466,7 @@ class OrderController extends AdminController | |||
$parameters['form_order_status'] = $this->createCustomForm(OrderStatusType::class, 'orderStatus', $parameters)->createView(); | |||
$parameters['form_order_invoice_address'] = $this->createCustomForm(OrderInvoiceAddressType::class, 'orderInvoiceAddress', $parameters)->createView(); | |||
break; | |||
case OrderStatus::ALIAS_PAID_BY_CREDIT : | |||
case OrderStatus::ALIAS_PAID_ONLINE : | |||
case OrderStatus::ALIAS_PAID : | |||
case OrderStatus::ALIAS_WAITING_DELIVERY : | |||
case OrderStatus::ALIAS_WAITING_BANK_RETURN : | |||
$parameters['form_order_payment'] = $this->createCustomForm(OrderPaymentType::class, 'orderPayment', $parameters, false)->createView(); |
@@ -2,7 +2,9 @@ | |||
namespace Lc\ShopBundle\Controller\Backend; | |||
use App\Entity\OrderShop; | |||
use App\Form\Backend\Common\AddressType; | |||
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | |||
use FOS\UserBundle\Doctrine\UserManager; | |||
use FOS\UserBundle\Model\UserManagerInterface ; | |||
use Lc\ShopBundle\Context\AddressInterface; | |||
@@ -11,6 +13,47 @@ use Lc\ShopBundle\Model\Address; | |||
class UserController extends AdminController | |||
{ | |||
public function showAction() | |||
{ | |||
$id = $this->request->query->get('id'); | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$entity = $easyadmin['item']; | |||
$this->orderShoprepo = $this->em->getRepository(OrderShop::class); | |||
/* dump($this->orderUtils->getRankTotalOrder($entity)); | |||
die(); | |||
dump($this->orderUtils->getRankSumOrderByUser($entity)); | |||
dump($this->orderUtils->getRankTotalOrderByUser($entity)); | |||
dump($this->orderUtils->getTotalSpentByUser($entity)); | |||
dump($this->orderUtils->getAverageOrderByUser($entity)); | |||
die();*/ | |||
$this->dispatch(EasyAdminEvents::PRE_SHOW); | |||
$fields = $this->entity['show']['fields']; | |||
$deleteForm = $this->createDeleteForm($this->entity['name'], $id); | |||
$this->dispatch(EasyAdminEvents::POST_SHOW, [ | |||
'deleteForm' => $deleteForm, | |||
'fields' => $fields, | |||
'entity' => $entity, | |||
]); | |||
$parameters = [ | |||
'entity' => $entity, | |||
'fields' => $fields, | |||
'delete_form' => $deleteForm->createView(), | |||
]; | |||
return $this->executeDynamicMethod('render<EntityName>Template', ['show', $this->entity['templates']['show'], $parameters]); | |||
} | |||
public function createNewEntity() | |||
{ | |||
return $this->userManager->createUser(); |
@@ -0,0 +1,32 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Event\EntityManager; | |||
use Symfony\Contracts\EventDispatcher\Event; | |||
/** | |||
* class EntityEvent. | |||
* | |||
* @author Simon Vieille <simon@deblan.fr> | |||
*/ | |||
class EntityManagerEvent extends Event | |||
{ | |||
const CREATE_EVENT = 'entity_manager_event.create'; | |||
const UPDATE_EVENT = 'entity_manager_event.update'; | |||
const DELETE_EVENT = 'entity_manager_event.delete'; | |||
const PRE_CREATE_EVENT = 'entity_manager_event.pre_create'; | |||
const PRE_UPDATE_EVENT = 'entity_manager_event.pre_update'; | |||
const PRE_DELETE_EVENT = 'entity_manager_event.pre_delete'; | |||
protected $entity; | |||
public function __construct($entity) | |||
{ | |||
$this->entity = $entity; | |||
} | |||
public function getEntity() | |||
{ | |||
return $this->entity; | |||
} | |||
} |
@@ -0,0 +1,35 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Event\OrderShop; | |||
use Symfony\Contracts\EventDispatcher\Event; | |||
/** | |||
* class EntityEvent. | |||
* | |||
* @author Simon Vieille <simon@deblan.fr> | |||
*/ | |||
class OrderShopChangeStatusEvent extends Event | |||
{ | |||
const PRE_CHANGE_STATUS = 'order_shop_event.pre_change_status'; | |||
const POST_CHANGE_STATUS = 'order_shop_event.post_change_status'; | |||
protected $orderShop; | |||
protected $orderStatus; | |||
public function __construct($orderShop, $orderStatus) | |||
{ | |||
$this->orderShop = $orderShop; | |||
$this->orderStatus = $orderStatus; | |||
} | |||
public function getOrderShop() | |||
{ | |||
return $this->orderShop; | |||
} | |||
public function getOrderStatus() | |||
{ | |||
return $this->orderStatus; | |||
} | |||
} |
@@ -0,0 +1,17 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form\Backend\Common; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType as DefaultEntityType; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class EntityType extends DefaultEntityType | |||
{ | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
parent::configureOptions($resolver); | |||
$resolver->setDefaults([ | |||
'merchant_filter' => true | |||
]); | |||
} | |||
} |
@@ -0,0 +1,42 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form\Backend\Common; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\NewsletterInterface; | |||
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 NewslettersType extends AbstractType | |||
{ | |||
protected $em; | |||
public function __construct(EntityManagerInterface $entityManager){ | |||
$this->em = $entityManager; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { | |||
$builder = $event->getForm()->getParent(); | |||
$newsletterClass = $this->em->getClassMetadata(NewsletterInterface::class); | |||
$builder->add('newsletters', EntityType::class, [ | |||
'class' => $newsletterClass->getName(), | |||
'multiple' =>true, | |||
'required' => false, | |||
'merchant_filter'=> false | |||
]); | |||
}); | |||
} | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults([ | |||
'merchant_filter' => false | |||
]); | |||
} | |||
} |
@@ -0,0 +1,41 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Form\DataTransformer; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Services\UtilsManager; | |||
use Symfony\Component\Form\DataTransformerInterface; | |||
use Symfony\Component\Form\Exception\TransformationFailedException; | |||
use Symfony\Component\Security\Core\Security; | |||
class NewsletterSignupToBooleanTransformer implements DataTransformerInterface | |||
{ | |||
private $security ; | |||
private $userUtils ; | |||
public function __construct(Security $security, UtilsManager $utilsManager) | |||
{ | |||
$this->security = $security; | |||
$this->userUtils = $utilsManager->getUserUtils() ; | |||
} | |||
public function transform($newsletter) | |||
{ | |||
$user = $this->security->getUser() ; | |||
if($user && $newsletter) { | |||
return $this->userUtils->isSubscribedToNewsletter($user, $newsletter) ; | |||
} | |||
return false ; | |||
} | |||
public function reverseTransform($isSubscribed) | |||
{ | |||
// Impossible de retrouver la newsletter depuis sa valeur booléenne. | |||
//throw new TransformationFailedException('Impossible de retrouver la newsletter depuis sa valeur booléenne.') ; | |||
return false ; | |||
} | |||
} |
@@ -17,6 +17,7 @@ class RegistrationType extends AbstractType | |||
public function __construct(UtilsManager $utilsManager) | |||
{ | |||
$this->utils = $utilsManager->getUtils() ; | |||
$this->merchantUtils = $utilsManager->getMerchantUtils() ; | |||
} | |||
public function getParent() | |||
@@ -26,6 +27,8 @@ class RegistrationType extends AbstractType | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$newsletters = $this->merchantUtils->getMerchantCurrent()->getNewsletters() ; | |||
$builder->remove('username') | |||
->add('gender', ChoiceType::class, [ | |||
'label' => 'field.default.title', | |||
@@ -48,16 +51,19 @@ class RegistrationType extends AbstractType | |||
->add('phone', TextType::class, [ | |||
'label' => 'field.default.phone', | |||
'translation_domain' => 'lcshop', | |||
]) | |||
->add('subscribeNewsletter', CheckboxType::class, [ | |||
'data' => true, | |||
'label' => 'field.default.subscribeNewsletter', | |||
'required' => false, | |||
'mapped' => false, | |||
'translation_domain' => 'lcshop', | |||
'help' => 'Un seul mail par semaine qui annonce l’ouverture des ventes, les nouveautés et promotions de la semaine ainsi que des informations utiles.' | |||
]); | |||
foreach($newsletters as $newsletter) { | |||
$builder->add('newsletter_'.$newsletter->getId(), CheckboxType::class, [ | |||
//'label' => 'field.default.subscribeNewsletter', | |||
'label' => $newsletter->getTitle(), | |||
'required' => false, | |||
'mapped' => false, | |||
'translation_domain' => 'lcshop', | |||
'help' => $newsletter->getDescription() | |||
]); | |||
} | |||
// captcha | |||
$this->utils->addCaptchaType($builder); | |||
} |
@@ -23,6 +23,7 @@ class TicketType extends AbstractType | |||
protected $security ; | |||
protected $em ; | |||
protected $priceUtils ; | |||
protected $utils ; | |||
public function __construct(Security $security, EntityManagerInterface $em, UtilsManager $utilsManager) | |||
{ | |||
@@ -30,6 +31,7 @@ class TicketType extends AbstractType | |||
$this->em = $em ; | |||
$this->orderShopRepository = $this->em->getRepository(OrderShop::class) ; | |||
$this->priceUtils = $utilsManager->getPriceUtils() ; | |||
$this->utils = $utilsManager->getUtils() ; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
@@ -83,13 +85,11 @@ class TicketType extends AbstractType | |||
]) ; | |||
} | |||
else { | |||
// captcha (honey pot) | |||
$builder->add('body', TextType::class, [ | |||
'label' => 'Body', | |||
'required' => false, | |||
]) ; | |||
// captcha | |||
$this->utils->addCaptchaType($builder); | |||
} | |||
$builder->add('subject', TextType::class, [ | |||
'label' => 'Sujet' | |||
]) |
@@ -0,0 +1,127 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Manager; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Event\EntityManager\EntityManagerEvent; | |||
use Symfony\Component\EventDispatcher\EventDispatcherInterface; | |||
use Symfony\Component\Security\Core\Security; | |||
/** | |||
* class EntityManager. | |||
* | |||
* @author Simon Vieille <simon@deblan.fr> | |||
*/ | |||
class EntityManager | |||
{ | |||
protected $eventDispatcher; | |||
protected $entityManager; | |||
protected $security; | |||
protected $userSystem = null; | |||
public function __construct(EventDispatcherInterface $eventDispatcher, EntityManagerInterface $entityManager, | |||
Security $security) | |||
{ | |||
$this->eventDispatcher = $eventDispatcher; | |||
$this->entityManager = $entityManager; | |||
$this->security = $security; | |||
} | |||
public function getUserSystem() | |||
{ | |||
if ($this->userSystem === null) { | |||
$this->userSystem = $this->getRepository(UserInterface::class)->findOneByDevAlias('system'); | |||
} | |||
return $this->userSystem; | |||
} | |||
public function getRepository($className) | |||
{ | |||
return $this->entityManager->getRepository($this->getEntityName($className)); | |||
} | |||
public function create($entity): self | |||
{ | |||
if ($this->security->getUser() === null) { | |||
if(method_exists($entity, 'setUpdatedBy')) { | |||
$entity->setUpdatedBy($this->getUserSystem()); | |||
} | |||
if(method_exists($entity, 'setCreatedBy')) { | |||
$entity->setCreatedBy($this->getUserSystem()); | |||
} | |||
} | |||
$this->persist($entity); | |||
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::CREATE_EVENT); | |||
return $this; | |||
} | |||
public function update($entity): self | |||
{ | |||
if ($this->security->getUser() === null) { | |||
$entity->setUpdatedBy($this->getUserSystem()); | |||
} | |||
$this->persist($entity); | |||
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::UPDATE_EVENT); | |||
return $this; | |||
} | |||
public function delete($entity): self | |||
{ | |||
$this->remove($entity); | |||
$this->eventDispatcher->dispatch(new EntityManagerEvent($entity), EntityManagerEvent::DELETE_EVENT); | |||
return $this; | |||
} | |||
public function remove($entity): self | |||
{ | |||
$this->entityManager->remove($entity) ; | |||
return $this ; | |||
} | |||
public function flush(): self | |||
{ | |||
$this->entityManager->flush(); | |||
return $this; | |||
} | |||
public function clear(): self | |||
{ | |||
$this->entityManager->clear(); | |||
return $this; | |||
} | |||
public function persist($entity) | |||
{ | |||
$this->entityManager->persist($entity); | |||
} | |||
public function refresh($entity) | |||
{ | |||
$this->entityManager->refresh($entity); | |||
} | |||
public function getClassMetadata($className) | |||
{ | |||
return $this->entityManager->getClassMetadata($className) ; | |||
} | |||
public function getEntityName($className) | |||
{ | |||
if (substr($className, -9) === 'Interface') { | |||
return $this->entityManager->getClassMetadata($className)->getName(); | |||
} | |||
else { | |||
return $className; | |||
} | |||
} | |||
} |
@@ -38,17 +38,11 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn | |||
*/ | |||
protected $description; | |||
/** | |||
* @ORM\Column(type="string", length=255, nullable=true) | |||
*/ | |||
protected $devAlias; | |||
public function getTitle(): ?string | |||
{ | |||
return $this->title; | |||
@@ -74,8 +68,6 @@ abstract class AbstractDocumentEntity extends AbstractEntity implements StatusIn | |||
return $this; | |||
} | |||
public function getDevAlias(): ?string | |||
{ | |||
return $this->devAlias; |
@@ -349,9 +349,13 @@ abstract class Merchant extends AbstractDocumentEntity | |||
public function getNewsletter() | |||
{ | |||
$newsletters = $this->getNewsletters() ; | |||
if(isset($newsletters[0])) { | |||
return $newsletters[0] ; | |||
foreach($newsletters as $newsletter) { | |||
if($newsletter->getIsMain()) { | |||
return $newsletter ; | |||
} | |||
} | |||
return false ; | |||
} | |||
@@ -24,6 +24,11 @@ abstract class Newsletter extends AbstractDocumentEntity implements FilterMercha | |||
*/ | |||
protected $users; | |||
/** | |||
* @ORM\Column(type="boolean", nullable=true) | |||
*/ | |||
protected $isMain; | |||
public function __toString() | |||
{ | |||
return $this->getTitle() ; | |||
@@ -73,4 +78,16 @@ abstract class Newsletter extends AbstractDocumentEntity implements FilterMercha | |||
return $this; | |||
} | |||
public function getIsMain(): ?bool | |||
{ | |||
return $this->isMain; | |||
} | |||
public function setIsMain(?bool $isMain): self | |||
{ | |||
$this->isMain = $isMain; | |||
return $this; | |||
} | |||
} |
@@ -23,7 +23,7 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa | |||
protected $merchant; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders") | |||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="orders", fetch="EAGER") | |||
*/ | |||
protected $user; | |||
@@ -73,7 +73,7 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa | |||
protected $orderPayments; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", cascade={"persist", "remove"}, orphanRemoval=true) | |||
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\OrderProductInterface", mappedBy="orderShop", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EAGER") | |||
*/ | |||
protected $orderProducts; | |||
@@ -303,8 +303,20 @@ abstract class OrderShop extends AbstractEntity implements FilterMerchantInterfa | |||
/** | |||
* @return Collection|OrderPayment[] | |||
*/ | |||
public function getOrderPayments(): Collection | |||
public function getOrderPayments($meanPayment = null): Collection | |||
{ | |||
if($meanPayment) { | |||
$orderPaymentsReturn = new ArrayCollection() ; | |||
foreach($this->orderPayments as $orderPayment) { | |||
if($orderPayment->getMeanPayment() == $meanPayment) { | |||
$orderPaymentsReturn[] = $orderPayment ; | |||
} | |||
} | |||
return $orderPaymentsReturn ; | |||
} | |||
return $this->orderPayments; | |||
} | |||
@@ -14,11 +14,10 @@ abstract class OrderStatus | |||
const ALIAS_CART = 'cart' ; | |||
const ALIAS_CART_CANCELED = 'cart-canceled' ; | |||
const ALIAS_WAITING_PAYMENT_ONLINE = 'waiting-payment-online' ; | |||
const ALIAS_WAITING_PAYMENT_CREDIT = 'waiting-payment-credit' ; | |||
const ALIAS_WAITING_BANK_RETURN = 'waiting-bank-return' ; | |||
const ALIAS_PAID_ONLINE = 'paid-online' ; | |||
const ALIAS_PARTIAL_PAYMENT = 'partial-payment' ; | |||
const ALIAS_PAID = 'paid' ; | |||
const ALIAS_ERROR_PAYMENT_ONLINE = 'error-payment-online' ; | |||
const ALIAS_PAID_BY_CREDIT = 'paid-by-credit' ; | |||
const ALIAS_WAITING_DELIVERY = 'waiting-delivery' ; | |||
const ALIAS_WAITING_DELIVERY_WITH_PAYMENT = 'waiting-delivery-with-payment' ; | |||
const ALIAS_DELIVERED_WITHOUT_PAYMENT = 'delivered-without-payment' ; | |||
@@ -30,8 +29,7 @@ abstract class OrderStatus | |||
//TODO : AJOUTER un champ valid ds orderSTATUS | |||
static $statusAliasAsValid = [ | |||
self::ALIAS_PAID_ONLINE, | |||
self::ALIAS_PAID_BY_CREDIT, | |||
self::ALIAS_PAID, | |||
self::ALIAS_WAITING_DELIVERY, | |||
self::ALIAS_WAITING_BANK_RETURN, | |||
self::ALIAS_WAITING_DELIVERY_WITH_PAYMENT, | |||
@@ -46,8 +44,8 @@ abstract class OrderStatus | |||
static $statusAliasAsCart = [ | |||
self::ALIAS_CART, | |||
self::ALIAS_PARTIAL_PAYMENT, | |||
self::ALIAS_WAITING_PAYMENT_ONLINE, | |||
self::ALIAS_WAITING_PAYMENT_CREDIT, | |||
self::ALIAS_ERROR_PAYMENT_ONLINE | |||
]; | |||
@@ -66,6 +66,10 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod | |||
$title .= ' - ' . $this->getTitle(); | |||
} | |||
if($this->getProductFamily()->hasProductsWithVariousWeight()) { | |||
$title .= ' - '.$this->getQuantityLabelInherited() ; | |||
} | |||
return $title; | |||
} | |||
@@ -15,8 +15,8 @@ use Lc\ShopBundle\Context\StatusInterface; | |||
*/ | |||
abstract class ReductionCredit extends AbstractEntity implements ReductionInterface, FilterMerchantInterface, StatusInterface | |||
{ | |||
const TYPE_CREDIT = 'credit' ; | |||
const TYPE_GIFT = 'gift' ; | |||
const TYPE_CREDIT = 'credit'; | |||
const TYPE_GIFT = 'gift'; | |||
use ReductionTrait; | |||
@@ -29,10 +29,11 @@ abstract class ReductionCredit extends AbstractEntity implements ReductionInterf | |||
protected $title; | |||
/** | |||
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\UserInterface") | |||
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\UserInterface", inversedBy="reductionCredits") | |||
*/ | |||
protected $users; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\MerchantInterface") | |||
* @ORM\JoinColumn(nullable=false) | |||
@@ -90,6 +91,19 @@ abstract class ReductionCredit extends AbstractEntity implements ReductionInterf | |||
return $this; | |||
} | |||
public function getType(): ?string | |||
{ | |||
return $this->type; | |||
} | |||
public function setType(string $type): self | |||
{ | |||
$this->type = $type; | |||
return $this; | |||
} | |||
/** | |||
* @return Collection|User[] | |||
*/ | |||
@@ -116,20 +130,6 @@ abstract class ReductionCredit extends AbstractEntity implements ReductionInterf | |||
return $this; | |||
} | |||
public function getType(): ?string | |||
{ | |||
return $this->type; | |||
} | |||
public function setType(string $type): self | |||
{ | |||
$this->type = $type; | |||
return $this; | |||
} | |||
public function getSended(): ?bool | |||
{ |
@@ -44,7 +44,6 @@ abstract class User extends UserModelFOS | |||
*/ | |||
protected $orders; | |||
/** | |||
* @ORM\Column(type="string", length=64, nullable=true) | |||
*/ | |||
@@ -108,6 +107,11 @@ abstract class User extends UserModelFOS | |||
protected $ticketTypesNotification = []; | |||
/** | |||
* @ORM\ManyToMany(targetEntity="Lc\ShopBundle\Context\ReductionCreditInterface", mappedBy="users") | |||
*/ | |||
protected $reductionCredits; | |||
public function __construct() | |||
{ | |||
@@ -119,6 +123,8 @@ abstract class User extends UserModelFOS | |||
$this->favoriteProductFamilies = new ArrayCollection(); | |||
$this->userPointSales = new ArrayCollection(); | |||
$this->userMerchants = new ArrayCollection(); | |||
$this->reductionCredits = new ArrayCollection(); | |||
$this->tickets = new ArrayCollection(); | |||
} | |||
public function __toString() | |||
@@ -464,4 +470,33 @@ abstract class User extends UserModelFOS | |||
return $this; | |||
} | |||
/** | |||
* @return Collection|ReductionCredit[] | |||
*/ | |||
public function getReductionCredits(): Collection | |||
{ | |||
return $this->reductionCredits; | |||
} | |||
public function addReductionCredit(ReductionCredit $reductionCredit): self | |||
{ | |||
if (!$this->reductionCredits->contains($reductionCredit)) { | |||
$this->reductionCredits[] = $reductionCredit; | |||
$reductionCredit->addUser($this); | |||
} | |||
return $this; | |||
} | |||
public function removeReductionCredit(ReductionCredit $reductionCredit): self | |||
{ | |||
if ($this->reductionCredits->contains($reductionCredit)) { | |||
$this->reductionCredits->removeElement($reductionCredit); | |||
$reductionCredit->removeUser($this); | |||
} | |||
return $this; | |||
} | |||
} |
@@ -66,11 +66,12 @@ class BaseRepository extends EntityRepository implements ServiceEntityRepository | |||
return $qb->getQuery()->getOneOrNullResult(); | |||
} | |||
public function findByMerchantQuery() :QueryBuilder | |||
public function findByMerchantQuery($merchant = null) :QueryBuilder | |||
{ | |||
if($merchant === false || $merchant===null)$merchant = $this->merchantUtils->getMerchantCurrent(); | |||
return $this->createQueryBuilder('e') | |||
->where('e.merchant = :currentMerchant') | |||
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId()) ; | |||
->setParameter('currentMerchant', $merchant) ; | |||
} | |||
public function findAll() |
@@ -4,6 +4,7 @@ namespace Lc\ShopBundle\Repository; | |||
use App\Entity\DeliveryAvailabilityPointSale; | |||
use App\Entity\DeliveryAvailabilityZone; | |||
use App\Entity\PointSale; | |||
use Doctrine\ORM\Query\Expr\Join; | |||
use Doctrine\ORM\QueryBuilder; | |||
use Lc\ShopBundle\Context\DefaultRepositoryInterface; | |||
@@ -118,7 +119,12 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
public function findAllBy($params = []) | |||
{ | |||
$query = $this->findByMerchantQuery(); | |||
if(isset($params['merchant'])){ | |||
$query = $this->findByMerchantQuery($params['merchant']); | |||
}else{ | |||
$query = $this->findByMerchantQuery(); | |||
} | |||
if (isset($params['count']) && $params['count']) { | |||
$query->select('count(e.id)'); | |||
@@ -232,11 +238,11 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
} | |||
if($setParameterHorsTournee) { | |||
$query->setParameter('devAliasHorsTournee', 'horstournee') ; | |||
$query->setParameter('devAliasHorsTournee', PointSale::DEV_ALIAS_OFF_CIRCUIT) ; | |||
} | |||
if($setParameterGiftVoucher) { | |||
$query->setParameter('devAliasGiftVoucher', 'giftvoucher') ; | |||
$query->setParameter('devAliasGiftVoucher', PointSale::DEV_ALIAS_GIFT_VOUCHER) ; | |||
} | |||
if (isset($params['deliveryAvailability'])) { | |||
@@ -307,20 +313,5 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
} | |||
public function countValidOrderProductsOfWeekByProduct($weekNumber, $productId) | |||
{ | |||
$query = $this->findByMerchantQuery(); | |||
$query = $this->filterOrderValid($query); | |||
$query->andWhere('e.weekNumber = :weekNumber'); | |||
$query->setParameter('weekNumber', $weekNumber); | |||
$query->leftJoin('e.orderProducts', 'orderProduct'); | |||
$query->andWhere('orderProduct.product = :product'); | |||
$query->setParameter('product', $productId); | |||
$query->select('SUM(orderProduct.quantityOrder) as quantity'); | |||
$result = $query->getQuery()->getOneOrNullResult(); | |||
return $result['quantity']; | |||
} | |||
} |
@@ -71,7 +71,7 @@ class ReductionCartRepository extends BaseRepository implements DefaultRepositor | |||
foreach($reductionCarts as $reductionCart) { | |||
if($this->orderUtils->isReductionCartMatchWithUser($reductionCart, $user) | |||
&& $this->orderUtils->isReductionCartMatchWithGroupUser($reductionCart, $user) | |||
&& $this->orderUtils->countReductionCartAvailableForUser($reductionCart, $user) | |||
&& $this->orderUtils->getReductionCartRemainingQuantityPerUser($reductionCart, $user) | |||
&& ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) { | |||
$reductionCartsArray[] = $reductionCart ; |
@@ -19,12 +19,13 @@ class UserRepository extends BaseRepository implements DefaultRepositoryInterfac | |||
return UserInterface::class; | |||
} | |||
public function findByMerchantQuery() :QueryBuilder | |||
public function findByMerchantQuery($merchant = null) :QueryBuilder | |||
{ | |||
if($merchant === false || $merchant===null)$merchant = $this->merchantUtils->getMerchantCurrent(); | |||
return $this->createQueryBuilder('e') | |||
->innerJoin('e.userMerchants', "userMerchants") | |||
->andWhere('userMerchants.merchant = :currentMerchant') | |||
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId()) ; | |||
->setParameter('currentMerchant', $merchant) ; | |||
} | |||
public function findAllByNewsletter($newsletter) |
@@ -18,4 +18,13 @@ class VisitorRepository extends BaseRepository implements DefaultRepositoryInter | |||
return VisitorInterface::class; | |||
} | |||
public function findOldVisitors($date){ | |||
$qb = $this->createQueryBuilder('v'); | |||
$qb->where('v.lastAccess < :date'); | |||
$qb->andWhere('v.totalVisit = 1'); | |||
$qb->setParameter('date', $date); | |||
return $qb->getQuery()->getResult(); | |||
} | |||
} |
@@ -26,9 +26,14 @@ function initDeleteAction() { | |||
}); | |||
/* $('.action-confirm').each(function () { | |||
$(this).on('click', function (e) { | |||
return confirm("Êtes vous sur de vouloir effectuer cette action ?"); | |||
}); | |||
});*/ | |||
$('.action-duplicate').each(function () { | |||
$(this).on('click', function (e) { | |||
return confirm("Press a button!"); | |||
return confirm("Êtes vous sur de vouloir effectuer cette action ?"); | |||
}); | |||
}); | |||
} |
@@ -115,7 +115,7 @@ appOrder = new Vue({ | |||
} | |||
}, | |||
preventFormSubmit: function (){ | |||
$(document).keypress(function(e) { | |||
$('#lc-order-edit').keypress(function(e) { | |||
if (e.which == 13) { | |||
e.preventDefault(); | |||
} |
@@ -31,6 +31,7 @@ body{font-size: 0.9rem;} | |||
a.link-as-text{color:#333;} | |||
.badge{font-size: 90%;} | |||
/***************************************** ADMIN SIDEBAR ***************************************/ | |||
.main-sidebar p{font-size: 0.8rem;} |
@@ -23,6 +23,8 @@ group: | |||
default: Édition | |||
Général: Général | |||
Adresse: Adresse | |||
Redelivery: | |||
list: Liste des relivraisons | |||
Supplier: | |||
contact: Personne de contact | |||
Reminder: | |||
@@ -53,10 +55,13 @@ group: | |||
ReductionCatalog: | |||
info: Informations principal | |||
conditions: Conditions d'application | |||
ReductionCredit: | |||
list: Liste des avoirs | |||
ReductionCart: | |||
info: Informations | |||
conditions: Conditions d'applications | |||
actions: Actions | |||
list: Liste des réductions paniers | |||
OrderShop: | |||
redelivery: Relivraison | |||
resume: Résumé de commande | |||
@@ -72,6 +77,8 @@ group: | |||
tickets: Tickets relatif à la commande | |||
orderStatusHistories: Historique de changement de statut | |||
waitingBankReturn: Commandes en attente de retour banque | |||
list: Liste des commandes | |||
giftVoucher: Commandes de bons cadeaux | |||
Ticket: | |||
listMessages: Liste des messages | |||
list: Tickets ouverts | |||
@@ -89,6 +96,11 @@ group: | |||
lunch: Repas du midi | |||
Address: | |||
listLoopBesancon: Adresses de Besançon à spécifier (lat / long) | |||
User: | |||
item: Utilisateur | |||
Notification: | |||
main: Notifications | |||
None: Aucune valeur | |||
@@ -131,10 +143,11 @@ error: | |||
deliverySlotMissing: Vous n'avez pas de créneau de livraison | |||
productUnavailable: Certains produits ne sont plus disponibles | |||
nextStatusNotAllow: La commande ne peut passer à ce statut | |||
noPayment: Le montant de la commande n'a pas été règlé dans sa totalité | |||
incompletePayment: Le montant de la commande n'a pas été règlé dans sa totalité | |||
otherOrderAlreadyExist: Une autre commande existe déjà pour cet utilisateur, vous avez été redirigé. | |||
minimumAmountZone: Montant minimum de commande non respecté pour cette zone | |||
minimumAmountPointSale: Montant minimum de commande non respecté pour ce point de vente | |||
noPayment: Aucun paiement n'a été enregistré pour cette commande | |||
reductionCart: | |||
conditionsError: Cette réduction ne peut pas être appliqué sur cette commande | |||
date: La réduction n'est plus active | |||
@@ -297,6 +310,8 @@ field: | |||
displaySpecificDay: Disponible un jour spécifique | |||
groupUsers: Groupes | |||
ticketTypesNotification: Catégorie ticket | |||
newsletter: Newsletter | |||
isEligibleTicketRestaurant: Éligible ticket restaurant | |||
PointSale: | |||
code: Code |
@@ -0,0 +1,11 @@ | |||
<div class="small-box {% block class %}bg-info{% endblock %}"> | |||
<div class="inner"> | |||
<h3>{% block value %}{% endblock %}</h3> | |||
<p>{% block label %}{% endblock %}</p> | |||
<div class="icon"> | |||
<i class="fa fa-{% block icon %}bg-info{% endblock %}"></i> | |||
</div> | |||
</div> | |||
</div> |
@@ -0,0 +1,27 @@ | |||
<table class="table table-condensed" id="address-list"> | |||
<thead> | |||
<tr> | |||
<th>Id</th> | |||
<th>Utilisateurs</th> | |||
<th>Date</th> | |||
<th></th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
{% for order in orderShopsWeekGiftVoucher %} | |||
<tr> | |||
<td>{{ order.id }}</td> | |||
<td>{{ order.user }}</td> | |||
<td>{{ order.updatedAt|date('d-m H:i') }}</td> | |||
<td><a class="btn-sm btn-success" | |||
href="{{ path('easyadmin', {id: order.id, entity: 'OrderShop', action: 'show'}) }}"> | |||
<i class="fas fa-eye"></i> | |||
</a></td> | |||
</tr> | |||
{% else %} | |||
<tr> | |||
<td colspan="4"><i>Aucune commande de bons cadeaux</i></td> | |||
{% endfor %} | |||
</tbody> | |||
</table> | |||
@@ -1,31 +0,0 @@ | |||
<table class="table table-condensed" id="ticket-list"> | |||
<thead> | |||
<tr> | |||
<th>Sujet</th> | |||
<th>Statut</th> | |||
<th>Dernier message</th> | |||
<th></th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
{% for ticket in tickets %} | |||
<tr> | |||
<td>{{ ticket.subject }}</td> | |||
<td> | |||
{% set value = ticket.status %} | |||
{% include '@LcShop/backend/default/field/ticket_status.html.twig' %} | |||
</td> | |||
<td> | |||
{% set item = ticket %} | |||
{% include '@LcShop/backend/default/field/ticket_last_message.html.twig' %} | |||
</td> | |||
<td> | |||
<a class="btn-sm btn-success" href="{{ path('easyadmin', {id: ticket.id, entity: 'Ticket', action: 'show'}) }}"> | |||
<i class="fas fa-eye"></i> | |||
</a> | |||
</td> | |||
</tr> | |||
{% endfor %} | |||
</tbody> | |||
</table> | |||
@@ -276,19 +276,197 @@ | |||
{% endmacro available_quantity_product %} | |||
{# {% macro modal(title, form) %} | |||
{% embed '@LcShop/backend/default/block/embed_modal.twig' %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% block id %}{{ id }}{% endblock %} | |||
{% block title %}{{ title }}{% endblock %} | |||
{% block form_start %} | |||
{{ form_start(form) }} | |||
{% endblock %} | |||
{% block icon %}{{ icon }}{% endblock %} | |||
{% block label %}{{ label }}{% endblock %} | |||
{% block value %} | |||
{{ value }} | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_info %}#} | |||
{% macro button(entity, action, id=null, class="success", title=null, icon=null) %} | |||
{% if title %} | |||
{% set trad = title %} | |||
{% else %} | |||
{% set trad = 'action.'~action %} | |||
{% endif %} | |||
{% if icon is null %} | |||
{% if action=="edit" %}{% set icon = 'pen' %} | |||
{% elseif action=="show" %}{% set icon = 'eye' %} | |||
{% endif %} | |||
{% endif %} | |||
{% set param = {action : action, entity: entity, referer: app.request.requestUri} %} | |||
{% if id %}{% set param = param|merge({id: id}) %}{% endif %} | |||
<a class="btn-sm btn-{{ class }}" data-toggle="tooltip" title="{{ trad|trans({}, "lcshop") }}" | |||
href="{{ path('easyadmin', param) }}"> | |||
<i class="fas fa-{{ icon }}"></i> | |||
</a> | |||
{% endmacro button %} | |||
{% macro list_tickets(tickets) %} | |||
<table class="table table-condensed"> | |||
<thead> | |||
<tr> | |||
<th>Sujet</th> | |||
<th>Statut</th> | |||
<th>Dernier message</th> | |||
<th></th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
{% for ticket in tickets %} | |||
<tr> | |||
<td>{{ ticket.subject }}</td> | |||
<td> | |||
{% set value = ticket.status %} | |||
{% include '@LcShop/backend/default/field/ticket_status.html.twig' %} | |||
</td> | |||
<td> | |||
{% set item = ticket %} | |||
{% include '@LcShop/backend/default/field/ticket_last_message.html.twig' %} | |||
</td> | |||
<td> | |||
{{ _self.button('Ticket', 'show', ticket.id) }} | |||
</td> | |||
</tr> | |||
{% endfor %} | |||
</tbody> | |||
</table> | |||
{% endmacro list_tickets %} | |||
{% macro list_reduction_credits(reductionCredits, user) %} | |||
{% set merchant_current = merchantUtils.getMerchantCurrent() %} | |||
<table class="table table-condensed"> | |||
<thead> | |||
<tr> | |||
<th>Titre</th> | |||
<th>Montant</th> | |||
<th>En ligne</th> | |||
<th>Utilisé</th> | |||
<th></th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
{% for reductionCredit in reductionCredits %} | |||
{% if reductionCredit.getMerchant() == merchant_current %} | |||
{% set isUsed = orderUtils.isReductionCreditUsed(reductionCredit, user) %} | |||
<tr> | |||
<td>{{ reductionCredit.title }}</td> | |||
<td> | |||
{{ reductionCredit.value|format_price(false) }} | |||
</td> | |||
<td> | |||
{% include '@LcShop/backend/default/field/status.html.twig' with {value: reductionCredit.status} %} | |||
</td> | |||
<td> | |||
{% include '@EasyAdmin/default/field_boolean.html.twig' with {value: isUsed} %} | |||
</td> | |||
<td> | |||
{% if isUsed == false and reductionCredit.status >=0 %} | |||
{{ _self.button('ReductionCredit', 'edit', reductionCredit.id, 'primary') }} | |||
{% endif %} | |||
</td> | |||
</tr> | |||
{% endif %} | |||
{% endfor %} | |||
</tbody> | |||
</table> | |||
{% endmacro list_reduction_credits %} | |||
{% macro list_reduction_carts(reductionCarts, user = false) %} | |||
<table class="table table-condensed"> | |||
<thead> | |||
<tr> | |||
<th>Titre</th> | |||
<th>Montant</th> | |||
<th>Quantité utilisé</th> | |||
<th>Quantité restante</th> | |||
<th>En ligne</th> | |||
<th>Actions</th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
{% for reductionCart in reductionCarts %} | |||
<tr> | |||
<td>{{ reductionCart.title }}</td> | |||
<td> | |||
{% if reductionCart.value > 0 %} | |||
{{ reductionCart.value }} | |||
{% if reductionCart.unit == 'percent' %}%{% else %}€{% endif %} | |||
{% if reductionCart.appliedTo is defined and reductionCart.appliedTo|length > 0 %} | |||
sur | |||
{% if reductionCart.appliedTo == 'order-products' %} | |||
les produits | |||
{% endif %} | |||
{% endif %} | |||
({% if reductionCart.behaviorTaxRate == 'tax-included' %}TTC{% else %}HT{% endif %}) | |||
{% endif %} | |||
{% if reductionCart.freeShipping %} | |||
{% if reductionCart.value > 0 %}<br/>{% endif %} | |||
Livraison offerte | |||
{% endif %} | |||
</td> | |||
<td> | |||
{% if user is not null %} | |||
{% set totalUsed = orderUtils.getReductionCartUsedQuantityPerUser(reductionCart, user) %} | |||
{{ totalUsed }} | |||
{% endif %} | |||
</td> | |||
<td> | |||
{% if user is not null %} | |||
{{ reductionCart.availableQuantityPerUser - totalUsed }} | |||
{% endif %} | |||
</td> | |||
<td> | |||
{% include '@EasyAdmin/default/field_boolean.html.twig' with {value: reductionCart.status} %} | |||
</td> | |||
<td> | |||
{{ _self.button('ReductionCart', 'edit', reductionCart.id, 'primary') }} | |||
</td> | |||
</tr> | |||
{% endfor %} | |||
</tbody> | |||
</table> | |||
{% endmacro list_reduction_carts %} | |||
{% macro box_user_info(user) %} | |||
{% embed '@LcShop/backend/default/block/embed_box.twig' %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% block class %}bg-info{% endblock %} | |||
{% block icon %}user{% endblock %} | |||
{% block label %}{{ "group.User.item"|trans({}, 'lcshop') }}{% endblock %} | |||
{% block value %} | |||
#{{ user.id }} | |||
{{ user.gender == 1 ? 'Mme.' : 'M.' }} {{ user.name }} {{ user.age < 200 ? '('~user.age~' ans)' : ''}}<br /> | |||
{{ user.email }}<br /> | |||
<span style="margin-top: 5px; display: inline-block;"> | |||
<span data-toggle="tooltip" data-placement="bottom" title="Nombre de commandes" class="badge badge-info"> | |||
{{ orderUtils.countValidOrderShopByUser(user) }} <i class="fa fa-shopping-cart"></i> | |||
</span> | |||
<span data-toggle="tooltip" data-placement="bottom" title="Total dépensés" class="badge badge-success"> | |||
{{ orderUtils.getTotalSpentByUser(user) }} <i class="fa fa-euro-sign"></i> | |||
</span> | |||
<span data-toggle="tooltip" data-placement="bottom" title="Nombre de relivraisons" class="badge badge-warning"> | |||
{{ orderUtils.countRedeliveryByUser(user) }} <i class="fa fa-undo"></i> | |||
</span> | |||
<span data-toggle="tooltip" data-placement="bottom" title="Nombre d'avoirs" class="badge badge-danger"> | |||
{{ user.reductionCredits|length }} <i class="fa fa-backspace"></i> | |||
</span> | |||
</span> | |||
{% endblock %} | |||
{% block button %} | |||
<a class="btn btn-sm btn-secondary" href="{{ path('easyadmin', {"action" : 'show', 'entity': 'User', 'id': user.id}) }}"> | |||
Voir la fiche | |||
</a> | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_user_info %} |
@@ -1,8 +1,12 @@ | |||
{# {{ value|date('U')}} #} | |||
{% if field_options.format == "d/m/Y h:i A e" or field_options.format == null %} | |||
{% if value is not null %} | |||
{% if field_options is not defined or field_options.format == "d/m/Y h:i A e" or field_options.format == null %} | |||
{% set format = "d/m/Y H:i" %} | |||
{% else %} | |||
{% set format = field_options.format %} | |||
{% endif %} | |||
<time data-timestamp="{{ value|date('U') }}" title="{{ value|date('r') }}">{{ value|date(format) }}</time> | |||
{% else %} | |||
<span class="badge badge-secondary">Non défini</span> | |||
{% endif %} |
@@ -0,0 +1,9 @@ | |||
{% trans_default_domain 'EasyAdminBundle' %} | |||
{% if value == 1 %} | |||
<span class="badge badge-success">{{ 'label.true'|trans }}</span> | |||
{% elseif value == 0 %} | |||
<span class="badge badge-danger">{{ 'label.false'|trans }}</span> | |||
{% elseif value == -1 %} | |||
<span class="badge badge-secondary">Supprimé</span> | |||
{% endif %} |
@@ -1 +1 @@ | |||
{{ priceUtils.getTotalWithTax(item)|format_price|raw }} | |||
{{ priceUtils.getTotalWithTax(item, true)|format_price|raw }}<br /> |
@@ -1,5 +1,7 @@ | |||
{% if item.user is not null %} | |||
{% if item is defined and item.user is defined and item.user is not null %} | |||
<a href="{{ path('easyadmin', {"entity": 'User', 'action': "show", "id" : item.user.id})}}">{{ value }}</a> | |||
{% elseif user is defined and user is not null %} | |||
<a href="{{ path('easyadmin', {"entity": 'User', 'action': "show", "id" : user.id})}}">{{ user }}</a> | |||
{% else %} | |||
{{ value }} | |||
{% endif %} |
@@ -240,11 +240,11 @@ | |||
</th> | |||
{% endfor %} | |||
{% if _list_item_actions|length > 0 %} | |||
{# {% if _list_item_actions|length > 0 %}#} | |||
<th {% if _entity_config.list.collapse_actions %}width="10px"{% endif %} {{ easyadmin_config('design.rtl') ? 'dir="rtl"' }}> | |||
<span class="sr-only">{{ 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') }}</span> | |||
</th> | |||
{% endif %} | |||
{#{% endif %}#} | |||
</tr> | |||
{% endblock table_head %} | |||
{% block table_filters %} | |||
@@ -287,7 +287,7 @@ | |||
</th> | |||
{% endfor %} | |||
{% if _list_item_actions|length > 0 %} | |||
{#{% if _list_item_actions|length > 0 %}#} | |||
<th class="actions"> | |||
<button type="submit" form="filters-form" class="btn btn-sm btn-info" | |||
data-toggle="tooltip" | |||
@@ -307,7 +307,7 @@ | |||
</th> | |||
{% endif %} | |||
{# {% endif %}#} | |||
</tr> | |||
{% endif %} | |||
@@ -353,9 +353,10 @@ | |||
</td> | |||
{% endfor %} | |||
<td class="actions"> | |||
{% if _list_item_actions|length > 0 %} | |||
{% set _column_label = 'list.row_actions'|trans(_trans_parameters, 'EasyAdminBundle') %} | |||
<td class="actions"> | |||
{% block item_actions %} | |||
{% set _actions_template = '@LcShop/backend/default/block/actions.html.twig' %} | |||
{{ include(_actions_template, { | |||
@@ -368,8 +369,9 @@ | |||
item: item | |||
}, with_context = false) }} | |||
{% endblock item_actions %} | |||
</td> | |||
{% endif %} | |||
</td> | |||
</tr> | |||
{% endif %} | |||
{% else %} |
@@ -0,0 +1 @@ | |||
<span class="badge badge-{{ value.color is defined ? value.color : item.orderStatus.color }}">{{ value }}</span> |
@@ -226,29 +226,6 @@ | |||
</div> | |||
{% endmacro %} | |||
{% macro box_user_info() %} | |||
{% embed '@LcShop/backend/default/block/embed_box.twig' %} | |||
{% import '@LcShop/backend/order/macros.html.twig' as order_macros %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% block class %}bg-info{% endblock %} | |||
{% block icon %}credit-card{% endblock %} | |||
{% block label %}{{ "field.OrderShop.reference"|trans({}, 'lcshop') }}{% endblock %} | |||
{% block value %} | |||
<span v-if="order.user" v-html="order.user"></span> | |||
<span v-else v-html="order.visitor"></span> | |||
{% endblock %} | |||
{% block button %} | |||
<a class="btn btn-sm btn-secondary" target="_blank" :href="order.userLink"> | |||
Voir la fiche | |||
</a> | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_user_info %} | |||
{% macro box_reference() %} | |||
{% embed '@LcShop/backend/default/block/embed_box.twig' %} | |||
{% import '@LcShop/backend/order/macros.html.twig' as order_macros %} |
@@ -19,7 +19,7 @@ | |||
<div class="lc-vue-js-container" id="lc-order-edit"> | |||
<div class="row"> | |||
<div class="col-3"> | |||
{{ order_macros.box_user_info() }} | |||
{{ macros.box_user_info(entity.user) }} | |||
</div> | |||
<div class="col-3"> | |||
{{ order_macros.box_total_order() }} |
@@ -20,7 +20,7 @@ | |||
<div class="lc-vue-js-container" id="lc-order-edit"> | |||
<div class="row"> | |||
<div class="col-3"> | |||
{{ order_macros.box_user_info() }} | |||
{{ macros.box_user_info(entity.user) }} | |||
</div> | |||
<div class="col-3"> | |||
{{ order_macros.box_total_order() }} |
@@ -8,8 +8,11 @@ | |||
{{ form_row(form.status) }} | |||
</div> | |||
<div class="col-6"> | |||
<label>Status de vente</label> | |||
<label>Statut de vente</label> | |||
{{ form_row(form.saleStatus) }} | |||
<label>Éligible ticket restaurant</label> | |||
{{ form_row(form.isEligibleTicketRestaurant) }} | |||
</div> | |||
<div class="col-12"> |
@@ -0,0 +1 @@ | |||
{{ item.availableQuantity - orderUtils.getReductionCartUsedQuantity(item) }} |
@@ -0,0 +1,3 @@ | |||
{% set totalUsed = orderUtils.getReductionCartUsedQuantity(item) %} | |||
<span class="badge badge-success">{{ totalUsed }}</span> utilisé(s) | |||
/ <span class="badge badge-primary">{{ item.availableQuantity - totalUsed }}</span> restante(s) |
@@ -23,7 +23,7 @@ | |||
{% endembed %} | |||
{% if entity.user %} | |||
{{ macros.box_info('bg-info', 'user', "field.default.user"|trans, entity.user.summary) }} | |||
{{ macros.box_user_info(entity.user) }} | |||
{% else %} | |||
{{ macros.box_info('bg-info', 'user-secret', "field.default.visitor"|trans, entity.user ? entity.user.summary : entity.visitorInfos) }} | |||
{% endif %} |
@@ -0,0 +1,10 @@ | |||
{% set totalOrder = orderUtils.countValidOrderShopByUser(item) %} | |||
{% if totalOrder > 0 %} | |||
<span class="badge badge-success"> | |||
{{ totalOrder }} commandes | |||
</span> | |||
{% else %} | |||
<span class="badge badge-secondary"> | |||
0 commandes | |||
</span> | |||
{% endif %} |
@@ -0,0 +1 @@ | |||
{{ orderUtils.getRankSumOrderByUser(item) }} |
@@ -0,0 +1 @@ | |||
{{ orderUtils.getRankTotalOrderByUser(item) }} |
@@ -0,0 +1,6 @@ | |||
{% set totalSpent = orderUtils.getTotalSpentByUser(item) %} | |||
{% if totalSpent >0 %} | |||
<span class="badge badge-primary"> {{ totalSpent|format_price(false) }}</span> | |||
{% else %} | |||
<span class="badge badge-secondary"> {{ totalSpent|format_price(false) }}</span> | |||
{% endif %} |
@@ -1,10 +0,0 @@ | |||
{% if value|length > 0 %} | |||
<span class="badge badge-success"> | |||
{{ value|length }} commandes | |||
</span> | |||
{% else %} | |||
<span class="badge badge-danger"> | |||
0 commandes | |||
</span> | |||
{% endif %} |
@@ -0,0 +1,222 @@ | |||
{% trans_default_domain 'lcshop' %} | |||
{% macro card_info(user) %} | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
<div class="card card-primary card-outline"> | |||
<div class="card-body box-profile"> | |||
<h3 class="profile-username"> | |||
<i class="fa fa-user"></i> {{ user.gender == 1 ? 'Mme.' : 'M.' }} {{ user.name }} | |||
</h3> | |||
<ul class="list-group list-group-unbordered"> | |||
{% if user.age < 200 and user.age > 2 %} | |||
<li class="list-group-item"> | |||
<b> <i class="fa fa-birthday-cake"></i> Age </b> | |||
<span class="float-right"> {{ user.age }} ans ({{ user.birthdate|date('d/m/Y') }})</span> | |||
</li> | |||
{% endif %} | |||
<li class="list-group-item"> | |||
<b> <i class="fa fa-envelope"></i> Email</b> | |||
<span class="float-right"> {{ user.email }}</span> | |||
</li> | |||
<li class="list-group-item"> | |||
<b> <i class="fa fa-phone"></i> Téléphone</b> | |||
<span class="float-right"> {{ user.phone }}</span> | |||
</li> | |||
<li class="list-group-item"> | |||
<b><i class="fa fa-fw fa-bullhorn"></i> Newsletters</b> | |||
{% for newsletter in user.newsletters %} | |||
<span class="badge badge-success float-right">{{ newsletter }}</span> | |||
{% else %} | |||
<span class="badge badge-dark float-right">Aucune</span> | |||
{% endfor %} | |||
</li> | |||
<li class="list-group-item"> | |||
<b> <i class="fa fa-users"></i> Groupes</b> | |||
{% for group in user.groupUsers %} | |||
<span class="badge badge-info float-right">{{ group }}</span> | |||
{% else %} | |||
<span class="badge badge-dark float-right">Aucun</span> | |||
{% endfor %} | |||
</li> | |||
{% if is_granted('ROLE_SUPER_ADMIN') == false %} | |||
<li class="list-group-item"> | |||
<b> <i class="fa fa-user-shield"></i> Roles</b> | |||
{% for role in user.roles %} | |||
<span class="badge badge-danger float-right">{{ role }}</span> | |||
{% endfor %} | |||
</li> | |||
{% endif %} | |||
</ul> | |||
<br /> | |||
<div> | |||
<a class="btn btn-sm btn-primary float-right" href="{{ path('easyadmin', {"action" : 'edit', 'entity': 'User', 'id': user.id}) }}"> | |||
<i class="fa fa-pen"></i> Éditer l'utilisateur | |||
</a> | |||
</div> | |||
</div> | |||
</div> | |||
{% endmacro card_info %} | |||
{% macro box_rank_sum_order(user) %} | |||
{% embed '@LcShop/backend/default/block/embed_figure_box.twig' %} | |||
{% block class %}bg-maroon{% endblock %} | |||
{% block icon %}cubes{% endblock %} | |||
{% block label %} Classement par total dépensés{% endblock %} | |||
{% block value %} | |||
{% set rankSumOrder = orderUtils.rankSumOrderByUser(user) %} | |||
{% if rankSumOrder %} | |||
{{ rankSumOrder }} <small style="opacity: 0.7"> / {{ orderUtils.countUsersWithValidOrderShop() }}</small> | |||
{% else %} | |||
Non classé | |||
{% endif %} | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_rank_sum_order %} | |||
{% macro box_total_spent(user) %} | |||
{% embed '@LcShop/backend/default/block/embed_figure_box.twig' %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% block class %}bg-pink{% endblock %} | |||
{% block icon %}euro-sign{% endblock %} | |||
{% block label %} Total dépensés{% endblock %} | |||
{% block value %} | |||
{{ orderUtils.totalSpentByUser(user)|format_price(false) }} | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_total_spent %} | |||
{% macro box_rank_total_order(user) %} | |||
{% embed '@LcShop/backend/default/block/embed_figure_box.twig' %} | |||
{% block class %}bg-info{% endblock %} | |||
{% block icon %}cubes{% endblock %} | |||
{% block label %}Classement par nombre de commande {% endblock %} | |||
{% block value %} | |||
{% set rankTotalOrder = orderUtils.rankTotalOrderByUser(user) %} | |||
{% if rankTotalOrder %} | |||
{{ rankTotalOrder }} <small style="opacity: 0.7"> / {{ orderUtils.countUsersWithValidOrderShop() }}</small> | |||
{% else %} | |||
Non classé | |||
{% endif %} | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_rank_total_order %} | |||
{% macro box_total_order(user) %} | |||
{% embed '@LcShop/backend/default/block/embed_figure_box.twig' %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% block class %}bg-lightblue{% endblock %} | |||
{% block icon %}shopping-cart{% endblock %} | |||
{% block label %} Nombre de commandes{% endblock %} | |||
{% block value %} | |||
{{ orderUtils.countValidOrderShopByUser(user) }} | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_total_order %} | |||
{% macro box_register_since(user) %} | |||
{% embed '@LcShop/backend/default/block/embed_figure_box.twig' %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% block class %}bg-success{% endblock %} | |||
{% block icon %}calendar-plus{% endblock %} | |||
{% block label %}Date de l'inscription{% endblock %} | |||
{% block value %} | |||
{{ user.createdAt|date('d/m/Y H:i') }} | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_register_since %} | |||
{% macro box_login_since(user) %} | |||
{% embed '@LcShop/backend/default/block/embed_figure_box.twig' %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% block class %}bg-olive{% endblock %} | |||
{% block icon %}calendar-check{% endblock %} | |||
{% block label %}Date de dernière visite{% endblock %} | |||
{% block value %} | |||
{{ user.lastLogin|date('d/m/Y H:i') }} | |||
{% endblock %} | |||
{% endembed %} | |||
{% endmacro box_login_since %} | |||
{% macro list_order_product_redelivery(orderProductsRedelivery) %} | |||
<table class="table lc-table-list table-striped"> | |||
<thead> | |||
<tr> | |||
<th>Id</th> | |||
<th>Produit</th> | |||
<th>Quantité</th> | |||
<th>Date de livraison</th> | |||
<th>Statut</th> | |||
<th></th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
{% for orderProduct in orderProductsRedelivery %} | |||
<tr> | |||
<td>{{ orderProduct.id }}</td> | |||
<td>{{ orderProduct.title }}</td> | |||
<td>{{ orderProduct.quantityOrder }}</td> | |||
<td> | |||
{% include '@LcShop/backend/default/field/datetime.html.twig' with {value : orderProduct.orderShop.deliveryDate} %}</td> | |||
<td>{% include '@LcShop/backend/order/field/order_status.html.twig' with {value : orderProduct.orderShop.orderStatus} %}</td> | |||
<td> | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
{% if orderProduct.orderShop.isCart() %} | |||
{{ macros.button('OrderProductRedelivery', 'edit', orderProduct.id, 'primary') }} | |||
{% endif %} | |||
{{ macros.button('OrderShop', 'show', orderProduct.orderShop.id) }} | |||
</td> | |||
</tr> | |||
{% endfor %} | |||
</tbody> | |||
</table> | |||
{% endmacro list_order_product_redelivery %} | |||
{% macro list_order_shops(orderShops) %} | |||
<table class="table table-striped"> | |||
<tbody> | |||
<thead> | |||
<tr> | |||
<th>Id</th> | |||
<th>WeekId</th> | |||
<th>Numéro de semaine</th> | |||
<th>Référence</th> | |||
<th>Montant TTC</th> | |||
<th>Statut</th> | |||
<th></th> | |||
</tr> | |||
</thead> | |||
<tbody> | |||
{% for orderShop in orderShops %} | |||
<tr> | |||
<td>{{ orderShop.id }}</td> | |||
<td>{{ orderShop.weekId }}</td> | |||
<td>{{ orderShop.weekNumber }}</td> | |||
<td>{{ orderShop.reference }}</td> | |||
<td>{{ priceUtils.getTotalWithTax(orderShop, true)|format_price(false) }}</td> | |||
<td>{% include '@LcShop/backend/order/field/order_status.html.twig' with {value : orderShop.orderStatus} %}</td> | |||
<td> | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
{{ macros.button('OrderShop', 'show', orderShop.id) }} | |||
</td> | |||
</tr> | |||
{% endfor %} | |||
</tbody> | |||
</table> | |||
{% endmacro list_order_shops %} |
@@ -0,0 +1,80 @@ | |||
{% extends '@LcShop/backend/default/show.html.twig' %} | |||
{% trans_default_domain 'lcshop' %} | |||
{% import '@LcShop/backend/default/block/macros.html.twig' as macros %} | |||
{% import '@LcShop/backend/user/macros.html.twig' as user_macros %} | |||
{% block global_actions %} | |||
{% if entity is not null %} | |||
{% set action = {label : "action.user.switch", icon: 'user-secret', css_class: 'btn btn-sm btn-danger'} %} | |||
{% include '@LcShop/backend/user/block/user-switch.html.twig' with {item: entity, is_dropdown: false, action: action, translation_domain: 'lcshop', trans_parameters: {}, item_id: entity.id}%} | |||
<button id="btn-ticket-write-to-user" | |||
data-url="{{ path('easyadmin', {'entity': 'Ticket', 'action': 'new'}) }}" | |||
data-user="{{ entity.id }}" | |||
class="btn-sm btn-success" | |||
type="button"><i class="fa fa-pen-alt"></i> {{ "action.ticket.writeToUser"|trans }} | |||
</button> | |||
{% endif %} | |||
{% endblock %} | |||
{% block main %} | |||
<div class="lc-vue-js-container" id="lc-user"> | |||
<div class="row"> | |||
<div class="col-3"> | |||
{{ user_macros.card_info(entity) }} | |||
</div> | |||
<div class="col-3"> | |||
{{ user_macros.box_rank_total_order(entity) }} | |||
{{ user_macros.box_total_order(entity) }} | |||
</div> | |||
<div class="col-3"> | |||
{{ user_macros.box_rank_sum_order(entity) }} | |||
{{ user_macros.box_total_spent(entity) }} | |||
</div> | |||
<div class="col-3"> | |||
{{ user_macros.box_register_since(entity) }} | |||
{{ user_macros.box_login_since(entity) }} | |||
</div> | |||
<div class="col-6"> | |||
{% set redeliveries = orderUtils.getRedeliveryByUser(entity) %} | |||
{% if redeliveries|length %} | |||
{{ macros.card_start('Redelivery.list', 'danger card-outline', true) }} | |||
{{ user_macros.list_order_product_redelivery(redeliveries) }} | |||
{{ macros.card_end() }} | |||
{% endif %} | |||
{% set tickets = ticketUtils.getTicketsByUser(entity) %} | |||
{% if tickets|length %} | |||
{{ macros.card_start('Ticket.listMessages', 'warning card-outline', false) }} | |||
{{ macros.list_tickets(tickets) }} | |||
{{ macros.card_end() }} | |||
{% endif %} | |||
{% if entity.reductionCredits|length %} | |||
{{ macros.card_start('ReductionCredit.list', 'warning card-outline', false) }} | |||
{{ macros.list_reduction_credits(entity.reductionCredits, entity) }} | |||
{{ macros.card_end() }} | |||
{% endif %} | |||
{% set reductionCartsAvailable = orderUtils.getReductionCartsAvailableByUser(entity) %} | |||
{% if reductionCartsAvailable|length %} | |||
{{ macros.card_start('ReductionCart.list', 'success card-outline', false) }} | |||
{{ macros.list_reduction_carts(reductionCartsAvailable, entity) }} | |||
{{ macros.card_end() }} | |||
{% endif %} | |||
</div> | |||
<div class="col-6"> | |||
{{ macros.card_start('OrderShop.list', 'primary card-outline', false) }} | |||
{{ user_macros.list_order_shops(orderUtils.getOrderShops({'user': entity})) }} | |||
{{ macros.card_end() }} | |||
</div> | |||
</div> | |||
</div> | |||
{% endblock %} |
@@ -31,8 +31,12 @@ class MailUtils | |||
protected $parameterBag; | |||
protected $merchantUtils; | |||
public function __construct(MailjetTransport $mailjetTransport, Environment $templating, ParameterBagInterface $parameterBag, MerchantUtilsInterface $merchantUtils) | |||
{ | |||
public function __construct( | |||
MailjetTransport $mailjetTransport, | |||
Environment $templating, | |||
ParameterBagInterface $parameterBag, | |||
MerchantUtilsInterface $merchantUtils | |||
) { | |||
$this->transport = $mailjetTransport; | |||
$this->templating = $templating; | |||
$this->parameterBag = $parameterBag; | |||
@@ -105,6 +109,6 @@ class MailUtils | |||
$message->getHeaders()->addMailboxHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo); | |||
}*/ | |||
$this->transport->send($message); | |||
return $this->transport->send($message); | |||
} | |||
} |
@@ -0,0 +1,108 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Services; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\HttpFoundation\ParameterBag; | |||
use Symfony\Contracts\HttpClient\HttpClientInterface; | |||
use Twig\Environment; | |||
class MailjetSmsUtils | |||
{ | |||
const TO_USER = 'to-user' ; | |||
const CONTENT_MESSAGE = 'content-message' ; | |||
const CONTENT_TEMPLATE = 'content-template' ; | |||
const CONTENT_DATA = 'content-data' ; | |||
protected $client; | |||
protected $parameterBag; | |||
protected $mailUtils ; | |||
protected $utils ; | |||
protected $templating ; | |||
public function __construct( | |||
HttpClientInterface $client, | |||
ParameterBagInterface $parameterBag, | |||
MailUtils $mailUtils, | |||
Utils $utils, | |||
Environment $templating | |||
) { | |||
$this->client = $client; | |||
$this->parameterBag = $parameterBag; | |||
$this->mailUtils = $mailUtils ; | |||
$this->utils = $utils ; | |||
$this->templating = $templating ; | |||
} | |||
public function send($params = []) | |||
{ | |||
$user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null ; | |||
if($user) { | |||
$phone = $this->utils->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->mailUtils->send([ | |||
MailUtils::SUBJECT => 'Notification par SMS à '.$phone, | |||
MailUtils::TO_EMAIL => $user->getEmail(), | |||
MailUtils::CONTENT_TEMPLATE => 'mail/notification', | |||
MailUtils::CONTENT_DATA => [ | |||
'message' => $message | |||
], | |||
]); | |||
return true ; | |||
} | |||
else { | |||
$token = $this->parameterBag->get('mailjet.sms.token'); | |||
$from = $this->parameterBag->get('mailjet.sms.from'); | |||
if ($token && strlen($token) > 0) { | |||
$response = $this->client->request( | |||
'POST', | |||
'https://api.mailjet.com/v4/sms-send', | |||
[ | |||
'headers' => [ | |||
'Authorization' => 'Bearer ' . $token, | |||
], | |||
'json' => [ | |||
'From' => $from, | |||
'To' => $phone, | |||
'Text' => $message, | |||
] | |||
] | |||
); | |||
$statusCode = $response->getStatusCode(); | |||
if ($statusCode == 200) { | |||
$content = $response->getContent(); | |||
$content = $response->toArray(); | |||
return $content; | |||
} else { | |||
// log | |||
} | |||
} | |||
else { | |||
throw new \ErrorException('Le token SMS Mailjet n\'est pas défini.'); | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -4,7 +4,7 @@ namespace Lc\ShopBundle\Services\Order; | |||
use App\Entity\OrderProductReductionCatalog; | |||
use App\Entity\OrderShop; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use App\Entity\OrderStatus; | |||
use Lc\ShopBundle\Context\DocumentInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\OrderReductionCreditInterface; | |||
@@ -16,6 +16,7 @@ use Lc\ShopBundle\Context\ReductionCreditInterface; | |||
use Lc\ShopBundle\Context\SectionInterface; | |||
use Lc\ShopBundle\Context\SectionUtilsInterface; | |||
use Lc\ShopBundle\Context\UserUtilsInterface; | |||
use Lc\ShopBundle\Manager\EntityManager; | |||
use Lc\ShopBundle\Model\ProductFamily; | |||
use Lc\ShopBundle\Services\CreditUtils; | |||
use Lc\ShopBundle\Services\DocumentUtils; | |||
@@ -50,18 +51,28 @@ class OrderUtils | |||
protected $router; | |||
protected $sectionUtils ; | |||
public function __construct(EntityManagerInterface $em, Security $security, RouterInterface $router, UserUtilsInterface $userUtils, | |||
MerchantUtilsInterface $merchantUtils, PriceUtilsInterface $priceUtils, ProductFamilyUtilsInterface $productFamilyUtils, | |||
DocumentUtils $documentUtils, Utils $utils, CreditUtils $creditUtils, SectionUtilsInterface $sectionUtils) | |||
public function __construct( | |||
EntityManager $em, | |||
Security $security, | |||
RouterInterface $router, | |||
UserUtilsInterface $userUtils, | |||
MerchantUtilsInterface $merchantUtils, | |||
PriceUtilsInterface $priceUtils, | |||
ProductFamilyUtilsInterface $productFamilyUtils, | |||
DocumentUtils $documentUtils, | |||
Utils $utils, | |||
CreditUtils $creditUtils, | |||
SectionUtilsInterface $sectionUtils | |||
) | |||
{ | |||
$this->em = $em; | |||
$this->security = $security; | |||
$this->userUtils = $userUtils; | |||
$this->merchantUtils = $merchantUtils; | |||
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName()); | |||
$this->reductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(ReductionCreditInterface::class)->getName()); | |||
$this->orderReductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(OrderReductionCreditInterface::class)->getName()); | |||
$this->documentRepo = $this->em->getRepository($this->em->getClassMetadata(DocumentInterface::class)->getName()); | |||
$this->orderShopRepo = $this->em->getRepository($this->em->getEntityName(OrderShopInterface::class)); | |||
$this->reductionCreditRepo = $this->em->getRepository($this->em->getEntityName(ReductionCreditInterface::class)); | |||
$this->orderReductionCreditRepo = $this->em->getRepository($this->em->getEntityName(OrderReductionCreditInterface::class)); | |||
$this->documentRepo = $this->em->getRepository($this->em->getEntityName(DocumentInterface::class)); | |||
$this->priceUtils = $priceUtils; | |||
$this->productFamilyUtils = $productFamilyUtils; | |||
$this->documentUtils = $documentUtils; | |||
@@ -257,6 +268,7 @@ class OrderUtils | |||
$data['count'] = $this->countQuantities($order); | |||
$data['total_with_tax'] = $this->priceUtils->getTotalWithTax($order); | |||
$data['order_products_by_category'] = $this->getOrderProductsByParentCategory($order); | |||
$data['total_remaining_to_be_paid'] = $this->getTotalRemainingToBePaid($order) ; | |||
} | |||
return $data; | |||
} | |||
@@ -296,8 +308,8 @@ class OrderUtils | |||
public function newOrderStatusHistory($order, $status, $origin = 'user') | |||
{ | |||
$orderStatusHistoryClass = $this->em->getClassMetadata(OrderStatusHistoryInterface::class); | |||
$orderStatusHistory = new $orderStatusHistoryClass->name; | |||
$orderStatusHistoryClass = $this->em->getEntityName(OrderStatusHistoryInterface::class); | |||
$orderStatusHistory = new $orderStatusHistoryClass; | |||
$orderStatusHistory->setOrderShop($order); | |||
$orderStatusHistory->setOrderStatus($status); | |||
$orderStatusHistory->setOrigin($origin); | |||
@@ -395,5 +407,30 @@ class OrderUtils | |||
} | |||
public function addPayment($orderShop, $meanPayment, $amount) | |||
{ | |||
$this->createOrderPayment([ | |||
'orderShop' => $orderShop, | |||
'meanPayment' => $meanPayment, | |||
'amount' => $amount | |||
]) ; | |||
$this->em->refresh($orderShop) ; | |||
if($this->isOrderPaid($orderShop)) { | |||
$nextStatus = OrderStatus::ALIAS_PAID ; | |||
} | |||
else { | |||
$nextStatus = OrderStatus::ALIAS_PARTIAL_PAYMENT ; | |||
} | |||
if($orderShop->getOrderStatus()->getAlias() != $nextStatus) { | |||
$orderShop = $this->changeOrderStatus( | |||
$nextStatus, | |||
$orderShop | |||
); | |||
} | |||
return $orderShop ; | |||
} | |||
} |
@@ -3,46 +3,44 @@ | |||
namespace Lc\ShopBundle\Services\Order; | |||
use App\Entity\CreditHistory; | |||
use App\Factory\Order\OrderPaymentFactory; | |||
use Lc\ShopBundle\Context\OrderPaymentInterface; | |||
use Lc\ShopBundle\Services\Utils; | |||
trait OrderUtilsPaymentTrait | |||
{ | |||
public function createOrderPayment($orderShop, $meanPayment, $amount, $reference = null, $comment = null, $paidAt = null) | |||
public function createOrderPayment($params = []) | |||
{ | |||
$classOrderPayment = $this->em->getClassMetadata(OrderPaymentInterface::class)->getName(); | |||
$orderPayment = new $classOrderPayment; | |||
$orderPayment->setOrderShop($orderShop); | |||
$orderPayment->setMeanPayment($meanPayment); | |||
$orderPayment->setAmount($amount); | |||
$orderPayment->setReference($reference); | |||
$orderPayment->setComment($comment); | |||
$orderPayment->setEditable(false); | |||
$orderPayment->setCreatedBy($orderShop->getUser()); | |||
$orderPayment->setUpdatedBy($orderShop->getUser()); | |||
if ($paidAt) { | |||
$orderPayment->setPaidAt($paidAt); | |||
} else { | |||
$orderPayment->setPaidAt(new \DateTime('now')); | |||
$orderPayment = $this->factoryManager->createEntity(OrderPaymentFactory::class, $params); | |||
if(isset($params['meanPayment']) && $params['meanPayment'] == Utils::MEAN_PAYMENT_CREDIT) { | |||
$this->creditUtils->createCreditHistory(CreditHistory::TYPE_DEBIT, $this->security->getUser(), [ | |||
'orderPayment' => $orderPayment | |||
]); | |||
} | |||
$this->em->persist($orderPayment); | |||
$this->em->flush(); | |||
$this->em->create($orderPayment) ; | |||
$this->em->flush() ; | |||
return $orderPayment; | |||
return $orderPayment ; | |||
} | |||
public function isOrderPaid($order, $mergeComplementaryOrderShop = false) | |||
{ | |||
$totalOrderPayments = $this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) ; | |||
$totalOrder = $this->priceUtils->getTotalWithTax($order) ; | |||
if ( (abs($totalOrderPayments - $totalOrder) < 0.00001 | |||
|| $totalOrderPayments >= $totalOrder) | |||
&& $totalOrder > 0) { | |||
if ($this->getTotalOrderPayments($order, $mergeComplementaryOrderShop) >= $this->priceUtils->getTotalWithTax($order) && $this->priceUtils->getTotalWithTax($order) > 0) { | |||
return true; | |||
} else { | |||
} | |||
else { | |||
return false; | |||
} | |||
} | |||
public function getTotalOrderPayments($order, $mergeComplementaryOrderShop = false): float | |||
@@ -61,4 +59,18 @@ trait OrderUtilsPaymentTrait | |||
return $totalAmount; | |||
} | |||
public function getTotalRemainingToBePaid($order) | |||
{ | |||
return $this->priceUtils->getTotalWithTax($order) - $this->getTotalOrderPayments($order) ; | |||
} | |||
public function isOrderShopPositiveAmountRemainingToBePaid($orderShop) | |||
{ | |||
return $this->getTotalRemainingToBePaid($orderShop) > 0 ; | |||
} | |||
public function addPayment() | |||
{ | |||
} | |||
} |
@@ -73,13 +73,18 @@ trait OrderUtilsReductionTrait | |||
$orderShop->addOrderReductionCart($orderReductionCart) ; | |||
if($this->isOrderShopPositiveAmount($orderShop)) { | |||
if($this->isOrderShopPositiveAmount($orderShop) | |||
&& $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) { | |||
$this->em->persist($orderReductionCart); | |||
$this->em->flush(); | |||
return $orderReductionCart ; | |||
} | |||
return false; | |||
else { | |||
$orderShop->removeOrderReductionCart($orderReductionCart) ; | |||
return false; | |||
} | |||
} | |||
public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit) | |||
@@ -111,12 +116,24 @@ trait OrderUtilsReductionTrait | |||
public function getReductionCartRemainingQuantity($reductionCart) :float | |||
{ | |||
return $reductionCart->getAvailableQuantity() - $this->orderShopRepo->countValidOrderWithReductionCart(); | |||
return $reductionCart->getAvailableQuantity() - $this->orderShopRepo->countValidOrderWithReductionCart($reductionCart); | |||
} | |||
public function getReductionCartRemainingQuantityPerUser($reductionCart) :float | |||
public function getReductionCartUsedQuantityPerUser($reductionCart, $user) :float | |||
{ | |||
return $this->orderShopRepo->countValidOrderWithReductionCartPerUser($reductionCart, $user); | |||
} | |||
public function getReductionCartUsedQuantity($reductionCart) :float | |||
{ | |||
return $reductionCart->getAvailableQuantityPerUser() - $this->orderShopRepo->countValidOrderWithReductionCartPerUser(); | |||
return $this->orderShopRepo->countValidOrderWithReductionCart($reductionCart); | |||
} | |||
public function getReductionCartRemainingQuantityPerUser($reductionCart, $user) :float | |||
{ | |||
if ($reductionCart->getAvailableQuantityPerUser()) { | |||
return $reductionCart->getAvailableQuantityPerUser() - $this->orderShopRepo->countValidOrderWithReductionCartPerUser($reductionCart, $user); | |||
} | |||
return false; | |||
} | |||
@@ -136,24 +153,28 @@ trait OrderUtilsReductionTrait | |||
$orderShop->addOrderReductionCredit($orderReductionCredit) ; | |||
if($this->isOrderShopPositiveAmount($orderShop)) { | |||
if($this->isOrderShopPositiveAmount($orderShop) | |||
&& $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) { | |||
$this->em->persist($orderReductionCredit); | |||
$this->em->flush(); | |||
return $orderReductionCredit; | |||
} | |||
else { | |||
$orderShop->removeOrderReductionCredit($orderReductionCredit) ; | |||
return false ; | |||
return false; | |||
} | |||
} | |||
/*public function getReductionCreditsAvailable($order) | |||
{ | |||
$reductionCreditRepo = $this->em->getRepository(ReductionCreditInterface::class); | |||
$reductionCredits = $reductionCreditRepo->getReductionCreditByUser($order->getUser()); | |||
foreach ($reductionCredits as $reductionCredit){ | |||
public function getReductionCartsAvailableByUser($user) | |||
{ | |||
$reductionCartRepository = $this->em->getRepository(ReductionCartInterface::class) ; | |||
return $reductionCartRepository->findAllAvailableForUser($user); | |||
} | |||
} | |||
}*/ | |||
public function getReductionCreditsAvailableByUser($user) | |||
{ | |||
$reductionCredits = $this->reductionCreditRepo->findReductionCreditsByUser($user) ; | |||
@@ -189,6 +210,15 @@ trait OrderUtilsReductionTrait | |||
return false; | |||
} | |||
} | |||
public function isReductionCreditUsed($reductionCredit, $user = false){ | |||
if($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user)) { | |||
return true; | |||
}else{ | |||
return false; | |||
} | |||
} | |||
public function isReductionCreditAddedToOrder($orderShop, $reductionCredit) | |||
{ | |||
foreach($orderShop->getOrderReductionCredits() as $orderReductionCredit) { |
@@ -40,22 +40,26 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface | |||
return $total; | |||
} | |||
public function getMarginOrderProductsWithReductions(OrderShopInterface $orderShop): float | |||
public function getMarginOrderProductsWithReductions(OrderShopInterface $orderShop, $cache = false): float | |||
{ | |||
$total = $this->getMarginOrderProducts($orderShop); | |||
if ($cache && $orderShop->getStatMarginOrderProductsWithReductions() !== null) { | |||
return $orderShop->getStatMarginOrderProductsWithReductions(); | |||
} else { | |||
$total = $this->getMarginOrderProducts($orderShop); | |||
$totalReductionAmount = 0; | |||
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||
$totalReductionAmount += $this->getOrderProductsReductionCartAmountWithoutTax($orderShop, $orderReductionCart); | |||
} | |||
$totalReductionAmount = 0; | |||
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||
$totalReductionAmount += $this->getOrderProductsReductionCartAmountWithoutTax($orderShop, $orderReductionCart); | |||
} | |||
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||
$totalReductionAmount += $this->getOrderProductsReductionCreditAmountWithoutTax($orderShop, $orderReductionCredit); | |||
} | |||
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||
$totalReductionAmount += $this->getOrderProductsReductionCreditAmountWithoutTax($orderShop, $orderReductionCredit); | |||
} | |||
$total -= $totalReductionAmount; | |||
$total -= $totalReductionAmount; | |||
return $total; | |||
return $total; | |||
} | |||
} | |||
public function getMarginOrderProductsWithReductionsPercent(OrderShopInterface $orderShop): float | |||
@@ -165,12 +169,16 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface | |||
return $this->getTotalOrderProductsWithTax($orderShop) / $this->getTotalOrderProducts($orderShop); | |||
} | |||
public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop) | |||
public function getTotalOrderProductsWithReductions(OrderShopInterface $orderShop, $cache = false) | |||
{ | |||
$total = $this->getTotalOrderProducts($orderShop); | |||
$total -= $this->getTotalReductionCartsAmount($orderShop); | |||
$total -= $this->getTotalReductionCreditsAmount($orderShop); | |||
return $total; | |||
if($cache && $orderShop->getStatTotalOrderProductsWithReductions()!==null){ | |||
return $orderShop->getStatTotalOrderProductsWithReductions(); | |||
}else { | |||
$total = $this->getTotalOrderProducts($orderShop); | |||
$total -= $this->getTotalReductionCartsAmount($orderShop); | |||
$total -= $this->getTotalReductionCreditsAmount($orderShop); | |||
return $total; | |||
} | |||
} | |||
public function getTotalOrderProductsWithReductionCarts(OrderShopInterface $orderShop) | |||
@@ -198,12 +206,16 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface | |||
return $totalReductionAmount; | |||
} | |||
public function getTotalOrderProductsWithTaxAndReductions(OrderShopInterface $orderShop) | |||
public function getTotalOrderProductsWithTaxAndReductions(OrderShopInterface $orderShop, $cache = false) | |||
{ | |||
$total = $this->getTotalOrderProductsWithTax($orderShop); | |||
$total -= $this->getTotalReductionCartsAmountWithTax($orderShop); | |||
$total -= $this->getTotalReductionCreditsAmountWithTax($orderShop); | |||
return $total; | |||
if($cache && $orderShop->getStatTotalOrderProductsWithTaxAndReductions()!==null){ | |||
return $orderShop->getStatTotalOrderProductsWithTaxAndReductions(); | |||
}else { | |||
$total = $this->getTotalOrderProductsWithTax($orderShop); | |||
$total -= $this->getTotalReductionCartsAmountWithTax($orderShop); | |||
$total -= $this->getTotalReductionCreditsAmountWithTax($orderShop); | |||
return $total; | |||
} | |||
} | |||
public function getTotalOrderProductsWithTaxAndReductionCarts(OrderShopInterface $orderShop) | |||
@@ -303,32 +315,32 @@ class OrderShopPriceUtils implements OrderShopPriceUtilsInterface | |||
public function getTotalReductions(OrderShopInterface $orderShop) | |||
{ | |||
$total = 0 ; | |||
$total = 0; | |||
foreach($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||
$total += $this->getOrderProductsReductionCartAmountWithoutTax($orderShop, $orderReductionCart) ; | |||
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||
$total += $this->getOrderProductsReductionCartAmountWithoutTax($orderShop, $orderReductionCart); | |||
} | |||
foreach($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||
$total += $this->getOrderProductsReductionCreditAmountWithoutTax($orderShop, $orderReductionCredit) ; | |||
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||
$total += $this->getOrderProductsReductionCreditAmountWithoutTax($orderShop, $orderReductionCredit); | |||
} | |||
return $total ; | |||
return $total; | |||
} | |||
public function getTotalReductionsWithTax(OrderShopInterface $orderShop) | |||
{ | |||
$total = 0 ; | |||
$total = 0; | |||
foreach($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||
$total += $this->getOrderProductsReductionCartAmountWithTax($orderShop, $orderReductionCart) ; | |||
foreach ($orderShop->getOrderReductionCarts() as $orderReductionCart) { | |||
$total += $this->getOrderProductsReductionCartAmountWithTax($orderShop, $orderReductionCart); | |||
} | |||
foreach($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||
$total += $this->getOrderProductsReductionCreditAmountWithTax($orderShop, $orderReductionCredit) ; | |||
foreach ($orderShop->getOrderReductionCredits() as $orderReductionCredit) { | |||
$total += $this->getOrderProductsReductionCreditAmountWithTax($orderShop, $orderReductionCredit); | |||
} | |||
return $total ; | |||
return $total; | |||
} | |||
} | |||
@@ -27,6 +27,11 @@ class TicketUtils | |||
$this->authorizationChecker = $authorizationChecker ; | |||
} | |||
public function getTicketsByUser($user){ | |||
$ticketRepo = $this->em->getRepository(TicketInterface::class); | |||
return $ticketRepo->findBy(array('user'=>$user)); | |||
} | |||
public function createTicket($params): TicketInterface | |||
{ | |||
$classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName() ; |
@@ -1,11 +1,11 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Services ; | |||
namespace Lc\ShopBundle\Services; | |||
use ConnectHolland\CookieConsentBundle\Cookie\CookieChecker; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Symfony\Component\HttpFoundation\Cookie ; | |||
use Symfony\Component\HttpFoundation\Cookie; | |||
use Lc\ShopBundle\Context\VisitorInterface; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\HttpFoundation\RequestStack; | |||
@@ -13,31 +13,32 @@ use Symfony\Component\Security\Core\Security; | |||
class UserUtils | |||
{ | |||
protected $parameterBag ; | |||
protected $em ; | |||
protected $utils ; | |||
protected $requestStack ; | |||
protected $visitorRepository ; | |||
protected $merchantUtils ; | |||
protected $cookieChecker ; | |||
protected $parameterBag; | |||
protected $em; | |||
protected $utils; | |||
protected $requestStack; | |||
protected $visitorRepository; | |||
protected $merchantUtils; | |||
protected $cookieChecker; | |||
protected $visitor; | |||
public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils, | |||
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils, CookieChecker $cookieChecker, | |||
Security $security) | |||
Security $security) | |||
{ | |||
$this->em = $em ; | |||
$this->parameterBag = $parameterBag ; | |||
$this->utils = $utils ; | |||
$this->requestStack = $requestStack ; | |||
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ; | |||
$this->merchantUtils = $merchantUtils ; | |||
$this->cookieChecker = $cookieChecker ; | |||
$this->security = $security ; | |||
$this->em = $em; | |||
$this->parameterBag = $parameterBag; | |||
$this->utils = $utils; | |||
$this->requestStack = $requestStack; | |||
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()); | |||
$this->merchantUtils = $merchantUtils; | |||
$this->cookieChecker = $cookieChecker; | |||
$this->security = $security; | |||
} | |||
public function getCookieNameVisitor() | |||
{ | |||
return $this->parameterBag->get('app.cookie_name_visitor') ; | |||
return $this->parameterBag->get('app.cookie_name_visitor'); | |||
} | |||
public function cryptCookie($data) | |||
@@ -52,60 +53,75 @@ class UserUtils | |||
public function setCookieVisitor($response, $cookie) | |||
{ | |||
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($cookie), 0, '/', $this->utils->getCookieDomain())); | |||
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($cookie), new \DateTime('+2 months'), '/', $this->utils->getCookieDomain())); | |||
} | |||
public function updateVisitorCookie($response) | |||
{ | |||
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($this->getVisitorCurrent()->getCookie()), new \DateTime('+2 months'), '/', $this->utils->getCookieDomain())); | |||
} | |||
public function getVisitor($cookie) | |||
{ | |||
return $this->visitorRepository->findOneBy(['cookie' => $cookie]) ; | |||
if (!isset($this->visitor[$cookie])) { | |||
$this->visitor[$cookie] = $this->visitorRepository->findOneBy(['cookie' => $cookie]); | |||
} | |||
return $this->visitor[$cookie]; | |||
} | |||
public function getVisitorCurrent() | |||
{ | |||
$cookie = $this->requestStack->getCurrentRequest()->cookies->get($this->getCookieNameVisitor()) ; | |||
return $this->getVisitor($cookie) ; | |||
$cookie = $this->requestStack->getCurrentRequest()->cookies->get($this->getCookieNameVisitor()); | |||
return $this->getVisitor($cookie); | |||
} | |||
public function addVisitor($cookie, $ip) | |||
{ | |||
$classVisitor = $this->em->getClassMetadata(VisitorInterface::class)->getName() ; | |||
$visitor = new $classVisitor ; | |||
$classVisitor = $this->em->getClassMetadata(VisitorInterface::class)->getName(); | |||
$visitor = new $classVisitor; | |||
$visitor->setCookie($cookie) ; | |||
$visitor->setIp($ip) ; | |||
$visitor->setTotalVisit(1) ; | |||
$visitor->setLastAccess(new \DateTime()) ; | |||
$visitor->setCookie($cookie); | |||
$visitor->setIp($ip); | |||
$visitor->setTotalVisit(1); | |||
$visitor->setLastAccess(new \DateTime()); | |||
$this->em->persist($visitor); | |||
$this->em->flush() ; | |||
$this->em->flush(); | |||
} | |||
public function updateVisitor($visitor) | |||
{ | |||
$totalVisit = $visitor->getTotalVisit() + 1 ; | |||
$visitor->setTotalVisit($totalVisit) ; | |||
$visitor->setLastAccess(new \DateTime()) ; | |||
$totalVisit = $visitor->getTotalVisit() + 1; | |||
$visitor->setTotalVisit($totalVisit); | |||
$visitor->setLastAccess(new \DateTime()); | |||
$this->em->persist($visitor); | |||
$this->em->flush() ; | |||
$this->em->flush(); | |||
} | |||
public function setNewsletter($user, $subscribeNewsletter) | |||
public function setNewsletter($user, $newsletter, $subscribeNewsletter) | |||
{ | |||
$currentMerchant = $this->merchantUtils->getMerchantCurrent() ; | |||
$newsletters = $currentMerchant->getNewsletters() ; | |||
if(isset($newsletters[0]) && $newsletters[0]) { | |||
if($subscribeNewsletter) { | |||
$user->addNewsletter($newsletters[0]) ; | |||
} | |||
else { | |||
$user->removeNewsletter($newsletters[0]) ; | |||
$currentMerchant = $this->merchantUtils->getMerchantCurrent(); | |||
$newsletters = $currentMerchant->getNewsletters(); | |||
foreach ($newsletters as $newsletterMerchant) { | |||
if ($newsletterMerchant->getId() == $newsletter->getId()) { | |||
if ($subscribeNewsletter) { | |||
$user->addNewsletter($newsletter); | |||
} else { | |||
$user->removeNewsletter($newsletter); | |||
} | |||
} | |||
} | |||
$this->em->persist($user) ; | |||
$this->em->flush() ; | |||
$this->em->persist($user); | |||
$this->em->flush(); | |||
} | |||
public function isSubscribedToNewsletter($user, $newsletter) | |||
{ | |||
return $user->getNewsletters()->contains($newsletter); | |||
} | |||
} |
@@ -87,6 +87,15 @@ class Utils | |||
return $text; | |||
} | |||
public function limitTextByLength($text, $length, $append = '...') | |||
{ | |||
if(strlen($text) > $length) { | |||
$text = substr($text, 0, $length) . $append ; | |||
} | |||
return $text ; | |||
} | |||
function truncateHtml($text, $length = 100, $ending = '...', $exact = false, $considerHtml = true) | |||
{ | |||
if ($considerHtml) { | |||
@@ -368,7 +377,7 @@ class Utils | |||
return $this->getNextDay($this->getDayByNumber($number, 'en')); | |||
} | |||
public function getDayByNumber($number, $lang = 'fr') | |||
public static function getDayByNumber($number, $lang = 'fr') | |||
{ | |||
if ($lang == 'fr') { | |||
$daysArray = [ | |||
@@ -588,5 +597,23 @@ class Utils | |||
return substr($fieldName, 0, strpos($fieldName, $needle)); | |||
} | |||
public function round($price, $precision = 2) | |||
{ | |||
return round((($price * 100)) / 100, $precision); | |||
} | |||
public function formatPhoneNumber($phone) | |||
{ | |||
$phone = preg_replace('`[^0-9]`', '', $phone); | |||
if(strlen($phone) == 10) { | |||
$phone = '+33'.substr($phone, 1, 9) ; | |||
} | |||
elseif(strlen($phone) == 11 && substr($phone, 0, 2) == '33') { | |||
$phone = '+'.$phone ; | |||
} | |||
return $phone ; | |||
} | |||
} |
@@ -29,6 +29,7 @@ class UtilsManager | |||
protected $statisticsUtils; | |||
protected $pointLocationUtils ; | |||
protected $sectionUtils ; | |||
protected $mailjetSmsUtils ; | |||
public function __construct( | |||
Utils $utils, | |||
@@ -44,7 +45,8 @@ class UtilsManager | |||
TicketUtils $ticketUtils, | |||
PointLocationUtils $pointLocationUtils, | |||
UtilsProcess $utilsProcess, | |||
SectionUtilsInterface $sectionUtils | |||
SectionUtilsInterface $sectionUtils, | |||
MailjetSmsUtils $mailjetSmsUtils | |||
) | |||
{ | |||
$this->utils = $utils ; | |||
@@ -61,6 +63,7 @@ class UtilsManager | |||
$this->pointLocationUtils = $pointLocationUtils ; | |||
$this->utilsProcess = $utilsProcess ; | |||
$this->sectionUtils = $sectionUtils ; | |||
$this->mailjetSmsUtils = $mailjetSmsUtils ; | |||
} | |||
public function getUtils(): Utils | |||
@@ -133,4 +136,9 @@ class UtilsManager | |||
return $this->sectionUtils ; | |||
} | |||
public function getMailjetSmsUtils(): MailjetSmsUtils | |||
{ | |||
return $this->mailjetSmsUtils ; | |||
} | |||
} |
@@ -2,6 +2,7 @@ | |||
namespace Lc\ShopBundle\Twig; | |||
use App\Services\NotificationUtils; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\MerchantInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
@@ -104,5 +105,4 @@ class FrontendTwigExtension extends AbstractExtension | |||
{ | |||
return $this->merchantRepository->findAll(); | |||
} | |||
} |