<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Eccube\Controller;
use Eccube\Controller\AbstractController;
use Eccube\Repository\ProductRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class TopController extends AbstractController
{
private $productRepository;
public function __construct(ProductRepository $productRepository)
{
$this->productRepository = $productRepository;
}
/**
* @Route("/", name="homepage")
*/
public function index(Request $request): Response
{
$searchData = array();
$qb = $this->entityManager->createQueryBuilder();
$query = $qb->select("plob")
->from("Eccube\\Entity\\Master\\ProductListOrderBy", "plob")
->where('plob.id = :id')
//->setParameter('id', $this->eccubeConfig['eccube_product_order_newer'])
->setParameter('id', 4)
->getQuery();
$searchData['orderby'] = $query->getOneOrNullResult();
/*$cat_id = 8;
$qb = $this->entityManager->createQueryBuilder();
$query = $qb->select("ctg")
->from("Eccube\\Entity\\Category", "ctg")
->where('ctg.id = :id')
->setParameter('id', $cat_id)
->getQuery();
$searchData['category_id'] = $query->getOneOrNullResult();*/
$qb = $this->productRepository->getQueryBuilderBySearchData($searchData);
$query = $qb->setMaxResults(20)->getQuery();
$products = $query->getResult();
return $this->render('index.twig', [
'Products' => $products,
]);
}
}