Files

98 lines
2.4 KiB
PHP

<?php
/**
* @package Plumrocket_CookieConsentPro
* @copyright Copyright (c) 2025 Plumrocket Inc.
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsentPro\Model\Integration;
use Magento\Framework\Serialize\SerializerInterface;
use Plumrocket\Base\Api\ConfigUtilsInterface;
use Plumrocket\CookieConsent\Helper\Config;
/**
* @since 1.0.0
*/
class MicrosoftAds
{
public const XML_PATH_ENABLED = 'pr_cookie/integrations/microsoft_ads/enabled';
public const XML_PATH_CONSENT_TYPES = 'pr_cookie/integrations/microsoft_ads/consent_types';
/**
* @var \Plumrocket\CookieConsent\Helper\Config
*/
private $config;
/**
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
*/
private $configUtils;
/**
* @var \Magento\Framework\Serialize\SerializerInterface
*/
private $serializer;
/**
* @param \Plumrocket\CookieConsent\Helper\Config $config
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
* @param \Magento\Framework\Serialize\SerializerInterface $serializer
*/
public function __construct(
Config $config,
ConfigUtilsInterface $configUtils,
SerializerInterface $serializer
) {
$this->config = $config;
$this->configUtils = $configUtils;
$this->serializer = $serializer;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
if (! $this->config->isModuleEnabled()) {
return false;
}
if (! $this->configUtils->isSetFlag(self::XML_PATH_ENABLED)) {
return false;
}
if (! $this->getConsentTypesConfig()) {
return false;
}
return true;
}
/**
* @param $store
* @return array[]
*/
public function getConsentTypesConfig($store = null): array
{
$config = $this->configUtils->getStoreConfig(self::XML_PATH_CONSENT_TYPES, $store);
if (is_string($config)) {
$config = $this->serializer->unserialize($config);
}
$result = [];
foreach ($config as $item) {
$consentType = $item['consent_type'];
$result[$consentType] = [
'cookie_category' => $item['cookie_category'],
'default_status' => $item['status'],
];
}
return $result;
}
}