src/Controller/Front/FrontController.php line 58

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use App\Manager\LanguageManager;
  8. class FrontController extends \App\Controller\BaseController
  9. {
  10. protected $cartMgr;
  11. protected $customerMgr;
  12. protected $categoryMgr;
  13. protected $productMgr;
  14. protected $redirectionMgr;
  15. protected $seenProductMgr;
  16. protected $attributeMgr;
  17. public function __construct(
  18. \App\Manager\PriceManager $priceMgr,
  19. \App\Manager\CartManager $cartMgr,
  20. \Symfony\Component\HttpKernel\KernelInterface $kernel,
  21. \App\Manager\CustomerManager $customerMgr,
  22. EntityManagerInterface $em,
  23. \App\Manager\RedirectionManager $redirectionMgr,
  24. \App\Manager\CategoryManager $categoryMgr,
  25. \App\Manager\SeenProductManager $seenProductMgr,
  26. \App\Manager\ProductManager $productMgr,
  27. \App\Manager\AttributeManager $attributeMgr
  28. ){
  29. $this->cartMgr = $cartMgr;
  30. $this->redirectionMgr = $redirectionMgr;
  31. $this->categoryMgr = $categoryMgr;
  32. $this->customerMgr = $customerMgr;
  33. $this->seenProductMgr = $seenProductMgr;
  34. $this->productMgr = $productMgr;
  35. $this->attributeMgr = $attributeMgr;
  36. parent::__construct($priceMgr, $kernel, $em);
  37. }
  38. /**
  39. * @Route("/", name="default_index")
  40. */
  41. public function defaultIndex(Request $request, LanguageManager $lgMgr)
  42. {
  43. return $this->redirect('/fr', 302);
  44. }
  45. /**
  46. * @Route("/{_locale}", name="index", requirements={"_locale":"fr|en"})
  47. */
  48. public function index(Request $request, \App\Manager\ModuleManager $moduleMgr, LanguageManager $lgMgr)
  49. {
  50. $moduleHooked = $moduleMgr->getHook('homepage');
  51. return $this->render('front/index.html.twig',[
  52. 'moduleHooked' => $moduleHooked
  53. ]);
  54. }
  55. /**
  56. * @Route("/{_locale}/maintenance", name="maintenance", requirements={"_locale":"fr|en"})
  57. */
  58. public function maintenance(Request $request)
  59. {
  60. return $this->render('front/maintenance.html.twig',[]);
  61. }
  62. /**
  63. * @Route("/{_locale}/email/test", name="email_test", requirements={"_locale":"fr|en"})
  64. */
  65. public function testEmail(\Doctrine\ORM\EntityManagerInterface $em, \App\Service\Mailer $mailer)
  66. {
  67. $rootCategories = $em->getRepository('App:Category')->getRoots();
  68. $mailer->sendOrderConfirmation($order);
  69. // return $this->render('mails/layout.html.twig',[
  70. // 'rootCategories' => $rootCategories
  71. // ]);
  72. }
  73. /**
  74. * @Route("/{_locale}/email/order", name="email_order", requirements={"_locale":"fr|en"})
  75. */
  76. public function orderEmail(\Doctrine\ORM\EntityManagerInterface $em, \App\Service\Mailer $mailer)
  77. {
  78. $order = $em->getRepository('App:Order')->find(90288);
  79. $mailer->sendOrderConfirmation($order);
  80. }
  81. /**
  82. * @Route("/send-email", name="sendemail")
  83. */
  84. public function sendEmail(\Swift_Mailer $mailer)
  85. {
  86. $message = (new \Swift_Message('Hello Email'))
  87. ->setFrom('website@dogcat.com')
  88. ->setTo('qkaulek@gmail.com')
  89. ->setBody('You should see me from the profiler!');
  90. $mailer->send($message);
  91. return $this->redirectToRoute('index');
  92. }
  93. /**
  94. * @Route("/change-locale/{_locale}", name="change_locale", requirements={"_locale=":"en|fr"})
  95. */
  96. public function changeLocale(Request $request, LanguageManager $lgMgr)
  97. {
  98. $request->getSession()->set('_locale', $request->getLocale());
  99. $lgMgr->switchTo($request->getLocale());
  100. $redirect = $request->get('redirect',null);
  101. if($redirect){
  102. return $this->redirect($redirect);
  103. }
  104. return $this->redirectToRoute('index');
  105. }
  106. protected function getDiscountList($products)
  107. {
  108. $priceGroup = $this->cartMgr->getPriceContext();
  109. $em = $this->getDoctrine()->getManager();
  110. $data = [];
  111. $prices = [];
  112. foreach($products as $product) {
  113. $parent = $product;
  114. if($product->hasChildren() && $product->getFromProduct($priceGroup)) {
  115. $product = $product->getFromProduct($priceGroup);
  116. }
  117. $discounts = $em->getRepository(\App\Entity\MarketingRule::class)->getByProduct($product, true);
  118. if($discounts) {
  119. foreach($discounts as $discount){
  120. $price = $this->priceMgr->getPrice($product, 1, false);
  121. if(empty($data[$parent->getId()]) || ($prices[$parent->getId()] > $price)) {
  122. $prices[$parent->getId()] = $price;
  123. $data[$parent->getId()] = $discount->getTitle();
  124. }
  125. }
  126. }
  127. }
  128. return $data;
  129. }
  130. }