app/Customize/Controller/TopController.php line 49

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\CartRepository;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Eccube\Controller\AbstractController;
  19. use Eccube\Repository\ProductRepository;
  20. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  21. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  22. use Eccube\Repository\PluginRepository;
  23. class TopController extends AbstractController
  24. {
  25.     /**
  26.      * @var ProductRepository
  27.      */
  28.     protected $productRepository;
  29.     /**
  30.      * @param ProductRepository $productRepository
  31.      */
  32.     public function __construct(ProductRepository $productRepositoryPluginRepository $pluginRepository) {
  33.         $this->productRepository $productRepository;
  34.         $this->pluginRepository $pluginRepository;
  35.     }
  36.     /**
  37.      * @Route("/", name="homepage", methods={"GET"})
  38.      * @Template("index.twig")
  39.      */
  40.     public function index()
  41.     {
  42.       $products $this->productRepository->findby([], ['id' => 'DESC'], 3);
  43.     //    $this->pluginRepository->insert([
  44.     //        'name' => 'AlwaysReCaptcha42',
  45.     //        'code' => 'AlwaysReCaptcha42',
  46.     //        'enabled' => 1,
  47.     //        'version' => '2.4.2',
  48.     //        'source' => '2618',
  49.     //        'initialized' => 1
  50.     //    ]);
  51.     // $Plugin = new Plugin();
  52.     //                 $Plugin->setName("AlwaysReCaptcha42");
  53.     //                 $Plugin->setCode("AlwaysReCaptcha42");
  54.     //                 $Plugin->setVersion("2.4.2");
  55.     //                 $Plugin->setSource("2618");
  56.     //                 $Plugin->setEnabled(true);
  57.     //                 $Plugin->setInitialized(true);
  58.     //   $p = $this->pluginRepository->save($Plugin);
  59.     //   dd($p);
  60.       return [
  61.           'Products' => $products,
  62.       ];
  63.     }
  64.     /**
  65.      * @Route("/deleteCartLowDate", name="deleteCartLowDate", methods={"GET"})
  66.      */
  67.     public function deleteCartLowDate(CartRepository $cartRepositoryRequest $request) {
  68.         try {
  69.             $Cart $cartRepository->createQueryBuilder('c')->delete()->where('c.create_date < :createDate')
  70.                 ->setParameter(':createDate'date('Y-m-d 00:00:00'strtotime('-3 weeks')))->getQuery()->getResult();
  71.             $this->entityManager->flush();
  72.             $this->entityManager->commit();
  73.             return new JsonResponse(['status' => 1,], 200);
  74.         } catch (\Exception $e) {
  75.             $this->entityManager->rollback();
  76.             return new JsonResponse(['status' => 2,], 200);
  77.         }
  78.     }
  79. }