app/Customize/Controller/CustomTopController.php line 37

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 Customize\Controller;
  13. use Eccube\Repository\CategoryRepository;
  14. use Eccube\Repository\ProductRepository;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. class CustomTopController extends AbstractController
  19. {
  20.     private $productRepository;
  21.     private $categoryRepository;
  22.     public function __construct(ProductRepository $productRepositoryCategoryRepository $categoryRepository)
  23.     {
  24.         $this->productRepository $productRepository;
  25.         $this->categoryRepository $categoryRepository;
  26.     }
  27.     /**
  28.      * @Route("/", name="homepage", methods={"GET"})
  29.      * @Template("index.twig")
  30.      */
  31.     public function index()
  32.     {
  33.         $rank $this->getUser()->getRank();
  34.         // $newProducts = $this->productRepository->findBy(['Status' => \Eccube\Entity\Master\ProductStatus::DISPLAY_SHOW], ['create_date' => 'DESC'], 10); // 公開ステータスの商品を新しい順で10件取得
  35.         $newProducts $this->productRepository->findNew(5$rank); // 新着商品を5件取得
  36.         $productsCategory81 $this->productRepository->findWithCategory(8110$rank); // 特化商品を10件取得
  37.         $Category81 $this->categoryRepository->find(81);
  38.         // $names = array_map(function($product) {
  39.         //     return $product->getName();
  40.         // }, $products);
  41.         return [
  42.             'newProducts' => $newProducts,
  43.             'productsCategory81' => $productsCategory81,
  44.             'Category81' => $Category81,
  45.             // 'names' => $names,
  46.         ];
  47.     }
  48. }