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

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\Storefront\Page\Account\VoucherListingPageLoader;
  10. use NetInventors\NetiNextEasyCoupon\Struct\PluginConfigStruct;
  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.     private PluginConfigStruct       $pluginConfig;
  24.     private VoucherListingPageLoader $pageLoader;
  25.     public function __construct(
  26.         PluginConfigStruct       $pluginConfig,
  27.         VoucherListingPageLoader $pageLoader
  28.     ) {
  29.         $this->pluginConfig $pluginConfig;
  30.         $this->pageLoader   $pageLoader;
  31.     }
  32.     /**
  33.      * @Route("/EasyCoupon/list", name="frontend.easy_coupon.list", methods={"GET"}, defaults={"XmlHttpRequest"=false})
  34.      *
  35.      * @param Request             $request
  36.      * @param SalesChannelContext $context
  37.      *
  38.      * @return Response
  39.      */
  40.     public function listAction(Request $requestSalesChannelContext $context): Response
  41.     {
  42.         $customer $context->getCustomer();
  43.         if (null === $customer) {
  44.             $message $this->trans('neti-easy-coupon.store-front.warning.login-needed');
  45.             $this->addFlash('warning'$message);
  46.             return $this->redirectToRoute('frontend.account.login.page');
  47.         }
  48.         if (!$this->pluginConfig->isActive() || !$this->pluginConfig->isDisplayInAccount()) {
  49.             $message $this->trans('neti-easy-coupon.store-front.warning.deactivated');
  50.             $this->addFlash('warning'$message);
  51.             return $this->redirectToRoute('frontend.account.home.page');
  52.         }
  53.         $page $this->pageLoader->load($request$context);
  54.         $page->setMetaInformation((new MetaInformation())->assign([
  55.             'robots' => 'noindex,nofollow',
  56.         ]));
  57.         $page->getMetaInformation()->setMetaTitle(
  58.             $this->trans('neti-easy-coupon.store-front.account.meta.title')
  59.         );
  60.         return $this->renderStorefront(
  61.             '@NetiNextEasyCoupon/storefront/easy_coupon/account/list_voucher.html.twig',
  62.             [
  63.                 'page' => $page,
  64.             ]
  65.         );
  66.     }
  67. }