<?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 Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Controller\AbstractController;
use Eccube\Repository\ProductRepository;
use Plugin\CMBlogPro42\Repository\BlogRepository;
class CustomTopController extends AbstractController
{
public function __construct(
BlogRepository $blogRepository,
ProductRepository $productRepository
)
{
$this->blogRepository = $blogRepository;
$this->productRepository = $productRepository;
}
/**
* @Route("/", name="homepage", methods={"GET"})
* @Template("index.twig")
*/
public function index()
{
$news = $this->blogRepository->getList();
$qb = $this->productRepository->getQueryBuilderBySearchData([]);
// is_hiddenフラグで非表示商品を除外
$qb->andWhere('p.is_hidden = :is_hidden OR p.is_hidden IS NULL')
->setParameter('is_hidden', false);
$qb->orderBy('p.id', 'ASC');
$products = $qb->getQuery()->getResult();
$subMapRaw = getenv('SUBSCRIPTION_MAP');
$subMap = [];
if (!empty($subMapRaw)) {
$subMapRaw = explode(',', $subMapRaw);
foreach ($subMapRaw as $map) {
$map = explode(':', $map);
$subMap[$map[0]] = $map[1];
}
}
return ['news' => $news, 'products' => $products, 'subMap' => $subMap];
}
}