custom/plugins/UltraWartung/src/Subscriber/Frontend.php line 66

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Ultra\Wartung\Subscriber;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\System\SystemConfig\SystemConfigService;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Shopware\Storefront\Event\StorefrontRenderEvent;
  7. use Symfony\Component\HttpFoundation\RedirectResponse;
  8. use Symfony\Component\HttpKernel\KernelEvents;
  9. use Symfony\Component\HttpKernel\Event\RequestEvent;
  10. use Symfony\Component\Routing\RouterInterface;
  11. class Frontend implements EventSubscriberInterface {
  12.     /**
  13.      * @var RouterInterface
  14.      */
  15.     private $router;
  16.     
  17.     /**
  18.      * @var connection
  19.      */
  20.     private $connection;
  21.     
  22.     /**
  23.      * @var SystemConfigService
  24.      */
  25.     private $systemConfigService;
  26.     
  27.      
  28.     
  29.     
  30.     public function __construct(
  31.         RouterInterface $router,
  32.         Connection $connection,
  33.         SystemConfigService $systemConfigService
  34.     )    
  35.     {    
  36.         $this->router $router;
  37.         $this->connection $connection;
  38.         $this->systemConfigService $systemConfigService;
  39.         }        
  40.         
  41.     public static function getSubscribedEvents(): array    {        
  42.         return[     
  43.             KernelEvents::REQUEST => 'ultrawartung',
  44.             StorefrontRenderEvent::class => 'onStorefrontRender'        
  45.             ];
  46.     }    
  47.     
  48.     public function onStorefrontRender(StorefrontRenderEvent $event) {
  49.         
  50.         $shopId $event->getSalesChannelContext()->getSalesChannel()->getId();
  51.         if (!$this->systemConfigService->get('UltraWartung.config.activeKanal'$shopId)) {
  52.             return;
  53.         }
  54.         $event->getSalesChannelContext()->getSalesChannel()->assign(['UltraWartung' => $this->systemConfigService->get('UltraWartung.config'$event->getContext()->getSource()->getSalesChannelId())]);
  55.     }
  56.     
  57.     public function ultrawartung(RequestEvent $event): void
  58.     {
  59.         $verkaufskanal=$event->getRequest()->attributes->get("sw-sales-channel-id");
  60.         $configit=$this->systemConfigService->get('UltraWartung.config.activeKanal'$verkaufskanal);
  61.         if($configit) {
  62.         $request $event->getRequest();
  63.         $route $request->attributes->get('_route');
  64.         if (!empty($route) and strpos($route'frontend') !== false) {
  65.         $ipadress=$request->getClientIp();
  66.         $eingang=0;
  67.         
  68.         $result $this->connection->fetchAllAssociative('SELECT ipadress, verkaufskanal, eingang FROM ultrawartung') ;
  69.         if($result) {
  70.             foreach($result as $value) {
  71.             
  72.             if($value["eingang"]==and $value["ipadress"]==$ipadress and $value["verkaufskanal"]==$verkaufskanal) {
  73.                 $eingang=1;    
  74.             }
  75.             }
  76.             
  77.         }
  78.         if($eingang === and strpos($route'frontend.ultrawartung.ultrawartung') === false) {    
  79.         $event->setResponse(
  80.                 new RedirectResponse(
  81.                     $this->router->generate('frontend.ultrawartung.ultrawartung')
  82.                 )
  83.             );
  84.         } 
  85.         }
  86.         
  87.         
  88.         
  89.         }    
  90.         
  91.     }
  92.     
  93. }