custom/plugins/AppflixStudygood/src/Storefront/Subscriber/SalesChannelContextSubscriber.php line 27

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Appflix\Studygood\Storefront\Subscriber;
  3. use Appflix\Studygood\Core\Service\VideoCourseService;
  4. use Shopware\Core\Framework\Routing\Event\SalesChannelContextResolvedEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. class SalesChannelContextSubscriber implements EventSubscriberInterface
  7. {
  8.     private VideoCourseService $videoCourseService;
  9.     public function __construct(
  10.         VideoCourseService $videoCourseService
  11.     )
  12.     {
  13.         $this->videoCourseService $videoCourseService;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             SalesChannelContextResolvedEvent::class => 'onSalesChannelContextResolved'
  19.         ];
  20.     }
  21.     public function onSalesChannelContextResolved(SalesChannelContextResolvedEvent $event): void
  22.     {
  23.         $customer $event->getSalesChannelContext()->getCustomer();
  24.         if (!$customer) {
  25.             return;
  26.         }
  27.         $this->videoCourseService->setContext($event->getSalesChannelContext()->getContext());
  28.         $esdSubscriptions $this->videoCourseService->getEsdSubscriptions($customer$event->getSalesChannelContext());
  29.         if (!$esdSubscriptions) {
  30.             return;
  31.         }
  32.         $customer->assign([
  33.             'esdSubscriptions' => $esdSubscriptions
  34.         ]);
  35.     }
  36. }