diff --git a/modules/blocknewsletter/blocknewsletter.php b/modules/blocknewsletter/blocknewsletter.php index a0f4565e9..498fbd00d 100644 --- a/modules/blocknewsletter/blocknewsletter.php +++ b/modules/blocknewsletter/blocknewsletter.php @@ -61,7 +61,8 @@ class Blocknewsletter extends Module public function install() { - if (parent::install() == false || $this->registerHook('leftColumn') == false || $this->registerHook('header') == false) + if (parent::install() == false || $this->registerHook('leftColumn') == false || $this->registerHook('header') == false + || $this->registerHook('actionCustomerAccountAdd') == false) return false; Configuration::updateValue('NW_SALT', Tools::passwdGen(16)); @@ -521,4 +522,20 @@ class Blocknewsletter extends Module { $this->context->controller->addCSS($this->_path.'blocknewsletter.css', 'all'); } + + /** + * Deletes duplicates email in newsletter table + * @param $params + * @return bool + */ + public function hookActionCustomerAccountAdd($params) + { + //if e-mail of the created user address has already been added to the newsletter through the blocknewsletter module, + //we delete it from blocknewsletter table to prevent duplicates + $id_shop = $params['newCustomer']->id_shop; + $email = $params['newCustomer']->email; + if (Validate::isEmail($email)) + return (bool)Db::getInstance()->execute('DELETE FROM '._DB_PREFIX_.'newsletter WHERE id_shop='.(int)$id_shop.' AND email=\''.pSQL($email)."'"); + return false; + } }