<?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\CartRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Eccube\Controller\AbstractController;
use Eccube\Repository\ProductRepository;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
use Eccube\Repository\PluginRepository;
class TopController extends AbstractController
{
/**
* @var ProductRepository
*/
protected $productRepository;
/**
* @param ProductRepository $productRepository
*/
public function __construct(ProductRepository $productRepository, PluginRepository $pluginRepository) {
$this->productRepository = $productRepository;
$this->pluginRepository = $pluginRepository;
}
/**
* @Route("/", name="homepage", methods={"GET"})
* @Template("index.twig")
*/
public function index()
{
$products = $this->productRepository->findby([], ['id' => 'DESC'], 3);
// $this->pluginRepository->insert([
// 'name' => 'AlwaysReCaptcha42',
// 'code' => 'AlwaysReCaptcha42',
// 'enabled' => 1,
// 'version' => '2.4.2',
// 'source' => '2618',
// 'initialized' => 1
// ]);
// $Plugin = new Plugin();
// $Plugin->setName("AlwaysReCaptcha42");
// $Plugin->setCode("AlwaysReCaptcha42");
// $Plugin->setVersion("2.4.2");
// $Plugin->setSource("2618");
// $Plugin->setEnabled(true);
// $Plugin->setInitialized(true);
// $p = $this->pluginRepository->save($Plugin);
// dd($p);
return [
'Products' => $products,
];
}
/**
* @Route("/deleteCartLowDate", name="deleteCartLowDate", methods={"GET"})
*/
public function deleteCartLowDate(CartRepository $cartRepository, Request $request) {
try {
$Cart = $cartRepository->createQueryBuilder('c')->delete()->where('c.create_date < :createDate')
->setParameter(':createDate', date('Y-m-d 00:00:00', strtotime('-3 weeks')))->getQuery()->getResult();
$this->entityManager->flush();
$this->entityManager->commit();
return new JsonResponse(['status' => 1,], 200);
} catch (\Exception $e) {
$this->entityManager->rollback();
return new JsonResponse(['status' => 2,], 200);
}
}
}