vendor/shopware/storefront/Page/GenericPageLoader.php line 92

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Storefront\Page;
  3. use Shopware\Core\Checkout\Payment\SalesChannel\AbstractPaymentMethodRoute;
  4. use Shopware\Core\Checkout\Shipping\SalesChannel\AbstractShippingMethodRoute;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\Log\Package;
  7. use Shopware\Core\Profiling\Profiler;
  8. use Shopware\Core\SalesChannelRequest;
  9. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  10. use Shopware\Core\System\SystemConfig\SystemConfigService;
  11. use Shopware\Storefront\Event\RouteRequest\PaymentMethodRouteRequestEvent;
  12. use Shopware\Storefront\Event\RouteRequest\ShippingMethodRouteRequestEvent;
  13. use Shopware\Storefront\Pagelet\Footer\FooterPageletLoaderInterface;
  14. use Shopware\Storefront\Pagelet\Header\HeaderPageletLoaderInterface;
  15. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  16. use Symfony\Component\HttpFoundation\Request;
  17. #[Package('storefront')]
  18. class GenericPageLoader implements GenericPageLoaderInterface
  19. {
  20.     /**
  21.      * @internal
  22.      */
  23.     public function __construct(
  24.         private readonly HeaderPageletLoaderInterface $headerLoader,
  25.         private readonly FooterPageletLoaderInterface $footerLoader,
  26.         private readonly SystemConfigService $systemConfigService,
  27.         private readonly AbstractPaymentMethodRoute $paymentMethodRoute,
  28.         private readonly AbstractShippingMethodRoute $shippingMethodRoute,
  29.         private readonly EventDispatcherInterface $eventDispatcher
  30.     ) {
  31.     }
  32.     public function load(Request $requestSalesChannelContext $context): Page
  33.     {
  34.         return Profiler::trace('generic-page-loader', function () use ($request$context) {
  35.             $page = new Page();
  36.             if ($request->isXmlHttpRequest()) {
  37.                 $this->eventDispatcher->dispatch(
  38.                     new GenericPageLoadedEvent($page$context$request)
  39.                 );
  40.                 return $page;
  41.             }
  42.             $page->setHeader(
  43.                 $this->headerLoader->load($request$context)
  44.             );
  45.             $page->setFooter(
  46.                 $this->footerLoader->load($request$context)
  47.             );
  48.             $criteria = new Criteria();
  49.             $criteria->setTitle('generic-page::shipping-methods');
  50.             $event = new ShippingMethodRouteRequestEvent($request, new Request(), $context$criteria);
  51.             $this->eventDispatcher->dispatch($event);
  52.             $shippingMethods $this->shippingMethodRoute
  53.                 ->load($event->getStoreApiRequest(), $context$event->getCriteria())
  54.                 ->getShippingMethods();
  55.             $page->setSalesChannelShippingMethods($shippingMethods);
  56.             $criteria = new Criteria();
  57.             $criteria->setTitle('generic-page::payment-methods');
  58.             $event = new PaymentMethodRouteRequestEvent($request, new Request(), $context$criteria);
  59.             $this->eventDispatcher->dispatch($event);
  60.             $paymentMethods $this->paymentMethodRoute
  61.                 ->load($event->getStoreApiRequest(), $context$event->getCriteria())
  62.                 ->getPaymentMethods();
  63.             $page->setSalesChannelPaymentMethods($paymentMethods);
  64.             $page->setMetaInformation((new MetaInformation())->assign([
  65.                 'revisit' => '15 days',
  66.                 'robots' => 'index,follow',
  67.                 'xmlLang' => $request->attributes->get(SalesChannelRequest::ATTRIBUTE_DOMAIN_LOCALE) ?? '',
  68.                 'metaTitle' => $this->systemConfigService->getString('core.basicInformation.shopName'$context->getSalesChannel()->getId()),
  69.             ]));
  70.             $this->eventDispatcher->dispatch(
  71.                 new GenericPageLoadedEvent($page$context$request)
  72.             );
  73.             return $page;
  74.         });
  75.     }
  76. }