src/Controller/Action/DisplayProductByBrandControllerAction.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller\Action;
  4. use App\Entity\Product\Product;
  5. use App\Entity\Taxonomy\Taxon;
  6. use App\Repository\Brand\BrandRepository;
  7. use App\Repository\Product\ProductRepository;
  8. use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository;
  9. use Sylius\Component\Channel\Context\ChannelContextInterface;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\Routing\RouterInterface;
  14. use Twig\Environment;
  15. final class DisplayProductByBrandControllerAction
  16. {
  17.     private Environment $twig;
  18.     private RouterInterface $router;
  19.     private ChannelContextInterface $channelContext;
  20.     public function __construct(
  21.         Environment $twig,
  22.         ChannelContextInterface $channelContext,
  23.         RouterInterface $router
  24.     ) {
  25.         $this->twig $twig;
  26.         $this->router $router;
  27.         $this->channelContext $channelContext;
  28.     }
  29.     public function __invoke(Request $requestBrandRepository $brandRepositoryProductRepository $productRepositoryTaxonRepository $taxonRepository)
  30.     {
  31.         $code $request->get('code');
  32.         if (!$code) {
  33.             return new RedirectResponse($this->router->generate('app_shop_brand_index'));
  34.         }
  35.         $brand $brandRepository->findOneBy(['code' => $code]);
  36.         if (!$brand) {
  37.             return new RedirectResponse($this->router->generate('app_shop_brand_index'));
  38.         }
  39.         // trier les produits par catégorie
  40. //        $taxons = [];
  41.         $products $productRepository->findAllByBrand($brand$this->channelContext->getChannel());
  42. //        /** @var Product $product */
  43. //        foreach ($products as $product) {
  44. //            /** @var Taxon $taxon */
  45. //            foreach ($product->getTaxons() as $taxon) {
  46. //                $taxons[$taxon->getId()]['taxon'] = $taxon;
  47. //                $taxons[$taxon->getId()]['products'][$product->getId()] = $product;
  48. //            }
  49. //        }
  50.         return new Response($this->twig->render('@SyliusShop/Brand/Product/index.html.twig', [
  51.             'brand' => $brand,
  52. //            'taxons' => $taxons,
  53.             'products' => $products
  54.         ]));
  55.     }
  56. }