Improved GDPR compliance
- Add more customization TODO: Update styling
This commit is contained in:
parent
e8b0d03d9c
commit
5172966eb2
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* GDPR Cookie Consent Module for PrestaShop
|
||||
*
|
||||
@ -42,14 +43,20 @@ class GdprCookieConsent extends Module
|
||||
$this->registerHook('displayHeader') &&
|
||||
$this->registerHook('displayFooter') &&
|
||||
Configuration::updateValue('GDPR_COOKIE_ENABLED', 1) &&
|
||||
Configuration::updateValue('GDPR_COOKIE_MESSAGE', 'This website uses cookies to ensure you get the best experience on our website.') &&
|
||||
Configuration::updateValue('GDPR_COOKIE_MESSAGE', 'This website uses cookies to ensure you get the best experience. We collect and process your data for website functionality, analytics, and personalized advertising.') &&
|
||||
Configuration::updateValue('GDPR_COOKIE_ACCEPT', 'Accept All Cookies') &&
|
||||
Configuration::updateValue('GDPR_COOKIE_DECLINE', 'Decline') &&
|
||||
Configuration::updateValue('GDPR_COOKIE_DECLINE', 'Decline Non-Essential') &&
|
||||
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');
|
||||
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');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Uninstall the module
|
||||
*/
|
||||
@ -62,7 +69,12 @@ class GdprCookieConsent extends Module
|
||||
Configuration::deleteByName('GDPR_COOKIE_DECLINE') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_SETTINGS') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_MORE_INFO') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_MORE_INFO_URL');
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -137,6 +149,27 @@ class GdprCookieConsent extends Module
|
||||
'name' => 'GDPR_COOKIE_MESSAGE',
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Data Controller'),
|
||||
'name' => 'GDPR_COOKIE_DATA_CONTROLLER',
|
||||
'desc' => $this->l('Your company/organization name'),
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Cookie Retention Period'),
|
||||
'name' => 'GDPR_COOKIE_RETENTION_PERIOD',
|
||||
'desc' => $this->l('How long cookies will be stored (e.g., 365 days)'),
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Third-Party Recipients'),
|
||||
'name' => 'GDPR_COOKIE_THIRD_PARTIES',
|
||||
'desc' => $this->l('List third parties that receive cookie data'),
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Accept Button Text'),
|
||||
@ -155,6 +188,13 @@ class GdprCookieConsent extends Module
|
||||
'name' => 'GDPR_COOKIE_SETTINGS',
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Manage Preferences Text'),
|
||||
'name' => 'GDPR_COOKIE_MANAGE_TEXT',
|
||||
'desc' => $this->l('Text for the manage preferences button (displayed after consent is given)'),
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('More Info Button Text'),
|
||||
@ -202,6 +242,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');
|
||||
|
||||
return $helper->generateForm([$form]);
|
||||
}
|
||||
@ -231,7 +276,22 @@ 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'),
|
||||
]);
|
||||
|
||||
// Assign variables to Smarty for the manage button template
|
||||
$this->context->smarty->assign([
|
||||
'gdprCookieManageText' => Configuration::get('GDPR_COOKIE_MANAGE_TEXT', 'Manage Cookies'),
|
||||
]);
|
||||
|
||||
// Return the template content - but don't throw an error if it doesn't exist yet
|
||||
if (file_exists(_PS_MODULE_DIR_ . $this->name . '/views/templates/hook/manage_button.tpl')) {
|
||||
return $this->display(__FILE__, 'views/templates/hook/manage_button.tpl');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -252,6 +312,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'),
|
||||
'gdprCookieThirdParties' => Configuration::get('GDPR_COOKIE_THIRD_PARTIES'),
|
||||
'gdprCookieManageText' => Configuration::get('GDPR_COOKIE_MANAGE_TEXT'),
|
||||
]);
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hook/footer.tpl');
|
||||
|
@ -225,3 +225,72 @@
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
|
||||
.gdpr-cookie-info-block {
|
||||
margin: 15px 0;
|
||||
padding: 15px;
|
||||
background-color: #f9f9f9;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-info-block p {
|
||||
margin: 5px 0;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-info {
|
||||
margin: 5px 0 10px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-info p {
|
||||
font-size: 12px;
|
||||
opacity: 0.9;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Equal prominence for buttons */
|
||||
.gdpr-cookie-banner-decline,
|
||||
.gdpr-cookie-banner-accept {
|
||||
font-weight: 400;
|
||||
padding: 8px 15px;
|
||||
border-radius: 3px;
|
||||
/* Make both buttons similar size but distinctive */
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-decline {
|
||||
background-color: #f1f1f1;
|
||||
color: #333;
|
||||
border: 1px solid #ccc;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-accept {
|
||||
background-color: #4caf50;
|
||||
color: white;
|
||||
border: 1px solid #4caf50;
|
||||
}
|
||||
|
||||
/* Manage button styles */
|
||||
.gdpr-cookie-manage-button {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
right: 20px;
|
||||
z-index: 9990;
|
||||
}
|
||||
|
||||
.gdpr-cookie-manage {
|
||||
padding: 8px 12px;
|
||||
background-color: #f1f1f1;
|
||||
color: #333;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: 3px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.gdpr-cookie-manage:hover {
|
||||
background-color: #e5e5e5;
|
||||
}
|
@ -29,6 +29,21 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Show manage preferences button when cookies are already set
|
||||
function showManageButton() {
|
||||
document.getElementById('gdpr-cookie-manage-button').style.display = 'block';
|
||||
}
|
||||
|
||||
// After user consents, hide banner and modal and show the manage button
|
||||
function afterConsent() {
|
||||
// Hide banner and modal
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
|
||||
// Show manage button
|
||||
showManageButton();
|
||||
}
|
||||
|
||||
// Check if cookie consent is already set
|
||||
var cookieConsent = getCookie('gdpr_cookie_consent');
|
||||
|
||||
@ -39,6 +54,9 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
// Apply cookie preferences
|
||||
var consentPreferences = JSON.parse(cookieConsent);
|
||||
applyConsentPreferences(consentPreferences);
|
||||
|
||||
// Show the manage button since consent was already given
|
||||
showManageButton();
|
||||
}
|
||||
|
||||
// Banner buttons
|
||||
@ -67,6 +85,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
acceptSelectedCookies();
|
||||
});
|
||||
|
||||
// Manage button (for after consent is given)
|
||||
document.getElementById('gdpr-cookie-manage').addEventListener('click', function() {
|
||||
showModal();
|
||||
});
|
||||
|
||||
// Functions
|
||||
function showModal() {
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
@ -103,8 +126,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
afterConsent(); // Use the new function for consistent post-consent behavior
|
||||
}
|
||||
|
||||
function declineAllCookies() {
|
||||
@ -117,8 +139,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
afterConsent(); // Use the new function for consistent post-consent behavior
|
||||
}
|
||||
|
||||
function acceptSelectedCookies() {
|
||||
@ -134,8 +155,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
afterConsent(); // Use the new function for consistent post-consent behavior
|
||||
}
|
||||
|
||||
function applyConsentPreferences(preferences) {
|
||||
@ -179,6 +199,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
function disableAnalytics() {
|
||||
// Example: Disable Google Analytics
|
||||
window['ga-disable-UA-XXXXXXXX-X'] = true;
|
||||
|
||||
// Remove existing GA cookies
|
||||
document.cookie = '_ga=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=.' + window.location.hostname;
|
||||
document.cookie = '_gid=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=.' + window.location.hostname;
|
||||
document.cookie = '_gat=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=.' + window.location.hostname;
|
||||
}
|
||||
|
||||
function enableAnalytics() {
|
||||
@ -187,12 +212,20 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
}
|
||||
|
||||
function disableMarketing() {
|
||||
// Example implementation
|
||||
// You would implement according to your specific marketing cookies
|
||||
// Example implementation for common marketing cookies
|
||||
var marketingCookies = ['_fbp', 'fr', 'IDE', 'MUID', 'personalization_id'];
|
||||
var domains = [window.location.hostname, '.' + window.location.hostname];
|
||||
|
||||
marketingCookies.forEach(function(cookie) {
|
||||
domains.forEach(function(domain) {
|
||||
document.cookie = cookie + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT; Domain=' + domain;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function enableMarketing() {
|
||||
// Example implementation
|
||||
// You would implement according to your specific marketing cookies
|
||||
// For enabling marketing, we typically don't need to do anything special
|
||||
// The marketing scripts will set their cookies when they load
|
||||
// Just ensure the marketing scripts are loaded after checking consent
|
||||
}
|
||||
});
|
@ -14,6 +14,13 @@
|
||||
<div class="gdpr-cookie-modal-body">
|
||||
<p>{$gdprCookieMessage}</p>
|
||||
|
||||
<div class="gdpr-cookie-info-block">
|
||||
<p><strong>{l s='Data Controller:' mod='gdprcookieconsent'}</strong> {$gdprCookieDataController}</p>
|
||||
<p><strong>{l s='Cookie Retention Period:' mod='gdprcookieconsent'}</strong> {$gdprCookieRetentionPeriod}</p>
|
||||
<p><strong>{l s='Third-Party Recipients:' mod='gdprcookieconsent'}</strong> {$gdprCookieThirdParties}</p>
|
||||
<p><strong>{l s='Your Rights:' mod='gdprcookieconsent'}</strong> {l s='You can withdraw your consent at any time by clicking the "Manage Cookie Preferences" button or by deleting cookies in your browser settings.' mod='gdprcookieconsent'}</p>
|
||||
</div>
|
||||
|
||||
<div class="gdpr-cookie-categories">
|
||||
<div class="gdpr-cookie-category">
|
||||
<input type="checkbox" id="gdpr-cookie-necessary" checked disabled>
|
||||
@ -51,6 +58,10 @@
|
||||
<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-buttons">
|
||||
<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>
|
||||
@ -58,3 +69,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gdpr-cookie-manage-button" class="gdpr-cookie-manage-button" style="display: none;">
|
||||
<button id="gdpr-cookie-manage" class="gdpr-cookie-manage">{$gdprCookieManageText}</button>
|
||||
</div>
|
11
views/templates/hook/manage_button.tpl
Normal file
11
views/templates/hook/manage_button.tpl
Normal file
@ -0,0 +1,11 @@
|
||||
{*
|
||||
* GDPR Cookie Consent Module for PrestaShop
|
||||
*
|
||||
* @author Walzen665
|
||||
* @copyright Copyright (c) 2025
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
*}
|
||||
|
||||
<div id="gdpr-cookie-manage-button" class="gdpr-cookie-manage-button" style="display: none;">
|
||||
<button id="gdpr-cookie-manage" class="gdpr-cookie-manage">{$gdprCookieManageText}</button>
|
||||
</div>
|
Loading…
x
Reference in New Issue
Block a user