<?php
namespace App\Controller\Front\Modules;
use Symfony\Component\HttpFoundation\Request;
use App\Manager\SeenProductManager;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class SeenProductsController extends \App\Controller\Front\FrontController
{
public function block(Request $request, EntityManagerInterface $em, SeenProductManager $seenMgr)
{
$ids = $seenMgr->getSeenProducts();
$products = [];
foreach($ids as $id){
$p = $em->getRepository('App:Product')->find($id);
if($p)
$products[] = $p;
}
$products = array_reverse($products);
return $this->render('front/modules/seen-products/block.html.twig', [
'products' => $products
]);
}
/**
* @Route("/{_locale}/seen-products/clear", name="seen_products_clear", requirements={"_locale":"fr|en"})
*/
public function clear(Request $request, SeenProductManager $seenProductMgr)
{
$seenProductMgr->clear();
$from = $request->get('from',false);
if(empty($from)){
$from = $this->generateUrl('index');
}
return $from;
}
}