|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Magefan\GoogleTagManager\Plugin\Magento\Framework\App\Config; |
| 4 | + |
| 5 | +use Magento\Framework\App\Config\ScopeConfigInterface; |
| 6 | +use Magefan\GoogleTagManager\Model\Config; |
| 7 | +class ScopeConfig |
| 8 | +{ |
| 9 | + /** |
| 10 | + * @var Config |
| 11 | + */ |
| 12 | + private $config; |
| 13 | + |
| 14 | + const PATHS = ['google/adwords/active', |
| 15 | + 'google/analytics/active', |
| 16 | + 'google/gtag/analytics4/active', |
| 17 | + 'google/gtag/adwords/active', |
| 18 | + 'googletagmanager/general/active', |
| 19 | + 'am_ga4/general/enable', |
| 20 | + 'weltpixel_ga4/general/enable', |
| 21 | + 'mst_gtm/general/enabled', |
| 22 | + 'googletagmanager/general/enabled' |
| 23 | + ]; |
| 24 | + |
| 25 | + /** |
| 26 | + * @param Config $config |
| 27 | + */ |
| 28 | + public function __construct( |
| 29 | + Config $config |
| 30 | + ) |
| 31 | + { |
| 32 | + $this->config = $config; |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * @param ScopeConfigInterface $subject |
| 37 | + * @param $result |
| 38 | + * @param $path |
| 39 | + * @param string $scopeType |
| 40 | + * @param $scopeCode |
| 41 | + * @return mixed|string |
| 42 | + */ |
| 43 | + public function afterGetValue( |
| 44 | + ScopeConfigInterface $subject, |
| 45 | + $result, |
| 46 | + $path, |
| 47 | + $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, |
| 48 | + $scopeCode = null |
| 49 | + ) |
| 50 | + { |
| 51 | + if (in_array($path, self::PATHS)) { |
| 52 | + if ($this->config->isEnabled() && !$this->config->isThirdPartyGaEnabled()) { |
| 53 | + $result = '0'; |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + return $result; |
| 58 | + } |
| 59 | +} |
0 commit comments