custom/plugins/UandiEfbContactInfo/src/Subscriber/CheckoutFinishSubscriber.php line 32

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Uandi\UandiEfbContactInfo\Subscriber;
  3. use Shopware\Storefront\Page\Checkout\Finish\CheckoutFinishPageLoadedEvent;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Uandi\UandiEfbContactInfo\Service\ContactsService;
  6. class CheckoutFinishSubscriber implements EventSubscriberInterface
  7. {
  8.     private ContactsService $contactsService;
  9.     public function __construct(ContactsService $contactsService)
  10.     {
  11.         $this->contactsService $contactsService;
  12.     }
  13.     public static function getSubscribedEvents(): array
  14.     {
  15.         return [
  16.             CheckoutFinishPageLoadedEvent::class => 'addContactData'
  17.         ];
  18.     }
  19.     /**
  20.      * Add contact data to the checkout finish page.
  21.      *
  22.      * @param CheckoutFinishPageLoadedEvent $event
  23.      *
  24.      * @return void
  25.      */
  26.     public function addContactData(CheckoutFinishPageLoadedEvent $event): void
  27.     {
  28.         $order $event->getPage()->getOrder();
  29.         $zipCode $order->getBillingAddress()->getZipcode();
  30.         $contactData $this->contactsService->getContactsByPostCode($event->getContext(), $zipCode'dtn');
  31.         $struct = new ContactDataStruct();
  32.         $struct->setContactData($contactData);
  33.         $event->getPage()->addExtension('contact_data'$struct);
  34.     }
  35. }