<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) Takashi Otaki All Rights Reserved.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Plugin\EtunaCheckedItem\Controller;
use Plugin\EtunaCheckedItem\Repository\EtunaCheckedItemConfigRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Eccube\Repository\ProductRepository;
/**
* Class EtunaCheckedItemController front.
*/
class EtunaCheckedItemController extends \Eccube\Controller\AbstractController
{
/**
* @Route("/block/etuna_checked_item", name="block_etuna_checked_item")
* @Template("Block/etuna_checked_item.twig")
*
* @param Request $request
* @param EtunaCheckedItemConfigRepository $configRepository
* @param ProductRepository $productRepository
*/
public function index(Request $request, EtunaCheckedItemConfigRepository $configRepository, ProductRepository $productRepository)
{
$Config = $configRepository->get();
$checkedItemArray = array();
$checkedItems = $request->cookies->get('CheckedItemIds');
$checkedItemsArray = array_reverse(explode("_", $checkedItems));
foreach ($checkedItemsArray as $checkedItemsId) {
$qb = $productRepository->createQueryBuilder('p')
->where('p.id = :id')
->andWhere('p.Status = 1')
->setParameter('id', $checkedItemsId)
;
$CheckedItem = $qb->getQuery()->getResult();
if ($CheckedItem != null) {
$checkedItemArray[] = $CheckedItem;
}
}
return [
'Config' => $Config,
'CheckedItem' => $checkedItemArray,
];
}
}