vendor/store.shopware.com/spnosalutationorder/src/Subscriber/SalutationPageSubscriber.php line 36

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Spno\SalutationOrder\Subscriber;
  3. use Shopware\Core\System\Salutation\SalutationCollection;
  4. use Shopware\Storefront\Page\Account\Login\AccountLoginPageLoadedEvent;
  5. use Shopware\Storefront\Page\Account\Profile\AccountProfilePageLoadedEvent;
  6. use Shopware\Storefront\Page\Address\Detail\AddressDetailPageLoadedEvent;
  7. use Shopware\Storefront\Page\Address\Listing\AddressListingPageLoadedEvent;
  8. use Shopware\Storefront\Page\Checkout\Register\CheckoutRegisterPageLoadedEvent;
  9. use Shopware\Storefront\Page\PageLoadedEvent;
  10. use Spno\SalutationOrder\Service\SalutationOrderService;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. class SalutationPageSubscriber implements EventSubscriberInterface
  13. {
  14.     private SalutationOrderService $salutationOrderService;
  15.     public function __construct(
  16.         SalutationOrderService $salutationOrderService
  17.     ) {
  18.         $this->salutationOrderService $salutationOrderService;
  19.     }
  20.     public static function getSubscribedEvents()
  21.     {
  22.         return [
  23.             CheckoutRegisterPageLoadedEvent::class => 'onPageLoaded',
  24.             AccountLoginPageLoadedEvent::class => 'onPageLoaded',
  25.             AddressDetailPageLoadedEvent::class => 'onPageLoaded',
  26.             AddressListingPageLoadedEvent::class => 'onPageLoaded',
  27.             AccountProfilePageLoadedEvent::class => 'onPageLoaded',
  28.         ];
  29.     }
  30.     public function onPageLoaded(PageLoadedEvent $page): void
  31.     {
  32.         /** @var SalutationCollection $salutations */
  33.         $salutations $page->getPage()->getSalutations();
  34.         $salutations $this->salutationOrderService->sort($salutations);
  35.         $page->getPage()->setSalutations($salutations);
  36.     }
  37. }