commit 677b2481ce2a38c77e70b98c0f5248f24e33622e Author: Walz Date: Mon Apr 7 16:41:38 2025 +0200 Initial commit - Functional module diff --git a/README.md b/README.md new file mode 100644 index 0000000..c614107 --- /dev/null +++ b/README.md @@ -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 \ No newline at end of file diff --git a/gdprcookieconsent.php b/gdprcookieconsent.php new file mode 100644 index 0000000..1f6d4b5 --- /dev/null +++ b/gdprcookieconsent.php @@ -0,0 +1,259 @@ +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'); + } +} \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..c73768f --- /dev/null +++ b/index.php @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/views/templates/hook/index.php b/views/templates/hook/index.php new file mode 100644 index 0000000..c73768f --- /dev/null +++ b/views/templates/hook/index.php @@ -0,0 +1,7 @@ +