app/Customize/Controller/MypageController.php line 90

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\Entity\BaseInfo;
  14. use Eccube\Event\EccubeEvents;
  15. use Eccube\Event\EventArgs;
  16. use Customize\Form\Type\SearchFavoriteProductType;
  17. use Customize\Form\Type\SearchInvoiceFileType;
  18. use DateTime;
  19. use Eccube\Repository\BaseInfoRepository;
  20. use Eccube\Repository\CategoryRepository;
  21. use Eccube\Repository\CustomerFavoriteProductRepository;
  22. use Eccube\Repository\OrderRepository;
  23. use Eccube\Repository\ProductRepository;
  24. use Eccube\Service\CartService;
  25. use Eccube\Service\PurchaseFlow\PurchaseFlow;
  26. use Knp\Component\Pager\PaginatorInterface;
  27. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  28. use Symfony\Component\HttpFoundation\Request;
  29. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  30. use Symfony\Component\Routing\Annotation\Route;
  31. class MypageController extends \Eccube\Controller\Mypage\MypageController
  32. {
  33.     private CategoryRepository $categoryRepository;
  34.     
  35.     /**
  36.      * @var ProductRepository
  37.      */
  38.     protected $productRepository;
  39.     /**
  40.      * @var CustomerFavoriteProductRepository
  41.      */
  42.     protected $customerFavoriteProductRepository;
  43.     /**
  44.      * @var BaseInfo
  45.      */
  46.     protected $BaseInfo;
  47.     /**
  48.      * @var CartService
  49.      */
  50.     protected $cartService;
  51.     /**
  52.      * @var OrderRepository
  53.      */
  54.     protected $orderRepository;
  55.     /**
  56.      * @var PurchaseFlow
  57.      */
  58.     protected $purchaseFlow;
  59.     public function __construct(
  60.         CategoryRepository $categoryRepository,
  61.         OrderRepository $orderRepository,
  62.         CustomerFavoriteProductRepository $customerFavoriteProductRepository,
  63.         CartService $cartService,
  64.         BaseInfoRepository $baseInfoRepository,
  65.         PurchaseFlow $purchaseFlow
  66.     ) {
  67.         $this->categoryRepository $categoryRepository;
  68.         $this->orderRepository $orderRepository;
  69.         $this->customerFavoriteProductRepository $customerFavoriteProductRepository;
  70.         $this->BaseInfo $baseInfoRepository->get();
  71.         $this->cartService $cartService;
  72.         $this->purchaseFlow $purchaseFlow;
  73.     }
  74.     /**
  75.      * お気に入り商品を表示する.
  76.      *
  77.      * @Route("/mypage/favorite", name="mypage_favorite", methods={"GET"})
  78.      * @Template("Mypage/favorite.twig")
  79.      */
  80.     public function favorite(Request $requestPaginatorInterface $paginator)
  81.     {
  82.         if (!$this->BaseInfo->isOptionFavoriteProduct()) {
  83.             throw new NotFoundHttpException();
  84.         }
  85.         if ($request->getMethod() === 'GET') {
  86.             $request->query->set('pageno'$request->query->get('pageno'''));
  87.         }
  88.         $Customer $this->getUser();
  89.         $builder $this->formFactory->createNamedBuilder(''SearchFavoriteProductType::class);
  90.         if ($request->getMethod() === 'GET') {
  91.             $builder->setMethod('GET');
  92.         }
  93.         /* @var $searchForm \Symfony\Component\Form\FormInterface */
  94.         $searchForm $builder->getForm();
  95.         $searchForm->handleRequest($request);
  96.         // paginator
  97.         $searchData $searchForm->getData();
  98.         $qb $this->customerFavoriteProductRepository->getQueryBuilderByCustomerWithSearchData($Customer$searchData);
  99.         $event = new EventArgs(
  100.             [
  101.                 'qb' => $qb,
  102.                 'Customer' => $Customer,
  103.             ],
  104.             $request
  105.         );
  106.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_MYPAGE_MYPAGE_FAVORITE_SEARCH);
  107.         $pagination $paginator->paginate(
  108.             $qb,
  109.             !empty($searchData['pageno']) ? $searchData['pageno'] : 1,
  110.             !empty($searchData['disp_number']) ? $searchData['disp_number']->getId() : $this->eccubeConfig['eccube_search_pmax']
  111.         );
  112.         $Category null;
  113.         if (!empty($searchForm->get('category_id')->getData())) {
  114.             $Category $this->categoryRepository->find($searchForm->geT('category_id')->getData());
  115.         }
  116.         return [
  117.             'pagination' => $pagination,
  118.             'search_form' => $searchForm->createView(),
  119.             'Category' => $Category
  120.         ];
  121.     }
  122.     /**
  123.      * お気に入り商品を表示する.
  124.      *
  125.      * @Route("/mypage/invoice", name="mypage_invoice", methods={"GET"})
  126.      * @Template("Mypage/invoice.twig")
  127.      */
  128.     public function invoice(Request $request)
  129.     {
  130.         $builder $this->formFactory->createNamedBuilder(''SearchInvoiceFileType::class);
  131.         if ($request->getMethod() === 'GET') {
  132.             $builder->setMethod('GET');
  133.         }
  134.         $searchForm $builder->getForm();
  135.         $searchForm->handleRequest($request);
  136.         // paginator
  137.         $searchData $searchForm->getData();
  138.         /** @var \Eccube\Entity\Customer $Customer */
  139.         $Customer $this->getUser();
  140.         $data = [];
  141.         if ($Customer) {
  142.             $year = isset($searchData['year']) ? $searchData['year'] : date('Y');
  143.             $dirPath $this->eccubeConfig->get('eccube_html_dir').'/user_data/assets/seikyu/'.$Customer->getId().'/';
  144.             if (is_dir($dirPath)) {
  145.                 $invoices preg_grep('~^'.$year.'~'scandir($dirPath));
  146.                 if (!empty($invoices)) {
  147.                     foreach ($invoices as $key => $fileName) {
  148.                         $date explode('_'$fileName)[0];
  149.                         $date DateTime::createFromFormat('Ym'$date);
  150.                         $date $date->format('n');
  151.         
  152.                         $data[$date] = $Customer->getId().'/'.$fileName;
  153.                     }
  154.                     uksort($data, function($key1$key2) {
  155.                         return $key2 <=> $key1;
  156.                     });
  157.                 }
  158.             }
  159.         }
  160.         return [
  161.             'invoices' => $data,
  162.             'searchForm' => $searchForm->createView(),
  163.         ];
  164.     }
  165. }