<?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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
class TopController extends AbstractController
{
/**
* @Route("/", name="homepage", methods={"GET"})
* @Template("index.twig")
*/
public function index()
{
$conn = $this->entityManager->getConnection();
$sql = '
SELECT p.*, sp.sort_no
FROM dtb_product p
INNER JOIN plg_sort_product sp ON p.id = sp.id
WHERE p.product_status_id = 1
ORDER BY sp.sort_no DESC
LIMIT 12
';
$stmt = $conn->executeQuery($sql);
$products = $stmt->fetchAll();
// 結果をエンティティにマッピングします。
$productEntities = [];
foreach ($products as $product) {
$productEntity = $this->entityManager->getRepository('Eccube\Entity\Product')->find($product['id']);
$productEntities[] = $productEntity;
}
return $this->render('index.twig', ['products' => $productEntities]);
}
}