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

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