src/Controller/Front/Modules/SeenProductsController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Front\Modules;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use App\Manager\SeenProductManager;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  10. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  11. class SeenProductsController extends \App\Controller\Front\FrontController
  12. {
  13. public function block(Request $request, EntityManagerInterface $em, SeenProductManager $seenMgr)
  14. {
  15. $ids = $seenMgr->getSeenProducts();
  16. $products = [];
  17. foreach($ids as $id){
  18. $p = $em->getRepository('App:Product')->find($id);
  19. if($p)
  20. $products[] = $p;
  21. }
  22. $products = array_reverse($products);
  23. return $this->render('front/modules/seen-products/block.html.twig', [
  24. 'products' => $products
  25. ]);
  26. }
  27. /**
  28. * @Route("/{_locale}/seen-products/clear", name="seen_products_clear", requirements={"_locale":"fr|en"})
  29. */
  30. public function clear(Request $request, SeenProductManager $seenProductMgr)
  31. {
  32. $seenProductMgr->clear();
  33. $from = $request->get('from',false);
  34. if(empty($from)){
  35. $from = $this->generateUrl('index');
  36. }
  37. return $from;
  38. }
  39. }