custom/static-plugins/NdSRS/src/Subscriber/AccountPageSubscriber.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nd\Srs\Subscriber;
  3. use Nd\Srs\Service\PointsCommunicator;
  4. use Shopware\Core\Framework\Struct\ArrayStruct;
  5. use Shopware\Storefront\Page\Account\Overview\AccountOverviewPageLoadedEvent;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class AccountPageSubscriber implements EventSubscriberInterface
  8. {
  9.     private PointsCommunicator $pointsCommunicator;
  10.     public function __construct(PointsCommunicator $pointsCommunicator)
  11.     {
  12.         $this->pointsCommunicator $pointsCommunicator;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [
  17.             AccountOverviewPageLoadedEvent::class => ['onAccountOverviewPageLoadedEvent'1000]
  18.         ];
  19.     }
  20.     public function onAccountOverviewPageLoadedEvent($event)
  21.     {
  22.         $customer $event->getPage()->getCustomer();
  23.         if (!$customer) {
  24.             return;
  25.         }
  26.         $points $this->pointsCommunicator->retrievePoints($customer$event->getContext());
  27.         $page $event->getPage();
  28.         $page->addExtension('srs_points', new ArrayStruct(['points' => $points]));
  29.     }
  30. }