custom/plugins/SmartsuppChat/src/Subscriber/StorefrontSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace Smartsupp\SmartsuppChat\Subscriber;
  3. use Smartsupp\SmartsuppChat\Struct\ConfigStruct;
  4. use Shopware\Core\Content\Cms\Events\CmsPageLoadedEvent;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Shopware\Storefront\Page\GenericPageLoadedEvent;
  7. use Shopware\Storefront\Page\PageLoadedEvent;
  8. use Shopware\Storefront\Pagelet\Header\HeaderPageletLoadedEvent;
  9. use Symfony\Contracts\EventDispatcher\Event;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. class StorefrontSubscriber implements EventSubscriberInterface
  12. {
  13.     private $systemConfigService;
  14.     public function __construct(SystemConfigService $systemConfigService){
  15.         $this->systemConfigService $systemConfigService;
  16.     }
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             GenericPageLoadedEvent::class => 'onPageLoaded',
  21.         ];
  22.     }
  23.     public function onPageLoaded(GenericPageLoadedEvent $loadedEvent){
  24.         $page $loadedEvent->getPage();
  25.         $config $this->systemConfigService->get('SmartsuppChat.config');
  26.         $chatKey $this->systemConfigService->get('SmartsuppChat.config.smartSuppChatKey');
  27.         $chatColor $this->systemConfigService->get('SmartsuppChat.config.smartSuppColor');
  28.         $chatConfig $this->systemConfigService->get('SmartsuppChat.config.smartSuppConfig');
  29.         $chatApi $this->systemConfigService->get('SmartsuppChat.config.smartSuppAPI');
  30.         if (!$config) {
  31.             return;
  32.         }
  33.         
  34.         if ($chatKey) {
  35.             $smartsuppConfiguration = new ConfigStruct();
  36.             $smartsuppConfiguration->setKey($chatKey);
  37.             $page->addExtension('smartsuppConfiguration'$smartsuppConfiguration);
  38.         }
  39.         
  40.         $smartsuppCookies = new ConfigStruct();
  41.         $smartsuppCookies->setKey($config['hasSWConsentSupport']);
  42.         $page->addExtension('smartsuppCookies'$smartsuppCookies);
  43.         if ($chatColor) {
  44.             $smartsuppColor = new ConfigStruct();
  45.             $smartsuppColor->setKey($chatColor);
  46.             $page->addExtension('smartsuppColor'$smartsuppColor);
  47.         }
  48.         if ($chatConfig) {
  49.             $smartsuppConfig = new ConfigStruct();
  50.             $smartsuppConfig->setKey($chatConfig);
  51.             $page->addExtension('smartsuppConfig'$smartsuppConfig);
  52.         }
  53.         if ($chatApi) {
  54.             $smartsuppApi = new ConfigStruct();
  55.             $smartsuppApi->setKey($chatApi);
  56.             $page->addExtension('smartsuppApi'$smartsuppApi);
  57.         }
  58.     }
  59. }