<?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\Mypage;
use Customize\Service\QrCodeService;
use Eccube\Controller\AbstractController;
use Eccube\Controller\Mypage\MypageController as MypageMypageController;
use Eccube\Entity\BaseInfo;
use Eccube\Entity\Customer;
use Eccube\Entity\Order;
use Eccube\Entity\Product;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Exception\CartException;
use Eccube\Form\Type\Front\CustomerLoginType;
use Eccube\Repository\BaseInfoRepository;
use Eccube\Repository\CustomerFavoriteProductRepository;
use Eccube\Repository\OrderRepository;
use Eccube\Repository\ProductRepository;
use Eccube\Service\CartService;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Service\PurchaseFlow\PurchaseFlow;
use Knp\Component\Pager\PaginatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class MypageController extends MypageMypageController
{
/** @var QrCodeService */
private $qrCodeService;
/**
* MypageController constructor.
*
* @param OrderRepository $orderRepository
* @param CustomerFavoriteProductRepository $customerFavoriteProductRepository
* @param CartService $cartService
* @param BaseInfoRepository $baseInfoRepository
* @param PurchaseFlow $purchaseFlow
* @param QrCodeService $qrCodeService
*/
public function __construct(
OrderRepository $orderRepository,
CustomerFavoriteProductRepository $customerFavoriteProductRepository,
CartService $cartService,
BaseInfoRepository $baseInfoRepository,
PurchaseFlow $purchaseFlow,
QrCodeService $qrCodeService,
) {
parent::__construct($orderRepository,$customerFavoriteProductRepository,$cartService,$baseInfoRepository,$purchaseFlow);
$this->qrCodeService = $qrCodeService;
}
/**
* ログイン画面.
*
* @Route("/mypage/login", name="mypage_login", methods={"GET", "POST"})
* @Template("Mypage/login.twig")
*/
public function login(Request $request, AuthenticationUtils $utils)
{
if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
log_info('認証済のためログイン処理をスキップ');
return $this->redirectToRoute('mypage');
}
/* @var $form \Symfony\Component\Form\FormInterface */
$builder = $this->formFactory
->createNamedBuilder('', CustomerLoginType::class);
$builder->get('login_memory')->setData((bool) $request->getSession()->get('_security.login_memory'));
if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
$Customer = $this->getUser();
if ($Customer instanceof Customer) {
$builder->get('login_email')
->setData($Customer->getEmail());
}
}
$event = new EventArgs(
[
'builder' => $builder,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_MYPAGE_MYPAGE_LOGIN_INITIALIZE);
$form = $builder->getForm();
return [
'error' => $utils->getLastAuthenticationError(),
'form' => $form->createView(),
];
}
/**
* マイページ.
*
* @Route("/mypage/", name="mypage", methods={"GET"})
* @Template("Mypage/index.twig")
*/
public function index(Request $request, PaginatorInterface $paginator)
{
$Customer = $this->getUser();
// 購入処理中/決済処理中ステータスの受注を非表示にする.
$this->entityManager
->getFilters()
->enable('incomplete_order_status_hidden');
// paginator
$qb = $this->orderRepository->getQueryBuilderByCustomer($Customer);
$event = new EventArgs(
[
'qb' => $qb,
'Customer' => $Customer,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_MYPAGE_MYPAGE_INDEX_SEARCH);
$pagination = $paginator->paginate(
$qb,
$request->get('pageno', 1),
$this->eccubeConfig['eccube_search_pmax']
);
$qr_code = $this->qrCodeService->generateQrCode($Customer);
return [
'pagination' => $pagination,
'qr_code' => $qr_code,
];
}
/**
* @Route("/mypage/qr_code", name="mypage_qr_code", methods={"GET"})
*/
public function qrcode(Request $request){
$Customer = $this->getUser();
$qr_code = $this->qrCodeService->generateQrCode($Customer);
return $this->render('Mypage/qr_code.twig',[
'qr_code' => $qr_code,
]);
}
}