custom/plugins/NetiNextEasyCoupon/src/Storefront/Controller/AccountVoucherListingController.php line 54

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright  Copyright (c) 2020, Net Inventors GmbH
  4.  * @category   Shopware
  5.  * @author     drebrov
  6.  */
  7. declare(strict_types=1);
  8. namespace NetInventors\NetiNextEasyCoupon\Storefront\Controller;
  9. use NetInventors\NetiNextEasyCoupon\Service\PluginConfig;
  10. use NetInventors\NetiNextEasyCoupon\Storefront\Page\Account\VoucherListingPageLoader;
  11. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  12. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  13. use Shopware\Storefront\Controller\StorefrontController;
  14. use Shopware\Storefront\Page\MetaInformation;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. /**
  19.  * @RouteScope(scopes={"storefront"})
  20.  */
  21. class AccountVoucherListingController extends StorefrontController
  22. {
  23.     /**
  24.      * @var PluginConfig
  25.      */
  26.     private $pluginConfig;
  27.     /**
  28.      * @var VoucherListingPageLoader
  29.      */
  30.     private $pageLoader;
  31.     public function __construct(
  32.         PluginConfig $pluginConfig,
  33.         VoucherListingPageLoader $pageLoader
  34.     ) {
  35.         $this->pluginConfig $pluginConfig;
  36.         $this->pageLoader   $pageLoader;
  37.     }
  38.     /**
  39.      * @Route("/EasyCoupon/list", name="frontend.easy_coupon.list", methods={"GET"}, defaults={"XmlHttpRequest"=false})
  40.      *
  41.      * @param Request             $request
  42.      * @param SalesChannelContext $context
  43.      *
  44.      * @return Response
  45.      */
  46.     public function listAction(Request $requestSalesChannelContext $context): Response
  47.     {
  48.         $customer $context->getCustomer();
  49.         if (null === $customer) {
  50.             $message $this->trans('neti-easy-coupon.store-front.warning.login-needed');
  51.             $this->addFlash('warning'$message);
  52.             return $this->redirectToRoute('frontend.account.login.page');
  53.         }
  54.         if (!$this->pluginConfig->isActive() || !$this->pluginConfig->isDisplayInAccount()) {
  55.             $message $this->trans('neti-easy-coupon.store-front.warning.deactivated');
  56.             $this->addFlash('warning'$message);
  57.             return $this->redirectToRoute('frontend.account.home.page');
  58.         }
  59.         $page $this->pageLoader->load($request$context);
  60.         $page->setMetaInformation((new MetaInformation())->assign([
  61.             'robots' => 'noindex,nofollow',
  62.         ]));
  63.         $page->getMetaInformation()->setMetaTitle(
  64.             $this->trans('neti-easy-coupon.store-front.account.meta.title')
  65.         );
  66.         return $this->renderStorefront(
  67.             '@NetiNextEasyCoupon/storefront/easy_coupon/account/list_voucher.html.twig',
  68.             [
  69.                 'page' => $page,
  70.             ]
  71.         );
  72.     }
  73. }