custom/plugins/OkeonlineKejeDeliveryAddress/src/Storefront/Subscriber/CheckoutConfirmPageRequestSubscriber.php line 32

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Okeonline\KejeDeliveryAddress\Storefront\Subscriber;
  3. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\System\SalesChannel\SalesChannelEntity;
  6. use Shopware\Storefront\Page\Checkout\Confirm\CheckoutConfirmPageLoadedEvent;
  7. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  8. class CheckoutConfirmPageRequestSubscriber implements EventSubscriberInterface
  9. {
  10.     /** @var EntityRepository $salesChannelRepository */
  11.     private $salesChannelRepository;
  12.     
  13.     public function __construct(
  14.         EntityRepository $salesChannelRepository
  15.     )
  16.     {
  17.         $this->salesChannelRepository $salesChannelRepository;
  18.     }
  19.     
  20.     public static function getSubscribedEvents(): array
  21.     {
  22.         return [
  23.             CheckoutConfirmPageLoadedEvent::class => 'addCountriesToPage'
  24.         ];
  25.     }
  26.     
  27.     // adds countries to the confirm page, for maunal adress input
  28.     public function addCountriesToPage(CheckoutConfirmPageLoadedEvent $event)
  29.     {
  30.         $page $event->getPage();
  31.         
  32.         $currentSalesChannelId $event->getSalesChannelContext()->getSalesChannel()->getId();
  33.         
  34.         $criteria = new Criteria([$currentSalesChannelId]);
  35.         $criteria->addAssociation('countries');
  36.     
  37.         $result $this->salesChannelRepository->search($criteria$event->getContext());
  38.         
  39.         if($result->count() !== 1)
  40.             return;
  41.             
  42.         /** @var SalesChannelEntity */
  43.         $salesChannel $result->first();
  44.         
  45.         $countries $salesChannel->getCountries();
  46.         
  47.         $page->addExtension('countries'$countries);
  48.         
  49.     }
  50. }