Files

80 lines
2.0 KiB
PHP

<?php
/**
* @package Plumrocket_CookieConsent
* @copyright Copyright (c) 2025 Plumrocket Inc. (https://plumrocket.com)
* @license https://plumrocket.com/license End-user License Agreement
*/
declare(strict_types=1);
namespace Plumrocket\CookieConsent\Model\Integration\AdobeCommerce;
use Magento\Framework\Module\Manager as ModuleManager;
use Plumrocket\Base\Api\ConfigUtilsInterface;
use Plumrocket\CookieConsent\Helper\Config;
/**
* @since 2.0.4
*/
class DataCollection
{
public const XML_PATH_CATEGORY_KEY = 'pr_cookie/integrations/adobe_commerce_data_collection/category';
/**
* @var \Plumrocket\CookieConsent\Helper\Config
*/
private $config;
/**
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
*/
private $configUtils;
/**
* @var \Magento\Framework\Module\Manager
*/
private $moduleManager;
/**
* @param \Plumrocket\CookieConsent\Helper\Config $config
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
* @param \Magento\Framework\Module\Manager $moduleManager
*/
public function __construct(
Config $config,
ConfigUtilsInterface $configUtils,
ModuleManager $moduleManager
) {
$this->config = $config;
$this->configUtils = $configUtils;
$this->moduleManager = $moduleManager;
}
/**
* @return bool
*/
public function isEnabled(): bool
{
if (! $this->config->isModuleEnabled() || ! $this->getAssociatedCategoryKey()) {
return false;
}
if (! $this->moduleManager->isEnabled('Magento_DataServices')) {
return false;
}
return true;
}
/**
* Get key of associated cookie category.
*
* @param int|string|null $store
* @return string
*/
public function getAssociatedCategoryKey($store = null): string
{
return (string) $this->configUtils->getStoreConfig(self::XML_PATH_CATEGORY_KEY, $store);
}
}