diff --git a/ps_emailsubscription.php b/ps_emailsubscription.php index 8de6d5d..9738960 100644 --- a/ps_emailsubscription.php +++ b/ps_emailsubscription.php @@ -964,25 +964,20 @@ public function hookActionCustomerAccountAdd($params) if (empty($params['newCustomer'])) { return false; } + $id_shop = $params['newCustomer']->id_shop; $email = $params['newCustomer']->email; - $newsletter = $params['newCustomer']->newsletter; - if (Validate::isEmail($email)) { - if ($params['newCustomer']->newsletter && $code = Configuration::get('NW_VOUCHER_CODE')) { - $this->sendVoucher($email, $code); - } - if ($params['newCustomer']->newsletter) { - return (bool) Db::getInstance()->execute('DELETE FROM ' . _DB_PREFIX_ . 'emailsubscription WHERE id_shop=' . (int) $id_shop . ' AND email=\'' . pSQL($email) . "'"); - } + + if (!Validate::isEmail($email)) { + return false; } - if ($newsletter) { - if (Configuration::get('NW_CONFIRMATION_EMAIL')) {// send confirmation email - $this->sendConfirmationEmail($params['newCustomer']->email); - } - if ($code = Configuration::get('NW_VOUCHER_CODE')) {// send voucher - $this->sendVoucher($params['newCustomer']->email, $code); + if ($params['newCustomer']->newsletter) { + if ($code = Configuration::get('NW_VOUCHER_CODE')) { + $this->sendVoucher($email, $code); } + + return Db::getInstance()->execute('DELETE FROM `' . _DB_PREFIX_ . 'emailsubscription` WHERE id_shop = ' . (int) $id_shop . ' AND email = "' . pSQL($email) . '"'); } return true;