custom/plugins/EconsorAppStorefront/src/Storefront/registration/RegistrationAppPageLoader.php line 37

Open in your IDE?
  1. <?php
  2. namespace EconsorAppStorefront\Storefront\registration;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\Routing\RequestContextResolverInterface;
  6. use Shopware\Core\Framework\Struct\ArrayStruct;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Shopware\Storefront\Framework\Routing\Router;
  9. use Shopware\Storefront\Page\GenericPageLoaderInterface;
  10. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpFoundation\Request;
  13. class RegistrationAppPageLoader
  14. {
  15.     private GenericPageLoaderInterface $genericPageLoader;
  16.     private EventDispatcherInterface $eventDispatcher;
  17.     private EntityRepository $salutationRepository;
  18.     private Router $router;
  19.     public function __construct(GenericPageLoaderInterface $genericPageLoader,
  20.                                 EventDispatcherInterface $eventDispatcher,
  21.                                 EntityRepository $salutationRepository,
  22.                                 Router $router)
  23.     {
  24.         $this->genericPageLoader $genericPageLoader;
  25.         $this->eventDispatcher $eventDispatcher;
  26.         $this->salutationRepository $salutationRepository;
  27.         $this->router $router;
  28.     }
  29.     public function load(Request $requestSalesChannelContext $context): RegistrationAppPage|RedirectResponse
  30.     {
  31.         $page $this->genericPageLoader->load($request$context);
  32.         $page RegistrationAppPage::createFrom($page);
  33. /*
  34.         if(!$context->getCustomer()) {
  35.             $url = $this->router->generate('frontend.account.login');
  36.             return new RedirectResponse($url);
  37.         }
  38. */
  39.         $customLoggedIn = new ArrayStruct();
  40.         $customLoggedIn->set('login'$context->getCustomer() != null);
  41.         $page->addExtension('customerLoggedIn'$customLoggedIn);
  42.         $salutations $this->salutationRepository->search(new Criteria(), $context->getContext());
  43.         $page->addExtension('salutations'$salutations);
  44.         $this->eventDispatcher->dispatch(
  45.             new RegistrationAppPageLoadedEvent($page$context$request)
  46.         );
  47.         return $page;
  48.     }
  49. }