custom/plugins/ThemeOkeonline/src/Storefront/Page/Checkout/CheckoutRegisterPageLoadedEventSubscriber.php line 45

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace ThemeOkeOnline\Storefront\Page\Checkout;
  3. use Shopware\Core\Checkout\Cart\LineItem\LineItemCollection;
  4. use Shopware\Core\Checkout\Shipping\SalesChannel\AbstractShippingMethodRoute;
  5. use Shopware\Core\Content\Product\ProductCollection;
  6. use Shopware\Core\Content\Product\SalesChannel\CrossSelling\AbstractProductCrossSellingRoute;
  7. use Shopware\Core\Content\Product\SalesChannel\CrossSelling\ProductCrossSellingRouteResponse;
  8. use Shopware\Core\Framework\Context;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  12. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  13. use Shopware\Core\System\SystemConfig\SystemConfigService;
  14. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Symfony\Component\HttpFoundation\Request;
  17. class CheckoutRegisterPageLoadedEventSubscriber implements EventSubscriberInterface
  18. {
  19.     private SalesChannelContext $salesChannelContext;
  20.     private Context $context;
  21.     private AbstractShippingMethodRoute $shippingMethodRoute;
  22.     private EntityRepositoryInterface $shippingMethodRepository;
  23.     public function __construct(
  24.         AbstractShippingMethodRoute $shippingMethodRoute,
  25.         EntityRepositoryInterface $shippingMethodRepository,
  26.         SystemConfigService $systemConfigService
  27.     )
  28.     {
  29.         $this->shippingMethodRoute $shippingMethodRoute;
  30.         $this->shippingMethodRepository $shippingMethodRepository;
  31.         $this->systemConfigService $systemConfigService;
  32.     }
  33.     public static function getSubscribedEvents(): array
  34.     {
  35.         return [
  36.             CheckoutRegisterPageLoadedEvent::class => ['addShippingMethodsToPage']
  37.         ];
  38.     }
  39.     public function addShippingMethodsToPage(CheckoutRegisterPageLoadedEvent $event)
  40.     {
  41.         $request = new Request();
  42.         $request->query->set('onlyAvailable''1');
  43.         
  44.         $salesChannelContext $event->getSalesChannelContext();
  45.         $context $salesChannelContext->getContext();
  46.         $page $event->getPage();
  47.         $salesChannelId $salesChannelContext->getSalesChannel()->id;
  48.         $criteria = new Criteria();
  49.         $criteria->addAssociation('salesChannels');
  50.         $criteria->addAssociation('prices');
  51.         $criteria->addFilter(
  52.             new EqualsFilter('active'true),
  53.             new EqualsFilter('salesChannels.id'$salesChannelId)
  54.         );
  55.         $shippingMethods $this->shippingMethodRoute->load($request$salesChannelContext, new Criteria())->getShippingMethods();
  56.         $page->addExtension(
  57.             'shippingMethods',
  58.             $shippingMethods
  59.         );
  60.     }
  61. }