Prevent email to be stored twice (1 in customer newsletter and 1 in module newsletter) by removing email in newsletter table when creating a new account

#PNM-1419
This commit is contained in:
Fabio Chelly
2013-06-28 18:10:13 +02:00
parent cf9c73a854
commit ae2491c402
+18 -1
View File
@@ -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;
}
}