Browse Source

Merge branch 'develop'

master
Fab 4 years ago
parent
commit
56d4c2b10c
11 changed files with 144 additions and 42 deletions
  1. +3
    -0
      ShopBundle/Controller/Backend/AdminController.php
  2. +94
    -38
      ShopBundle/Controller/Backend/NewsController.php
  3. +3
    -0
      ShopBundle/Controller/Backend/ProductFamilyController.php
  4. +1
    -1
      ShopBundle/Controller/Frontend/CartController.php
  5. +17
    -0
      ShopBundle/Repository/OrderProductRepository.php
  6. +13
    -0
      ShopBundle/Repository/OrderShopRepository.php
  7. +1
    -0
      ShopBundle/Repository/TicketRepository.php
  8. +1
    -1
      ShopBundle/Resources/public/js/backend/script/default/init-common.js
  9. +1
    -1
      ShopBundle/Resources/views/backend/default/list.html.twig
  10. +1
    -0
      ShopBundle/Services/Order/OrderUtils.php
  11. +9
    -1
      ShopBundle/Services/Order/OrderUtilsCartTrait.php

+ 3
- 0
ShopBundle/Controller/Backend/AdminController.php View File

@@ -18,6 +18,7 @@ use Lc\ShopBundle\Form\Backend\Filters\ListFilterType;
use Lc\ShopBundle\Services\UtilsManager;
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
@@ -38,6 +39,7 @@ class AdminController extends EasyAdminController
protected $merchantUtils;
protected $mailjetTransport;
protected $orderUtils;
protected $mailUtils ;
protected $translator;
protected $filtersForm = null;

@@ -51,6 +53,7 @@ class AdminController extends EasyAdminController
$this->utils = $utilsManager->getUtils();
$this->merchantUtils = $utilsManager->getMerchantUtils();
$this->orderUtils = $utilsManager->getOrderUtils();;
$this->mailUtils = $utilsManager->getMailUtils() ;
$this->translator = $translator;
}


+ 94
- 38
ShopBundle/Controller/Backend/NewsController.php View File

@@ -7,61 +7,117 @@ use Doctrine\ORM\EntityManagerInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Lc\ShopBundle\Context\NewsInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Services\MailUtils;
use Lc\ShopBundle\Services\UtilsManager;
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;

class NewsController extends AdminController
{
protected $parameterBag ;

public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em,
MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator,
ParameterBagInterface $parameterBag)
{
$this->parameterBag = $parameterBag ;
parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator);
}

public function sendTestAction()
{
$newsletter = $this->getNewsletter() ;
$news = $this->getNews() ;

$merchantCurrent = $this->merchantUtils->getMerchantCurrent() ;
$merchantConfigEmailContact = $merchantCurrent->getMerchantConfig('email-contact');

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()
],
]);

$this->addFlash('success', 'Actualité de test envoyée à '.$merchantConfigEmailContact);
}
else {
throw new \ErrorException("L'email de contact n'est pas défini pour ce Merchant.") ;
}

return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ;
}

public function sendAction()
{
$idNews = $this->request->get('id') ;
$newsletter = $this->getNewsletter() ;

$newsletter = $this->merchantUtils->getMerchantCurrent()->getNewsletter() ;
$news = $this->getNews() ;
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ;
$countUsers = count($users) ;
$messages = [];

if($newsletter) {
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ;
$countUsers = count($users) ;
$messages = [];
$news = $this->em->getRepository($this->em->getClassMetadata(NewsInterface::class)->getName())->find($idNews) ;
if($news) {
foreach ($users as $user) {
$message = new \Swift_Message('[Place du Local] '.$news->getTitle());
$message->addTo($user->getEmail())
->addFrom($this->getParameter('app.noreply_email'), $this->getParameter('app.site_name'))
->setBody($this->renderView('mail/news.html.twig', [
'message' => $news->getDescription(),
'image' => $news->getImage(),
'newsletter' => $newsletter,
'user' => $user
]), 'text/html');
array_push($messages, $message);
}

if($countUsers > 0) {
$result = $this->mailjetTransport->bulkSend($messages);

$this->addFlash('success', 'Actualité envoyée à '.count($users).' utilisateurs.');

$news->setIsSent(true) ;
$this->em->persist($news);
$this->em->flush() ;
}
else {
$this->addFlash('error', 'Aucun utilisateur inscrit à la newsletter.');
}
}
else {
throw new NotFoundHttpException('Actualité introuvable') ;
}
foreach ($users as $user) {
$message = new \Swift_Message('[Place du Local] '.$news->getTitle());
$message->addTo($user->getEmail())
->addFrom($this->getParameter('app.noreply_email'), $this->getParameter('app.site_name'))
->setBody($this->renderView('mail/news-html.html.twig', [
'news' => $news,
'newsletter' => $newsletter,
'user' => $user
]), 'text/html');
array_push($messages, $message);
}

if($countUsers > 0) {
$result = $this->mailjetTransport->bulkSend($messages);

$this->addFlash('success', 'Actualité envoyée à '.count($users).' utilisateurs.');

$news->setIsSent(true) ;
$this->em->persist($news);
$this->em->flush() ;
}
else {
throw new \ErrorException('Aucune newsletter n\'est lié à ce Merchant.') ;
$this->addFlash('error', 'Aucun utilisateur inscrit à la newsletter.');
}

return $this->redirectToRoute('easyadmin', ['entity' => 'News', 'action' => 'list']) ;
}

public function getNewsletter()
{
$newsletter = $this->merchantUtils->getMerchantCurrent()->getNewsletter() ;
if($newsletter) {
return $newsletter ;
}
else {
throw new \ErrorException('Aucune newsletter n\'est liée à ce Merchant.') ;
}
}

public function getNews()
{
$idNews = $this->request->get('id') ;
$news = $this->em->getRepository($this->em->getClassMetadata(NewsInterface::class)->getName())->find($idNews) ;

if($news) {
return $news ;
}
else {
throw new NotFoundHttpException('Actualité introuvable') ;
}
}

}

