<?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 Customize\Controller;
use Eccube\Repository\CategoryRepository;
use Eccube\Repository\ProductRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class CustomTopController extends AbstractController
{
private $productRepository;
private $categoryRepository;
public function __construct(ProductRepository $productRepository, CategoryRepository $categoryRepository)
{
$this->productRepository = $productRepository;
$this->categoryRepository = $categoryRepository;
}
/**
* @Route("/", name="homepage", methods={"GET"})
* @Template("index.twig")
*/
public function index()
{
$rank = $this->getUser()->getRank();
// $newProducts = $this->productRepository->findBy(['Status' => \Eccube\Entity\Master\ProductStatus::DISPLAY_SHOW], ['create_date' => 'DESC'], 10); // 公開ステータスの商品を新しい順で10件取得
$newProducts = $this->productRepository->findNew(5, $rank); // 新着商品を5件取得
$productsCategory81 = $this->productRepository->findWithCategory(81, 10, $rank); // 特化商品を10件取得
$Category81 = $this->categoryRepository->find(81);
// $names = array_map(function($product) {
// return $product->getName();
// }, $products);
return [
'newProducts' => $newProducts,
'productsCategory81' => $productsCategory81,
'Category81' => $Category81,
// 'names' => $names,
];
}
}