src/App/Controller/GroupController.php line 52

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare (strict_types 1);
  11. namespace App\Controller;
  12. use Sylius\Component\Channel\Context\ChannelContextInterface;
  13. use Sylius\Component\Core\Repository\ProductRepositoryInterface;
  14. use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. /**
  19.  *
  20.  * @Route({
  21.  *     "en": "{_locale}/group",
  22.  *     "es_CL": "{_locale}/grupo"
  23.  * }, name="app_group")
  24.  */
  25. class GroupController extends AbstractController
  26. {
  27.     /**
  28.      * @Route({
  29.      *     "en": "/",
  30.      *     "es_CL": "/"
  31.      * }, name="_index")
  32.      */
  33.     public function index(TaxonRepositoryInterface $taxonRepository): Response {
  34.         $parentGroup $taxonRepository->findOneByCode('products-and-services');
  35.         $parentGroupCode $parentGroup $parentGroup->getCode() : null;
  36.         // return $this->redirectToRoute('app_group_render_group', ['groupId' => $parentGroup->getId()]);
  37.         return $this->forward('App\Controller\GroupController::renderGroup', [
  38.             'groupCode' => $parentGroupCode
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route({
  43.      *     "en": "/show/{groupCode}",
  44.      *     "es_CL": "/ver/{groupCode}"
  45.      * }, name="_render_group")
  46.      */
  47.     public function renderGroup($groupCodeTaxonRepositoryInterface $taxonRepository): Response
  48.     {
  49.         $parentGroup $taxonRepository->findOneByCode($groupCode);
  50.         return $this->render('app/Group/index.html.twig', array(
  51.             'group' => $parentGroup
  52.         ));
  53.     }
  54.     /**
  55.      * @Route({
  56.      *     "en": "/show/{groupCode}/products",
  57.      *     "es_CL": "/ver/{groupCode}/productos"
  58.      * }, name="_render_group_products")
  59.      */
  60.     public function renderGroupProducts(
  61.         $groupCode,
  62.         TaxonRepositoryInterface $taxonRepository,
  63.         ChannelContextInterface $channelContext,
  64.         ProductRepositoryInterface $productRepository
  65.     ): Response {
  66.         $parentGroup $taxonRepository->findOneByCode($groupCode);
  67.         $currentChannel $channelContext->getChannel();
  68.         $products $productRepository->findAllOnTaxon($parentGroup$currentChannel);
  69.         return $this->render('app/Group/index.html.twig', array(
  70.             'group' => $parentGroup,
  71.             'products' => $products
  72.         ));
  73.     }
  74. }