<?php
/*
* This file is part of the Sylius package.
*
* (c) Paweł Jędrzejewski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare (strict_types = 1);
namespace App\Controller;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
*
* @Route({
* "en": "{_locale}/group",
* "es_CL": "{_locale}/grupo"
* }, name="app_group")
*/
class GroupController extends AbstractController
{
/**
* @Route({
* "en": "/",
* "es_CL": "/"
* }, name="_index")
*/
public function index(TaxonRepositoryInterface $taxonRepository): Response {
$parentGroup = $taxonRepository->findOneByCode('products-and-services');
$parentGroupCode = $parentGroup ? $parentGroup->getCode() : null;
// return $this->redirectToRoute('app_group_render_group', ['groupId' => $parentGroup->getId()]);
return $this->forward('App\Controller\GroupController::renderGroup', [
'groupCode' => $parentGroupCode
]);
}
/**
* @Route({
* "en": "/show/{groupCode}",
* "es_CL": "/ver/{groupCode}"
* }, name="_render_group")
*/
public function renderGroup($groupCode, TaxonRepositoryInterface $taxonRepository): Response
{
$parentGroup = $taxonRepository->findOneByCode($groupCode);
return $this->render('app/Group/index.html.twig', array(
'group' => $parentGroup
));
}
/**
* @Route({
* "en": "/show/{groupCode}/products",
* "es_CL": "/ver/{groupCode}/productos"
* }, name="_render_group_products")
*/
public function renderGroupProducts(
$groupCode,
TaxonRepositoryInterface $taxonRepository,
ChannelContextInterface $channelContext,
ProductRepositoryInterface $productRepository
): Response {
$parentGroup = $taxonRepository->findOneByCode($groupCode);
$currentChannel = $channelContext->getChannel();
$products = $productRepository->findAllOnTaxon($parentGroup, $currentChannel);
return $this->render('app/Group/index.html.twig', array(
'group' => $parentGroup,
'products' => $products
));
}
}