[ 'consent_type' => 'ad_Storage', 'status' => 'denied', 'cookie_category' => null, ], 'item2' => [ 'consent_type' => 'analytics_Storage', 'status' => 'denied', 'cookie_category' => null, ], ]; /** * @var \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory */ private $configDataCollectionFactory; /** * @var \Magento\Framework\App\Config\Storage\WriterInterface */ private $configWriter; /** * @var \Magento\Framework\Serialize\Serializer\Json */ private $jsonSerializer; /** * @param \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configDataCollectionFactory * @param \Magento\Framework\App\Config\Storage\WriterInterface $configWriter * @param \Magento\Framework\Serialize\Serializer\Json $jsonSerializer */ public function __construct( CollectionFactory $configDataCollectionFactory, WriterInterface $configWriter, Json $jsonSerializer ) { $this->configDataCollectionFactory = $configDataCollectionFactory; $this->configWriter = $configWriter; $this->jsonSerializer = $jsonSerializer; } /** * @inheritDoc */ public function apply() { $legacyCategoryConfigs = $this->configDataCollectionFactory->create(); $legacyCategoryConfigs->addFieldToFilter('path', 'pr_cookie/integrations/microsoft_clarity/category'); /** @var \Magento\Framework\App\Config\Value $legacyCategoryConfig */ foreach ($legacyCategoryConfigs as $legacyCategoryConfig) { $categoryKey = (string) $legacyCategoryConfig->getValue(); if (! $categoryKey) { continue; } $configDataItemValue = self::V2_CONSENT_TYPES; foreach ($configDataItemValue as $key => $consentType) { $configDataItemValue[$key]['cookie_category'] = $categoryKey; } $this->configWriter->save( MicrosoftClarityConfig::XML_PATH_CONSENT_TYPES, $this->jsonSerializer->serialize($configDataItemValue), $legacyCategoryConfig->getScope(), (int) $legacyCategoryConfig->getScopeId() ); } } /** * @inheritDoc */ public static function getDependencies() { return []; } /** * @inheritDoc */ public function getAliases() { return []; } }