src/Eccube/Controller/TopController.php line 19

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller;
  13. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class TopController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="homepage", methods={"GET"})
  19.      * @Template("index.twig")
  20.      */
  21.     public function index()
  22.     {
  23.         $conn $this->entityManager->getConnection();
  24.         $sql '
  25.             SELECT p.*, sp.sort_no 
  26.             FROM dtb_product p
  27.             INNER JOIN plg_sort_product sp ON p.id = sp.id
  28.             WHERE p.product_status_id = 1
  29.             ORDER BY sp.sort_no DESC
  30.             LIMIT 12
  31.         ';
  32.         $stmt $conn->executeQuery($sql);
  33.         $products $stmt->fetchAll();
  34.         // 結果をエンティティにマッピングします。
  35.         $productEntities = [];
  36.         foreach ($products as $product) {
  37.             $productEntity $this->entityManager->getRepository('Eccube\Entity\Product')->find($product['id']);
  38.             $productEntities[] = $productEntity;
  39.         }
  40.         return $this->render('index.twig', ['products' => $productEntities]);
  41.     }
  42. }