src/Controller/Front/DistributionController.php line 78

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Slim Sayari
  5.  * Date: 10/07/2019
  6.  * Time: 13:43
  7.  */
  8. namespace App\Controller\Front;
  9. use App\Entity\Carrier;
  10. use App\Entity\Cart;
  11. use App\Entity\DistributionCart;
  12. use App\Entity\DistributionFlyer;
  13. use App\Entity\Orders;
  14. use App\Repository\DistributionCartRepository;
  15. use App\Services\CartService;
  16. use App\Services\CheckoutService;
  17. use App\Services\Notifications;
  18. use Symfony\Component\HttpFoundation\RedirectResponse;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  21. use Twig\Environment;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Doctrine\ORM\EntityManagerInterface;
  27. use Symfony\Contracts\Translation\TranslatorInterface;
  28. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  29. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  30. use App\Services\OrderService;
  31. use App\Services\DistributionFlyerService;
  32. /**
  33.  * @Route("/distribution")
  34.  */
  35. class DistributionController extends AbstractController
  36. {
  37.     private $em;
  38.     private $session;
  39.     private $trans;
  40.     private $cart_service;
  41.     private $authenticationUtils;
  42.     private $checkout_service;
  43.     private $notifications;
  44.     private $distributionFlyerService;
  45.     private $router;
  46.     public function __construct(
  47.         Notifications $notifications,
  48.         OrderService $order_service,
  49.         CheckoutService $checkout_service,
  50.         CartService $cart_service,
  51.         SessionInterface $session,
  52.         TranslatorInterface $trans,
  53.         EntityManagerInterface $em,
  54.         AuthenticationUtils $authenticationUtils,
  55.         DistributionFlyerService $distributionFlyerService,
  56.         UrlGeneratorInterface $router
  57.     ) {
  58.         $this->em $em;
  59.         $this->trans $trans;
  60.         $this->session $session;
  61.         $this->cart_service $cart_service;
  62.         $this->checkout_service $checkout_service;
  63.         $this->authenticationUtils $authenticationUtils;
  64.         $this->order_service $order_service;
  65.         $this->notifications $notifications;
  66.         $this->distributionFlyerService $distributionFlyerService;
  67.         $this->router $router;
  68.     }
  69.     /**
  70.      * @Route("/index", name="distribution_calcule")
  71.      */
  72.     public function index(Request $request): Response
  73.     {
  74.         $data $this->distributionFlyerService->add($request);
  75.         if(isset($data['success'])&&$data['success']){
  76.             return new RedirectResponse($this->router->generate('distribution_add_to_carte',array('id'=>$data['id_distribution'])));
  77.         }
  78.         $result $this->cart_service->checkB2bUser($this->getUser());
  79.         $abonnement $result['abonnement'];
  80.         $isAbonnementProInCart $result['isAbonnementProInCart'];
  81.         if($abonnement['is_abonnemen_pro'] || $isAbonnementProInCart){
  82.             return  $this->render('front/b2b/distribution/index.html.twig'$data);
  83.         }else{
  84.             return $this->render('front/distribution/index.html.twig'$data);
  85.         }
  86.     }
  87.     /**
  88.      * @Route("/edit/{id}", name="distribution_calcule_edit")
  89.      */
  90.     public function edit(Request $request,$id): Response
  91.     {
  92.         $data $this->distributionFlyerService->edit($request,$id);
  93.         if(isset($data['success'])&&$data['success']){
  94.             return new RedirectResponse($this->router->generate('distribution_add_to_carte',array('id'=>$data['id_distribution'])));
  95.         }
  96.         $result $this->cart_service->checkB2bUser($this->getUser());
  97.         $abonnement $result['abonnement'];
  98.         $isAbonnementProInCart $result['isAbonnementProInCart'];
  99.         if($abonnement['is_abonnemen_pro'] || $isAbonnementProInCart){
  100.             return  $this->render('front/b2b/distribution/index.html.twig'$data);
  101.         }else{
  102.             return $this->render('front/distribution/index.html.twig'$data);
  103.         }
  104.     }
  105.     /**
  106.      * @Route("/delete/{id}", name="distribution_calcule_delete")
  107.      */
  108.     public function delete(Request $request,$id): Response
  109.     {
  110.         $data $this->distributionFlyerService->delete($request,$id);
  111.         $refererPathInfo Request::create($request->headers->get('referer'))->getPathInfo();
  112.         $routeInfos $this->router->match($refererPathInfo);
  113.         $route = isset($routeInfos['_route'])? $routeInfos['_route'] :'checkout';
  114.         return  $this->redirectToRoute($route);
  115.     }
  116.     /**
  117.      * @Route("/add-to-carte/{id}", name="distribution_add_to_carte")
  118.      */
  119.     public function view(Request $request,$id): Response
  120.     {
  121.         $distribution $this->em->getRepository(DistributionCart::class)->find($id);
  122.         if($request->getMethod() == 'POST'){
  123.             $is_add $this->distributionFlyerService->addToCart($id);
  124.             if($is_add){
  125.                 return new RedirectResponse($this->router->generate('checkout'));
  126.             }else{
  127.                die('ereur!') ;
  128.             }
  129.         }
  130.         $result $this->cart_service->checkB2bUser($this->getUser());
  131.         $abonnement $result['abonnement'];
  132.         $isAbonnementProInCart $result['isAbonnementProInCart'];
  133.         if($abonnement['is_abonnemen_pro'] || $isAbonnementProInCart){
  134.             return  $this->render('front/b2b/distribution/view.html.twig',  array('distribution'=>$distribution));
  135.         }else{
  136.             return $this->render('front/distribution/view.html.twig',  array('distribution'=>$distribution));
  137.         }
  138.     }
  139. }