Add only required cookies option

This commit is contained in:
Max W. 2025-04-07 23:58:40 +02:00
parent 5172966eb2
commit 2cab569707
4 changed files with 71 additions and 33 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.idea/

View File

@ -49,11 +49,11 @@ class GdprCookieConsent extends Module
Configuration::updateValue('GDPR_COOKIE_SETTINGS', 'Cookie Settings') &&
Configuration::updateValue('GDPR_COOKIE_MORE_INFO', 'More Information') &&
Configuration::updateValue('GDPR_COOKIE_MORE_INFO_URL', 'content/2-privacy-policy') &&
// New configuration values
Configuration::updateValue('GDPR_COOKIE_DATA_CONTROLLER', 'Your Company Name') &&
Configuration::updateValue('GDPR_COOKIE_RETENTION_PERIOD', '365 days') &&
Configuration::updateValue('GDPR_COOKIE_THIRD_PARTIES', 'Google Analytics, Facebook, etc.') &&
Configuration::updateValue('GDPR_COOKIE_MANAGE_TEXT', 'Manage Cookie Preferences');
Configuration::updateValue('GDPR_COOKIE_MANAGE_TEXT', 'Manage Cookie Preferences') &&
Configuration::updateValue('GDPR_COOKIE_ONLY_REQUIRED', 1);
}
@ -70,11 +70,11 @@ class GdprCookieConsent extends Module
Configuration::deleteByName('GDPR_COOKIE_SETTINGS') &&
Configuration::deleteByName('GDPR_COOKIE_MORE_INFO') &&
Configuration::deleteByName('GDPR_COOKIE_MORE_INFO_URL') &&
// New configuration values
Configuration::deleteByName('GDPR_COOKIE_DATA_CONTROLLER') &&
Configuration::deleteByName('GDPR_COOKIE_RETENTION_PERIOD') &&
Configuration::deleteByName('GDPR_COOKIE_THIRD_PARTIES') &&
Configuration::deleteByName('GDPR_COOKIE_MANAGE_TEXT');
Configuration::deleteByName('GDPR_COOKIE_MANAGE_TEXT') &&
Configuration::deleteByName('GDPR_COOKIE_ONLY_REQUIRED');
}
/**
@ -94,6 +94,11 @@ class GdprCookieConsent extends Module
$settings = Tools::getValue('GDPR_COOKIE_SETTINGS');
$moreInfo = Tools::getValue('GDPR_COOKIE_MORE_INFO');
$moreInfoUrl = Tools::getValue('GDPR_COOKIE_MORE_INFO_URL');
$dataController = Tools::getValue('GDPR_COOKIE_DATA_CONTROLLER');
$retentionPeriod = Tools::getValue('GDPR_COOKIE_RETENTION_PERIOD');
$thirdParties = Tools::getValue('GDPR_COOKIE_THIRD_PARTIES');
$manageText = Tools::getValue('GDPR_COOKIE_MANAGE_TEXT');
$onlyRequired = Tools::getValue('GDPR_COOKIE_ONLY_REQUIRED');
// Update configuration values
Configuration::updateValue('GDPR_COOKIE_ENABLED', $enabled);
@ -103,6 +108,11 @@ class GdprCookieConsent extends Module
Configuration::updateValue('GDPR_COOKIE_SETTINGS', $settings);
Configuration::updateValue('GDPR_COOKIE_MORE_INFO', $moreInfo);
Configuration::updateValue('GDPR_COOKIE_MORE_INFO_URL', $moreInfoUrl);
Configuration::updateValue('GDPR_COOKIE_DATA_CONTROLLER', $dataController);
Configuration::updateValue('GDPR_COOKIE_RETENTION_PERIOD', $retentionPeriod);
Configuration::updateValue('GDPR_COOKIE_THIRD_PARTIES', $thirdParties);
Configuration::updateValue('GDPR_COOKIE_MANAGE_TEXT', $manageText);
Configuration::updateValue('GDPR_COOKIE_ONLY_REQUIRED', $onlyRequired);
// Display confirmation
$output .= $this->displayConfirmation($this->l('Settings updated'));
@ -208,6 +218,26 @@ class GdprCookieConsent extends Module
'name' => 'GDPR_COOKIE_MORE_INFO_URL',
'required' => true,
],
[
'type' => 'switch',
'label' => $this->l('This cookie types are used'),
'name' => 'GDPR_COOKIE_ONLY_REQUIRED',
'desc' => $this->l('If this option is enabled, no config modal will be rendered and there will only be a single button to hide the cookie notice. (Only enable this, if you don\'t track any user data)'),
'is_bool' => true,
'required' => true,
'values' => [
[
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Nessessary only')
],
[
'id' => 'active_off',
'value' => 0,
'label' => $this->l('All cookies')
]
],
],
],
'submit' => [
'title' => $this->l('Save'),
@ -242,11 +272,11 @@ class GdprCookieConsent extends Module
$helper->fields_value['GDPR_COOKIE_SETTINGS'] = Configuration::get('GDPR_COOKIE_SETTINGS');
$helper->fields_value['GDPR_COOKIE_MORE_INFO'] = Configuration::get('GDPR_COOKIE_MORE_INFO');
$helper->fields_value['GDPR_COOKIE_MORE_INFO_URL'] = Configuration::get('GDPR_COOKIE_MORE_INFO_URL');
// New fields
$helper->fields_value['GDPR_COOKIE_DATA_CONTROLLER'] = Configuration::get('GDPR_COOKIE_DATA_CONTROLLER');
$helper->fields_value['GDPR_COOKIE_RETENTION_PERIOD'] = Configuration::get('GDPR_COOKIE_RETENTION_PERIOD');
$helper->fields_value['GDPR_COOKIE_THIRD_PARTIES'] = Configuration::get('GDPR_COOKIE_THIRD_PARTIES');
$helper->fields_value['GDPR_COOKIE_MANAGE_TEXT'] = Configuration::get('GDPR_COOKIE_MANAGE_TEXT');
$helper->fields_value['GDPR_COOKIE_ONLY_REQUIRED'] = Configuration::get('GDPR_COOKIE_ONLY_REQUIRED');
return $helper->generateForm([$form]);
}
@ -276,11 +306,11 @@ class GdprCookieConsent extends Module
'gdprCookieMoreInfoUrl' => $this->context->link->getCMSLink(
Configuration::get('GDPR_COOKIE_MORE_INFO_URL')
),
// New variables
'gdprCookieDataController' => Configuration::get('GDPR_COOKIE_DATA_CONTROLLER', ''),
'gdprCookieRetentionPeriod' => Configuration::get('GDPR_COOKIE_RETENTION_PERIOD', '365 days'),
'gdprCookieThirdParties' => Configuration::get('GDPR_COOKIE_THIRD_PARTIES', ''),
'gdprCookieManageText' => Configuration::get('GDPR_COOKIE_MANAGE_TEXT', 'Manage Cookies'),
'gdprCookieOnlyRequired' => Configuration::get('GDPR_COOKIE_ONLY_REQUIRED'),
]);
// Assign variables to Smarty for the manage button template
@ -317,6 +347,7 @@ class GdprCookieConsent extends Module
'gdprCookieRetentionPeriod' => Configuration::get('GDPR_COOKIE_RETENTION_PERIOD'),
'gdprCookieThirdParties' => Configuration::get('GDPR_COOKIE_THIRD_PARTIES'),
'gdprCookieManageText' => Configuration::get('GDPR_COOKIE_MANAGE_TEXT'),
'gdprCookieOnlyRequired' => Configuration::get('GDPR_COOKIE_ONLY_REQUIRED'),
]);
return $this->display(__FILE__, 'views/templates/hook/footer.tpl');

View File

@ -64,6 +64,7 @@ document.addEventListener('DOMContentLoaded', function() {
acceptAllCookies();
});
if(!gdprCookieOnlyRequired) {
document.getElementById('gdpr-cookie-banner-decline').addEventListener('click', function() {
declineAllCookies();
});
@ -71,6 +72,7 @@ document.addEventListener('DOMContentLoaded', function() {
document.getElementById('gdpr-cookie-banner-settings').addEventListener('click', function() {
showModal();
});
}
// Modal buttons
document.getElementById('gdpr-cookie-accept-all').addEventListener('click', function() {

View File

@ -27,6 +27,7 @@
<label for="gdpr-cookie-necessary">{l s='Necessary' mod='gdprcookieconsent'}</label>
<p>{l s='Necessary cookies help make a website usable by enabling basic functions like page navigation. The website cannot function properly without these cookies.' mod='gdprcookieconsent'}</p>
</div>
{if !$gdprCookieOnlyRequired}
<div class="gdpr-cookie-category">
<input type="checkbox" id="gdpr-cookie-functional" class="gdpr-cookie-checkbox" data-cookie-category="functional">
<label for="gdpr-cookie-functional">{l s='Functional' mod='gdprcookieconsent'}</label>
@ -42,6 +43,7 @@
<label for="gdpr-cookie-marketing">{l s='Marketing' mod='gdprcookieconsent'}</label>
<p>{l s='Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user.' mod='gdprcookieconsent'}</p>
</div>
{/if}
</div>
</div>
<div class="gdpr-cookie-modal-footer">
@ -58,13 +60,15 @@
<div id="gdpr-cookie-banner" class="gdpr-cookie-banner">
<div class="gdpr-cookie-banner-content">
<p>{$gdprCookieMessage}</p>
<div class="gdpr-cookie-banner-info">
<p><small><strong>{l s='Data Controller:' mod='gdprcookieconsent'}</strong> {$gdprCookieDataController} |
<strong>{l s='Retention:' mod='gdprcookieconsent'}</strong> {$gdprCookieRetentionPeriod}</small></p>
</div>
{* <div class="gdpr-cookie-banner-info">*}
{* <p><small><strong>{l s='Data Controller:' mod='gdprcookieconsent'}</strong> {$gdprCookieDataController} | *}
{* <strong>{l s='Retention:' mod='gdprcookieconsent'}</strong> {$gdprCookieRetentionPeriod}</small></p>*}
{* </div>*}
<div class="gdpr-cookie-banner-buttons">
{if !$gdprCookieOnlyRequired}
<button id="gdpr-cookie-banner-decline" class="gdpr-cookie-banner-decline">{$gdprCookieDecline}</button>
<button id="gdpr-cookie-banner-settings" class="gdpr-cookie-banner-settings">{$gdprCookieSettings}</button>
{/if}
<button id="gdpr-cookie-banner-accept" class="gdpr-cookie-banner-accept">{$gdprCookieAccept}</button>
</div>
</div>