+ 3
- 0
ShopBundle/Controller/Backend/ProductFamilyController.php View File

@@ -175,7 +175,10 @@ class ProductFamilyController extends AdminController
$this->processProducts($entity);
$this->processPrice($entity);
}

parent::updateEntity($entity);

$this->orderUtils->updatePriceByProductFamily($entity);
}

public function persistProductFamilyEntity($entity, $newForm)

+ 1
- 1
ShopBundle/Controller/Frontend/CartController.php View File

@@ -70,7 +70,7 @@ class CartController extends BaseController
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$orderShop = $this->orderUtils->getCartCurrent() ;
$orderShop = $this->orderUtils->getCartCurrent(true) ;
$data = $form->getData() ;
foreach($data as $orderProduct) {
if($orderProduct instanceof OrderProductInterface) {

+ 17
- 0
ShopBundle/Repository/OrderProductRepository.php View File

@@ -4,6 +4,7 @@ namespace Lc\ShopBundle\Repository;

use Lc\ShopBundle\Context\DefaultRepositoryInterface;
use Lc\ShopBundle\Context\OrderProductInterface;
use Lc\ShopBundle\Model\OrderStatus;

/**
* @method OrderProductInterface|null find($id, $lockMode = null, $lockVersion = null)
@@ -18,5 +19,21 @@ class OrderProductRepository extends BaseRepository implements DefaultRepository
return OrderProductInterface::class;
}

public function findOrderProductsInCartsByProduct($product){
$qb = $this->createQueryBuilder('e');
$qb->andWhere('e.product = :product');
$qb->andWhere('e.redelivery = false OR e.redelivery IS NULL');
$qb->setParameter('product', $product);
$qb->leftJoin('e.orderShop', 'orderShop');
$qb->andWhere('orderShop.merchant = :currentMerchant');
$qb->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent());
$qb->leftJoin('orderShop.orderStatus', 'orderStatus');
$qb->andWhere('orderStatus.alias IN (:alias)');
$qb->setParameter('alias',OrderStatus::ALIAS_CART);

return $qb->getQuery()->getResult();

}


}

+ 13
- 0
ShopBundle/Repository/OrderShopRepository.php View File

@@ -250,6 +250,19 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt

}

public function findLastOrderValid()
{
$query = $this->findByMerchantQuery();
$query = $this->filterOrderValid($query);
$query->andWhere('e.mainOrderShop = false OR e.mainOrderShop IS NULL');
$query->orderBy('e.validationDate', 'DESC');
$query->setMaxResults(1);

return $query->getQuery()->getOneOrNullResult();

}


public function countValidOrderProductsOfWeekByProduct($weekNumber, $productId)
{
$query = $this->findByMerchantQuery();

+ 1
- 0
ShopBundle/Repository/TicketRepository.php View File

@@ -27,6 +27,7 @@ class TicketRepository extends BaseRepository implements DefaultRepositoryInterf
{
$query = $this->findByMerchantQuery() ;
$query->andWhere('e.status IN (:statusOpen)')->setParameter('statusOpen', [Ticket::TICKET_STATUS_OPEN, Ticket::TICKET_STATUS_BEING_PROCESSED]) ;
$query->addOrderBy('e.id', 'DESC') ;
return $query->getQuery()->getResult() ;
}
}

+ 1
- 1
ShopBundle/Resources/public/js/backend/script/default/init-common.js View File

@@ -21,7 +21,7 @@ function initNotice() {
}

function initButtonConfirm() {
$('.btn-confirm-js').click(function () {
$('.btn-confirm-js, .action-confirm').click(function () {
return confirm('Êtes-vous sûr de vouloir réaliser cette action ?');
});
}

+ 1
- 1
ShopBundle/Resources/views/backend/default/list.html.twig View File

@@ -135,7 +135,7 @@
{% endblock new_action %}
{% endif %}
{% if _entity_config['list']['btn_init_export_purchase_order'] is defined %}
<a class="float-right btn-sm btn-success action-sort"
<a class="float-right btn-sm btn-success action-confirm"
href="{{ path('easyadmin', { entity: 'Supplier', action: 'initExportPurchaseOrder' }) }}">
<i class="fa fa-undo"></i> Réinitialiser export bons de commande
</a>

+ 1
- 0
ShopBundle/Services/Order/OrderUtils.php View File

@@ -99,6 +99,7 @@ class OrderUtils

public function addOrderProduct($orderShop, $orderProductAdd, $persist = true)
{

$return = false;

$user = $this->security->getUser();

+ 9
- 1
ShopBundle/Services/Order/OrderUtilsCartTrait.php View File

@@ -21,7 +21,7 @@ trait OrderUtilsCartTrait
}


public function getCartCurrent()
public function getCartCurrent($createIfNotExist = false)
{
$paramsSearchOrderShop = [];

@@ -63,6 +63,14 @@ trait OrderUtilsCartTrait
}
}

if($createIfNotExist && !$orderShop) {
$orderShop = $this->createOrderShop([
'user' => $user,
'visitor' => $visitor,
'merchant' => $this->merchantUtils->getMerchantCurrent()
]);
}

return $orderShop;
}


Loading…
Cancel
Save