custom/plugins/WbmTagManagerEcomm/src/Services/DataLayerModules.php line 33

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Wbm\TagManagerEcomm\Services;
  3. use Doctrine\DBAL\Connection;
  4. use Shopware\Core\System\SystemConfig\SystemConfigService;
  5. class DataLayerModules implements DataLayerModulesInterface
  6. {
  7.     /**
  8.      * @var Connection
  9.      */
  10.     private $connection;
  11.     /**
  12.      * @var SystemConfigService
  13.      */
  14.     private $systemConfigService;
  15.     /**
  16.      * @var array
  17.      */
  18.     private $modules;
  19.     public function __construct(
  20.         Connection $connection,
  21.         SystemConfigService $systemConfigService
  22.     ) {
  23.         $this->connection $connection;
  24.         $this->systemConfigService $systemConfigService;
  25.     }
  26.     public function getModules(): array
  27.     {
  28.         if (!empty($this->modules)) {
  29.             return $this->modules;
  30.         }
  31.         $qb $this->connection->createQueryBuilder();
  32.         $qb->from('wbm_data_layer_modules''module')
  33.             ->select(
  34.                 [
  35.                     'module.module',
  36.                     'module.response',
  37.                 ]
  38.             );
  39.         $this->modules $qb->execute()->fetchAll(\PDO::FETCH_KEY_PAIR);
  40.         return $this->modules;
  41.     }
  42.     public function getResponseRoutes(): array
  43.     {
  44.         $modules = [];
  45.         foreach ($this->getModules() as $key => $module) {
  46.             if (!empty($module)) {
  47.                 $modules array_merge($modulesexplode(','$module));
  48.             }
  49.         }
  50.         return $modules;
  51.     }
  52.     public function getContainerId(?string $salesChannelId null): ?string
  53.     {
  54.         return $this->systemConfigService->get(
  55.             'WbmTagManagerEcomm.config.containerId',
  56.             $salesChannelId
  57.         );
  58.     }
  59.     public function isActive(?string $salesChannelId null): ?bool
  60.     {
  61.         return !$this->systemConfigService->get(
  62.             'WbmTagManagerEcomm.config.isInactive',
  63.             $salesChannelId
  64.         );
  65.     }
  66.     public function isTrackingProductClicks(?string $salesChannelId null): ?bool
  67.     {
  68.         return $this->systemConfigService->get(
  69.             'WbmTagManagerEcomm.config.isTrackingProductClicks',
  70.             $salesChannelId
  71.         );
  72.     }
  73.     public function hasSWConsentSupport(?string $salesChannelId null): int
  74.     {
  75.         return $this->systemConfigService->get(
  76.             'WbmTagManagerEcomm.config.hasSWConsentSupport',
  77.             $salesChannelId
  78.         ) ? 0;
  79.     }
  80.     public function getScriptTagAttributes(?string $salesChannelId null): string
  81.     {
  82.         return $this->systemConfigService->get(
  83.             'WbmTagManagerEcomm.config.scriptTagAttributes',
  84.             $salesChannelId
  85.         ) ?: '';
  86.     }
  87.     public function getDataLayerScriptTagAttributes(?string $salesChannelId null): string
  88.     {
  89.         $removeAtDataLayerTag $this->systemConfigService->get(
  90.             'WbmTagManagerEcomm.config.removeAtDataLayerTag',
  91.             $salesChannelId
  92.         );
  93.         return ($removeAtDataLayerTag !== true)
  94.             ? $this->getScriptTagAttributes($salesChannelId)
  95.             : '';
  96.     }
  97.     public function getExtendedURLParameter(?string $salesChannelId null): string
  98.     {
  99.         return $this->systemConfigService->get(
  100.             'WbmTagManagerEcomm.config.extendedURLParameter',
  101.             $salesChannelId
  102.         ) ?: '';
  103.     }
  104. }