vendor/shopware/storefront/Page/Account/Login/AccountLoginPageLoader.php line 62

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Page\Account\Login;
  3. use Shopware\Core\Content\Category\Exception\CategoryNotFoundException;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
  8. use Shopware\Core\System\Country\CountryCollection;
  9. use Shopware\Core\System\Country\SalesChannel\AbstractCountryRoute;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. use Shopware\Core\System\Salutation\SalesChannel\AbstractSalutationRoute;
  12. use Shopware\Core\System\Salutation\SalutationCollection;
  13. use Shopware\Core\System\Salutation\SalutationEntity;
  14. use Shopware\Storefront\Page\GenericPageLoaderInterface;
  15. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  16. use Symfony\Component\HttpFoundation\Request;
  17. class AccountLoginPageLoader
  18. {
  19.     /**
  20.      * @var GenericPageLoaderInterface
  21.      */
  22.     private $genericLoader;
  23.     /**
  24.      * @var EventDispatcherInterface
  25.      */
  26.     private $eventDispatcher;
  27.     /**
  28.      * @var AbstractCountryRoute
  29.      */
  30.     private $countryRoute;
  31.     /**
  32.      * @var AbstractSalutationRoute
  33.      */
  34.     private $salutationRoute;
  35.     /**
  36.      * @internal
  37.      */
  38.     public function __construct(
  39.         GenericPageLoaderInterface $genericLoader,
  40.         EventDispatcherInterface $eventDispatcher,
  41.         AbstractCountryRoute $countryRoute,
  42.         AbstractSalutationRoute $salutationRoute
  43.     ) {
  44.         $this->genericLoader $genericLoader;
  45.         $this->eventDispatcher $eventDispatcher;
  46.         $this->countryRoute $countryRoute;
  47.         $this->salutationRoute $salutationRoute;
  48.     }
  49.     /**
  50.      * @throws CategoryNotFoundException
  51.      * @throws InconsistentCriteriaIdsException
  52.      * @throws MissingRequestParameterException
  53.      */
  54.     public function load(Request $requestSalesChannelContext $salesChannelContext): AccountLoginPage
  55.     {
  56.         $page $this->genericLoader->load($request$salesChannelContext);
  57.         $page AccountLoginPage::createFrom($page);
  58.         if ($page->getMetaInformation()) {
  59.             $page->getMetaInformation()->setRobots('noindex,follow');
  60.         }
  61.         $page->setCountries($this->getCountries($salesChannelContext));
  62.         $page->setSalutations($this->getSalutations($salesChannelContext));
  63.         $this->eventDispatcher->dispatch(
  64.             new AccountLoginPageLoadedEvent($page$salesChannelContext$request)
  65.         );
  66.         return $page;
  67.     }
  68.     /**
  69.      * @throws InconsistentCriteriaIdsException
  70.      */
  71.     private function getSalutations(SalesChannelContext $salesChannelContext): SalutationCollection
  72.     {
  73.         $salutations $this->salutationRoute->load(new Request(), $salesChannelContext, new Criteria())->getSalutations();
  74.         $salutations->sort(function (SalutationEntity $aSalutationEntity $b) {
  75.             return $b->getSalutationKey() <=> $a->getSalutationKey();
  76.         });
  77.         return $salutations;
  78.     }
  79.     private function getCountries(SalesChannelContext $salesChannelContext): CountryCollection
  80.     {
  81.         $criteria = (new Criteria())
  82.             ->addFilter(new EqualsFilter('active'true))
  83.             ->addAssociation('states');
  84.         $countries $this->countryRoute->load(new Request(), $criteria$salesChannelContext)->getCountries();
  85.         $countries->sortCountryAndStates();
  86.         return $countries;
  87.     }
  88. }