Initial commit
- Functional module
This commit is contained in:
commit
677b2481ce
4
README.md
Normal file
4
README.md
Normal file
@ -0,0 +1,4 @@
|
||||
# How to install
|
||||
|
||||
1. Select all files in root folder and pack them into a .zip
|
||||
2. Install the .zip on you PrestaShop instance
|
259
gdprcookieconsent.php
Normal file
259
gdprcookieconsent.php
Normal file
@ -0,0 +1,259 @@
|
||||
<?php
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
if (!defined('_PS_VERSION_')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class GdprCookieConsent extends Module
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->name = 'gdprcookieconsent';
|
||||
$this->tab = 'front_office_features';
|
||||
$this->version = '1.0.0';
|
||||
$this->author = 'Walzen665';
|
||||
$this->need_instance = 0;
|
||||
$this->ps_versions_compliancy = [
|
||||
'min' => '1.7.0.0',
|
||||
'max' => _PS_VERSION_
|
||||
];
|
||||
$this->bootstrap = true;
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->displayName = $this->l('GDPR Cookie Consent');
|
||||
$this->description = $this->l('Adds a GDPR compliant cookie consent modal to your shop');
|
||||
$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
|
||||
}
|
||||
|
||||
/**
|
||||
* Install the module
|
||||
*/
|
||||
public function install()
|
||||
{
|
||||
return parent::install() &&
|
||||
$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_ACCEPT', 'Accept All Cookies') &&
|
||||
Configuration::updateValue('GDPR_COOKIE_DECLINE', 'Decline') &&
|
||||
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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Uninstall the module
|
||||
*/
|
||||
public function uninstall()
|
||||
{
|
||||
return parent::uninstall() &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_ENABLED') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_MESSAGE') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_ACCEPT') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_DECLINE') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_SETTINGS') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_MORE_INFO') &&
|
||||
Configuration::deleteByName('GDPR_COOKIE_MORE_INFO_URL');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the configuration form
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
$output = '';
|
||||
|
||||
// If form submitted
|
||||
if (Tools::isSubmit('submitGdprCookieModule')) {
|
||||
// Get configuration values from form
|
||||
$enabled = (int)Tools::getValue('GDPR_COOKIE_ENABLED');
|
||||
$message = Tools::getValue('GDPR_COOKIE_MESSAGE');
|
||||
$accept = Tools::getValue('GDPR_COOKIE_ACCEPT');
|
||||
$decline = Tools::getValue('GDPR_COOKIE_DECLINE');
|
||||
$settings = Tools::getValue('GDPR_COOKIE_SETTINGS');
|
||||
$moreInfo = Tools::getValue('GDPR_COOKIE_MORE_INFO');
|
||||
$moreInfoUrl = Tools::getValue('GDPR_COOKIE_MORE_INFO_URL');
|
||||
|
||||
// Update configuration values
|
||||
Configuration::updateValue('GDPR_COOKIE_ENABLED', $enabled);
|
||||
Configuration::updateValue('GDPR_COOKIE_MESSAGE', $message);
|
||||
Configuration::updateValue('GDPR_COOKIE_ACCEPT', $accept);
|
||||
Configuration::updateValue('GDPR_COOKIE_DECLINE', $decline);
|
||||
Configuration::updateValue('GDPR_COOKIE_SETTINGS', $settings);
|
||||
Configuration::updateValue('GDPR_COOKIE_MORE_INFO', $moreInfo);
|
||||
Configuration::updateValue('GDPR_COOKIE_MORE_INFO_URL', $moreInfoUrl);
|
||||
|
||||
// Display confirmation
|
||||
$output .= $this->displayConfirmation($this->l('Settings updated'));
|
||||
}
|
||||
|
||||
// Display the configuration form
|
||||
return $output . $this->displayForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the configuration form
|
||||
*/
|
||||
protected function displayForm()
|
||||
{
|
||||
// Init Fields form array
|
||||
$form = [
|
||||
'form' => [
|
||||
'legend' => [
|
||||
'title' => $this->l('Settings'),
|
||||
'icon' => 'icon-cogs',
|
||||
],
|
||||
'input' => [
|
||||
[
|
||||
'type' => 'switch',
|
||||
'label' => $this->l('Enable Cookie Consent'),
|
||||
'name' => 'GDPR_COOKIE_ENABLED',
|
||||
'is_bool' => true,
|
||||
'values' => [
|
||||
[
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => $this->l('Enabled')
|
||||
],
|
||||
[
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => $this->l('Disabled')
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'type' => 'textarea',
|
||||
'label' => $this->l('Cookie Consent Message'),
|
||||
'name' => 'GDPR_COOKIE_MESSAGE',
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Accept Button Text'),
|
||||
'name' => 'GDPR_COOKIE_ACCEPT',
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Decline Button Text'),
|
||||
'name' => 'GDPR_COOKIE_DECLINE',
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Settings Button Text'),
|
||||
'name' => 'GDPR_COOKIE_SETTINGS',
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('More Info Button Text'),
|
||||
'name' => 'GDPR_COOKIE_MORE_INFO',
|
||||
'required' => true,
|
||||
],
|
||||
[
|
||||
'type' => 'text',
|
||||
'label' => $this->l('More Info URL'),
|
||||
'desc' => $this->l('URL to your Privacy Policy page'),
|
||||
'name' => 'GDPR_COOKIE_MORE_INFO_URL',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
'submit' => [
|
||||
'title' => $this->l('Save'),
|
||||
'class' => 'btn btn-default pull-right',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$helper = new HelperForm();
|
||||
|
||||
// Module, token and currentIndex
|
||||
$helper->module = $this;
|
||||
$helper->name_controller = $this->name;
|
||||
$helper->token = Tools::getAdminTokenLite('AdminModules');
|
||||
$helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;
|
||||
|
||||
// Language
|
||||
$helper->default_form_language = $this->context->language->id;
|
||||
$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG', 0);
|
||||
|
||||
// Title and toolbar
|
||||
$helper->title = $this->displayName;
|
||||
$helper->show_toolbar = true;
|
||||
$helper->toolbar_scroll = true;
|
||||
$helper->submit_action = 'submitGdprCookieModule';
|
||||
|
||||
// Load current values
|
||||
$helper->fields_value['GDPR_COOKIE_ENABLED'] = Configuration::get('GDPR_COOKIE_ENABLED');
|
||||
$helper->fields_value['GDPR_COOKIE_MESSAGE'] = Configuration::get('GDPR_COOKIE_MESSAGE');
|
||||
$helper->fields_value['GDPR_COOKIE_ACCEPT'] = Configuration::get('GDPR_COOKIE_ACCEPT');
|
||||
$helper->fields_value['GDPR_COOKIE_DECLINE'] = Configuration::get('GDPR_COOKIE_DECLINE');
|
||||
$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');
|
||||
|
||||
return $helper->generateForm([$form]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add CSS and JS to the header
|
||||
*/
|
||||
public function hookDisplayHeader()
|
||||
{
|
||||
if (!Configuration::get('GDPR_COOKIE_ENABLED')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add CSS
|
||||
$this->context->controller->addCSS($this->_path . 'views/css/gdpr_cookie.css');
|
||||
|
||||
// Add JS
|
||||
$this->context->controller->addJS($this->_path . 'views/js/gdpr_cookie.js');
|
||||
|
||||
// Add JS variables for modal
|
||||
Media::addJsDef([
|
||||
'gdprCookieMessage' => Configuration::get('GDPR_COOKIE_MESSAGE'),
|
||||
'gdprCookieAccept' => Configuration::get('GDPR_COOKIE_ACCEPT'),
|
||||
'gdprCookieDecline' => Configuration::get('GDPR_COOKIE_DECLINE'),
|
||||
'gdprCookieSettings' => Configuration::get('GDPR_COOKIE_SETTINGS'),
|
||||
'gdprCookieMoreInfo' => Configuration::get('GDPR_COOKIE_MORE_INFO'),
|
||||
'gdprCookieMoreInfoUrl' => $this->context->link->getCMSLink(
|
||||
Configuration::get('GDPR_COOKIE_MORE_INFO_URL')
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the cookie modal to the footer
|
||||
*/
|
||||
public function hookDisplayFooter()
|
||||
{
|
||||
if (!Configuration::get('GDPR_COOKIE_ENABLED')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->smarty->assign([
|
||||
'gdprCookieMessage' => Configuration::get('GDPR_COOKIE_MESSAGE'),
|
||||
'gdprCookieAccept' => Configuration::get('GDPR_COOKIE_ACCEPT'),
|
||||
'gdprCookieDecline' => Configuration::get('GDPR_COOKIE_DECLINE'),
|
||||
'gdprCookieSettings' => Configuration::get('GDPR_COOKIE_SETTINGS'),
|
||||
'gdprCookieMoreInfo' => Configuration::get('GDPR_COOKIE_MORE_INFO'),
|
||||
'gdprCookieMoreInfoUrl' => $this->context->link->getCMSLink(
|
||||
Configuration::get('GDPR_COOKIE_MORE_INFO_URL')
|
||||
),
|
||||
]);
|
||||
|
||||
return $this->display(__FILE__, 'views/templates/hook/footer.tpl');
|
||||
}
|
||||
}
|
7
index.php
Normal file
7
index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("X-Frame-Options: DENY");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header('Location: ../');
|
||||
exit;
|
7
translations/index.php
Normal file
7
translations/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("X-Frame-Options: DENY");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header('Location: ../');
|
||||
exit;
|
227
views/css/gdpr_cookie.css
Normal file
227
views/css/gdpr_cookie.css
Normal file
@ -0,0 +1,227 @@
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
/* Banner styles */
|
||||
.gdpr-cookie-banner {
|
||||
display: none;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
background-color: rgba(33, 41, 52, 0.95);
|
||||
color: #fff;
|
||||
padding: 15px;
|
||||
z-index: 9999;
|
||||
box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-content {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-content p {
|
||||
flex: 1;
|
||||
margin: 0 20px 10px 0;
|
||||
font-size: 14px;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-buttons {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
/* Modal styles */
|
||||
.gdpr-cookie-modal {
|
||||
display: none;
|
||||
position: fixed;
|
||||
z-index: 10000;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
background-color: rgba(0, 0, 0, 0.5);
|
||||
}
|
||||
|
||||
.gdpr-cookie-modal-content {
|
||||
background-color: #fff;
|
||||
margin: 5% auto;
|
||||
padding: 20px;
|
||||
border-radius: 5px;
|
||||
width: 90%;
|
||||
max-width: 800px;
|
||||
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
||||
max-height: 80vh;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.gdpr-cookie-modal-header {
|
||||
border-bottom: 1px solid #e5e5e5;
|
||||
margin-bottom: 15px;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-modal-header h4 {
|
||||
margin: 0;
|
||||
color: #333;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-modal-body {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-categories {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-category {
|
||||
margin-bottom: 15px;
|
||||
padding: 10px;
|
||||
border: 1px solid #eee;
|
||||
border-radius: 5px;
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.gdpr-cookie-category label {
|
||||
font-weight: bold;
|
||||
display: inline-block;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-category p {
|
||||
margin-top: 5px;
|
||||
margin-bottom: 0;
|
||||
font-size: 13px;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.gdpr-cookie-modal-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-top: 1px solid #e5e5e5;
|
||||
padding-top: 15px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-more-info {
|
||||
color: #555;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.gdpr-cookie-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
/* Button styles */
|
||||
.gdpr-cookie-decline,
|
||||
.gdpr-cookie-banner-decline {
|
||||
background-color: #f1f1f1;
|
||||
color: #333;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.gdpr-cookie-decline:hover,
|
||||
.gdpr-cookie-banner-decline:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
.gdpr-cookie-accept-selected {
|
||||
background-color: #4285f4;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.gdpr-cookie-accept-selected:hover {
|
||||
background-color: #2b6edb;
|
||||
}
|
||||
|
||||
.gdpr-cookie-accept-all,
|
||||
.gdpr-cookie-banner-accept {
|
||||
background-color: #4caf50;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 8px 15px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.gdpr-cookie-accept-all:hover,
|
||||
.gdpr-cookie-banner-accept:hover {
|
||||
background-color: #45a049;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-settings {
|
||||
background-color: transparent;
|
||||
color: white;
|
||||
border: 1px solid white;
|
||||
padding: 8px 15px;
|
||||
text-align: center;
|
||||
text-decoration: none;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
border-radius: 3px;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-settings:hover {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
/* Responsive adjustments */
|
||||
@media (max-width: 768px) {
|
||||
.gdpr-cookie-banner-content {
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.gdpr-cookie-banner-content p {
|
||||
margin-right: 0;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-modal-content {
|
||||
width: 95%;
|
||||
margin: 10% auto;
|
||||
}
|
||||
|
||||
.gdpr-cookie-modal-footer {
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
}
|
||||
|
||||
.gdpr-cookie-more-info {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
7
views/css/index.php
Normal file
7
views/css/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("X-Frame-Options: DENY");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header('Location: ../');
|
||||
exit;
|
7
views/index.php
Normal file
7
views/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("X-Frame-Options: DENY");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header('Location: ../');
|
||||
exit;
|
198
views/js/gdpr_cookie.js
Normal file
198
views/js/gdpr_cookie.js
Normal file
@ -0,0 +1,198 @@
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Cookie functions
|
||||
function setCookie(name, value, days) {
|
||||
var expires = '';
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = '; expires=' + date.toUTCString();
|
||||
}
|
||||
document.cookie = name + '=' + (value || '') + expires + '; path=/; SameSite=Lax';
|
||||
}
|
||||
|
||||
function getCookie(name) {
|
||||
var nameEQ = name + '=';
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Check if cookie consent is already set
|
||||
var cookieConsent = getCookie('gdpr_cookie_consent');
|
||||
|
||||
if (!cookieConsent) {
|
||||
// Show the cookie banner if consent is not set
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'block';
|
||||
} else {
|
||||
// Apply cookie preferences
|
||||
var consentPreferences = JSON.parse(cookieConsent);
|
||||
applyConsentPreferences(consentPreferences);
|
||||
}
|
||||
|
||||
// Banner buttons
|
||||
document.getElementById('gdpr-cookie-banner-accept').addEventListener('click', function() {
|
||||
acceptAllCookies();
|
||||
});
|
||||
|
||||
document.getElementById('gdpr-cookie-banner-decline').addEventListener('click', function() {
|
||||
declineAllCookies();
|
||||
});
|
||||
|
||||
document.getElementById('gdpr-cookie-banner-settings').addEventListener('click', function() {
|
||||
showModal();
|
||||
});
|
||||
|
||||
// Modal buttons
|
||||
document.getElementById('gdpr-cookie-accept-all').addEventListener('click', function() {
|
||||
acceptAllCookies();
|
||||
});
|
||||
|
||||
document.getElementById('gdpr-cookie-decline').addEventListener('click', function() {
|
||||
declineAllCookies();
|
||||
});
|
||||
|
||||
document.getElementById('gdpr-cookie-accept-selected').addEventListener('click', function() {
|
||||
acceptSelectedCookies();
|
||||
});
|
||||
|
||||
// Functions
|
||||
function showModal() {
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
document.getElementById('gdpr-cookie-modal').style.display = 'block';
|
||||
|
||||
// Load saved preferences if they exist
|
||||
var cookieConsent = getCookie('gdpr_cookie_consent');
|
||||
if (cookieConsent) {
|
||||
var preferences = JSON.parse(cookieConsent);
|
||||
|
||||
// Set checkboxes based on saved preferences
|
||||
document.querySelectorAll('.gdpr-cookie-checkbox').forEach(function(checkbox) {
|
||||
var category = checkbox.getAttribute('data-cookie-category');
|
||||
if (preferences[category]) {
|
||||
checkbox.checked = true;
|
||||
} else {
|
||||
checkbox.checked = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function hideModal() {
|
||||
document.getElementById('gdpr-cookie-modal').style.display = 'none';
|
||||
}
|
||||
|
||||
function acceptAllCookies() {
|
||||
var preferences = {
|
||||
necessary: true,
|
||||
functional: true,
|
||||
analytics: true,
|
||||
marketing: true
|
||||
};
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
}
|
||||
|
||||
function declineAllCookies() {
|
||||
var preferences = {
|
||||
necessary: true, // Necessary cookies are always accepted
|
||||
functional: false,
|
||||
analytics: false,
|
||||
marketing: false
|
||||
};
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
}
|
||||
|
||||
function acceptSelectedCookies() {
|
||||
var preferences = {
|
||||
necessary: true // Necessary cookies are always accepted
|
||||
};
|
||||
|
||||
// Get selected preferences
|
||||
document.querySelectorAll('.gdpr-cookie-checkbox').forEach(function(checkbox) {
|
||||
var category = checkbox.getAttribute('data-cookie-category');
|
||||
preferences[category] = checkbox.checked;
|
||||
});
|
||||
|
||||
setCookie('gdpr_cookie_consent', JSON.stringify(preferences), 365);
|
||||
applyConsentPreferences(preferences);
|
||||
hideModal();
|
||||
document.getElementById('gdpr-cookie-banner').style.display = 'none';
|
||||
}
|
||||
|
||||
function applyConsentPreferences(preferences) {
|
||||
// Example implementation
|
||||
// You would need to adapt this based on your specific cookie usage
|
||||
|
||||
// Functional cookies
|
||||
if (!preferences.functional) {
|
||||
// Disable functional cookies
|
||||
removeFunctionalCookies();
|
||||
}
|
||||
|
||||
// Analytics cookies
|
||||
if (!preferences.analytics) {
|
||||
// Disable analytics cookies (like Google Analytics)
|
||||
disableAnalytics();
|
||||
} else {
|
||||
// Enable analytics
|
||||
enableAnalytics();
|
||||
}
|
||||
|
||||
// Marketing cookies
|
||||
if (!preferences.marketing) {
|
||||
// Disable marketing cookies
|
||||
disableMarketing();
|
||||
} else {
|
||||
// Enable marketing
|
||||
enableMarketing();
|
||||
}
|
||||
}
|
||||
|
||||
// Helper functions to implement consent preferences
|
||||
function removeFunctionalCookies() {
|
||||
// This is just an example - implement based on your specific needs
|
||||
var functionalCookies = ['prefs', 'language', 'theme'];
|
||||
functionalCookies.forEach(function(cookie) {
|
||||
document.cookie = cookie + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
|
||||
});
|
||||
}
|
||||
|
||||
function disableAnalytics() {
|
||||
// Example: Disable Google Analytics
|
||||
window['ga-disable-UA-XXXXXXXX-X'] = true;
|
||||
}
|
||||
|
||||
function enableAnalytics() {
|
||||
// Example: Enable Google Analytics
|
||||
window['ga-disable-UA-XXXXXXXX-X'] = false;
|
||||
}
|
||||
|
||||
function disableMarketing() {
|
||||
// Example implementation
|
||||
// You would implement according to your specific marketing cookies
|
||||
}
|
||||
|
||||
function enableMarketing() {
|
||||
// Example implementation
|
||||
// You would implement according to your specific marketing cookies
|
||||
}
|
||||
});
|
7
views/js/index.php
Normal file
7
views/js/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("X-Frame-Options: DENY");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header('Location: ../');
|
||||
exit;
|
60
views/templates/hook/footer.tpl
Normal file
60
views/templates/hook/footer.tpl
Normal file
@ -0,0 +1,60 @@
|
||||
{*
|
||||
* 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-modal" class="gdpr-cookie-modal">
|
||||
<div class="gdpr-cookie-modal-content">
|
||||
<div class="gdpr-cookie-modal-header">
|
||||
<h4>{l s='Cookie Settings' mod='gdprcookieconsent'}</h4>
|
||||
</div>
|
||||
<div class="gdpr-cookie-modal-body">
|
||||
<p>{$gdprCookieMessage}</p>
|
||||
|
||||
<div class="gdpr-cookie-categories">
|
||||
<div class="gdpr-cookie-category">
|
||||
<input type="checkbox" id="gdpr-cookie-necessary" checked disabled>
|
||||
<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>
|
||||
<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>
|
||||
<p>{l s='Functional cookies enable a website to remember information that changes the way the website behaves or looks, like your preferred language or the region you are in.' mod='gdprcookieconsent'}</p>
|
||||
</div>
|
||||
<div class="gdpr-cookie-category">
|
||||
<input type="checkbox" id="gdpr-cookie-analytics" class="gdpr-cookie-checkbox" data-cookie-category="analytics">
|
||||
<label for="gdpr-cookie-analytics">{l s='Analytics' mod='gdprcookieconsent'}</label>
|
||||
<p>{l s='Analytics cookies help website owners understand how visitors interact with websites by collecting and reporting information anonymously.' mod='gdprcookieconsent'}</p>
|
||||
</div>
|
||||
<div class="gdpr-cookie-category">
|
||||
<input type="checkbox" id="gdpr-cookie-marketing" class="gdpr-cookie-checkbox" data-cookie-category="marketing">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gdpr-cookie-modal-footer">
|
||||
<a href="{$gdprCookieMoreInfoUrl}" class="gdpr-cookie-more-info">{$gdprCookieMoreInfo}</a>
|
||||
<div class="gdpr-cookie-buttons">
|
||||
<button id="gdpr-cookie-decline" class="gdpr-cookie-decline">{$gdprCookieDecline}</button>
|
||||
<button id="gdpr-cookie-accept-selected" class="gdpr-cookie-accept-selected">{l s='Accept Selected' mod='gdprcookieconsent'}</button>
|
||||
<button id="gdpr-cookie-accept-all" class="gdpr-cookie-accept-all">{$gdprCookieAccept}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="gdpr-cookie-banner" class="gdpr-cookie-banner">
|
||||
<div class="gdpr-cookie-banner-content">
|
||||
<p>{$gdprCookieMessage}</p>
|
||||
<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>
|
||||
<button id="gdpr-cookie-banner-accept" class="gdpr-cookie-banner-accept">{$gdprCookieAccept}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
7
views/templates/hook/index.php
Normal file
7
views/templates/hook/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("X-Frame-Options: DENY");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header('Location: ../');
|
||||
exit;
|
7
views/templates/index.php
Normal file
7
views/templates/index.php
Normal file
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
header('Strict-Transport-Security: max-age=31536000; includeSubDomains');
|
||||
header("X-Content-Type-Options: nosniff");
|
||||
header("X-Frame-Options: DENY");
|
||||
header("X-XSS-Protection: 1; mode=block");
|
||||
header('Location: ../');
|
||||
exit;
|
Loading…
x
Reference in New Issue
Block a user