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

  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.      * @internal
  23.      */
  24.     public function __construct(private readonly GenericPageLoaderInterface $genericLoader, private readonly EventDispatcherInterface $eventDispatcher, private readonly AbstractCountryRoute $countryRoute, private readonly AbstractSalutationRoute $salutationRoute)
  25.     {
  26.     }
  27.     /**
  28.      * @throws CategoryNotFoundException
  29.      * @throws InconsistentCriteriaIdsException
  30.      * @throws MissingRequestParameterException
  31.      */
  32.     public function load(Request $requestSalesChannelContext $salesChannelContext): AccountLoginPage
  33.     {
  34.         $page $this->genericLoader->load($request$salesChannelContext);
  35.         $page AccountLoginPage::createFrom($page);
  36.         if ($page->getMetaInformation()) {
  37.             $page->getMetaInformation()->setRobots('noindex,follow');
  38.         }
  39.         $page->setCountries($this->getCountries($salesChannelContext));
  40.         $page->setSalutations($this->getSalutations($salesChannelContext));
  41.         $this->eventDispatcher->dispatch(
  42.             new AccountLoginPageLoadedEvent($page$salesChannelContext$request)
  43.         );
  44.         return $page;
  45.     }
  46.     /**
  47.      * @throws InconsistentCriteriaIdsException
  48.      */
  49.     private function getSalutations(SalesChannelContext $salesChannelContext): SalutationCollection
  50.     {
  51.         $salutations $this->salutationRoute->load(new Request(), $salesChannelContext, new Criteria())->getSalutations();
  52.         $salutations->sort(fn (SalutationEntity $aSalutationEntity $b) => $b->getSalutationKey() <=> $a->getSalutationKey());
  53.         return $salutations;
  54.     }
  55.     private function getCountries(SalesChannelContext $salesChannelContext): CountryCollection
  56.     {
  57.         $criteria = (new Criteria())
  58.             ->addFilter(new EqualsFilter('active'true))
  59.             ->addAssociation('states');
  60.         $countries $this->countryRoute->load(new Request(), $criteria$salesChannelContext)->getCountries();
  61.         $countries->sortCountryAndStates();
  62.         return $countries;
  63.     }
  64. }