src/Flexy/FrontBundle/Controller/CategoryProductController.php line 60

Open in your IDE?
  1. <?php
  2. namespace App\Flexy\FrontBundle\Controller;
  3. use App\Flexy\ShopBundle\Entity\Product\CategoryProduct;
  4. use App\Flexy\ProductBundle\Repository\CategoryProductRepository;
  5.  
  6. use App\Flexy\ShopBundle\Repository\Product\ProductRepository;
  7. use App\Flexy\ShopBundle\Entity\Brand;
  8. use App\Flexy\ShopBundle\Entity\Product\ProductShop;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Knp\Component\Pager\PaginatorInterface;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. #[Route('/shop')]
  16. class CategoryProductController extends AbstractController
  17. {
  18.     #[Route('/category-product/{id}'name'single_category_product')]
  19.     public function singleProduct(
  20.         CategoryProduct $categoryProduct,
  21.         EntityManagerInterface $em
  22.         PaginatorInterface $paginator
  23.         Request $request
  24.         ): Response
  25.     {
  26.         $dql   "SELECT product FROM App\Flexy\ShopBundle\Entity\Product\Product product LEFT OUTER JOIN product.categoriesProduct categorie WhERE categorie.id =  ".$categoryProduct->getId()." AND  product.isPublished = TRUE";
  27.         $query $em->createQuery($dql);
  28.         
  29.           
  30.         $pagination $paginator->paginate(
  31.             $query/* query NOT result */
  32.             $request->query->getInt('page'1), /*page number*/
  33.             10 /*limit per page*/
  34.         );
  35.         if( $categoryProduct->getId() == 75)  {
  36.             return $this->render('@Flexy\FrontBundle/templates/food/PageFood.html.twig', [
  37.                 'categoryProduct' => $categoryProduct
  38.     
  39.             ]);
  40.         }else{
  41.         return $this->render('@Flexy\FrontBundle/templates/categories/singleCategoryProduct.html.twig', [
  42.             'categoryProduct' => $categoryProduct,
  43.             "products"=>$pagination
  44.         ]);
  45.     }
  46.     }
  47.     
  48.         #[Route('/brand-product/{id}'name'single_brand_product')]
  49.         public function singleBrand(
  50.             Brand $brand,
  51.             EntityManagerInterface $em
  52.             PaginatorInterface $paginator
  53.             Request $request
  54.             ): Response
  55.         {
  56.     
  57.             $dql   "SELECT product FROM App\Flexy\ShopBundle\Entity\Product\Product product LEFT OUTER JOIN product.brand brand WhERE brand.id =  ".$brand->getId()." AND  product.isPublished = TRUE";
  58.             $query $em->createQuery($dql);
  59.             
  60.     
  61.             $pagination $paginator->paginate(
  62.                 $query/* query NOT result */
  63.                 $request->query->getInt('page'1), /*page number*/
  64.                 10 /*limit per page*/
  65.             );
  66.             return $this->render('@Flexy\FrontBundle/templates/brand/singleBrandProduct.html.twig', [
  67.                 'brand' => $brand,
  68.                 "products"=>$pagination
  69.     
  70.             ]);
  71.         }
  72.         #[Route('/category-announce/{id}'name'announce_category_product')]
  73.         public function singleCategory(
  74.             CategoryProduct $categoryProduct,
  75.             EntityManagerInterface $em
  76.             ProductRepository $productRepository,
  77.             PaginatorInterface $paginator
  78.             Request $request
  79.             ): Response
  80.         {
  81.     
  82.             $dql   "SELECT product FROM App\Flexy\ShopBundle\Entity\Product\Product product WhERE product.parentCategory =  ".$categoryProduct->getId()."   AND  product.isPublished = TRUE";
  83.             $query $em->createQuery($dql);
  84.             
  85.             
  86.     
  87.             $pagination $paginator->paginate(
  88.                 $query/* query NOT result */
  89.                 $request->query->getInt('page'1), /*page number*/
  90.                 10 /*limit per page*/
  91.             );
  92.             return $this->render('@Flexy\FrontBundle/templates/categories/announceCategoryProduct.html.twig', [
  93.                 'categoryProduct' =>  $productRepository->findBy(["id"=>$categoryProduct->getId()]),              
  94.                 "products"=>$pagination
  95.     
  96.             ]);
  97.         }
  98.     
  99. }