Jump to content

Email already registered - [SOLVED]


Recommended Posts

Assalamu Alykum Dawood,

 

No, not yet.

You can check out my website: sitinuriatistudio.com to see the problem. It will send the email registration to the person, but it shows in red,'your email is already registered still. Also, if they try to register from a category or product page, where my newsletter is on the side, it'll go back to my homepage and give that same error (at least better than going to a blank page as it had before, but still weird!).

Link to comment
Share on other sites

Wa alaikum salaam warahmatullah!

 

I had setup PS v1.5.5 and NewsLetter Module 1.4.

 

We need to debug this problem step by step because I really don't know what the problem is exactly. Can u send me your BlockNewsLetter Module and send it to me ? I'll try to reproduce the error in my local setup and then insha Allah I will have an answer.

Link to comment
Share on other sites

As salaamu alaikum,

 

I have found the bug and here is the fix. I wrote this in another forum reproducing it here.

 

This is age old bug. Its amazing this bug escaped the eyes of prestashop developers. In Programming, equal to is == (double equal to) and a single = is assignment.

 

So search for line :

if (!$registered = Db::getInstance()->getRow($sql))
    return self::GUEST_NOT_REGISTERED; 

Replace the above with this piece of code

if (!$registered == Db::getInstance()->getRow($sql))
    return self::GUEST_NOT_REGISTERED; 

Notice the doubel equal to. This should fix your bug.

Edited by ibndawood (see edit history)
  • Like 1
Link to comment
Share on other sites

Jazakallah,

 

That fixes it. I'll have to check the original to the new one to see what you did. Cuz you must've done more like you said, because it didn't work for me when I did that one fix.

Wow. Can't believe the whole blocknewsletter module itself is so flawed. Too many places with assignment (=) instead of equal to (==). I have changed them in all the places. Here is the updated file.

 

attachicon.gifblocknewsletter.php

 

This should work insha Allah.

  • Like 1
Link to comment
Share on other sites

Hi El Patron,

 

Yes I will try a pull request in github.

 

Closeupman,

 

Yes there are about 7 places this mistake is repeated. I changed in all those places.

 

Here is the detailed account : http://blog.prestastrap.com/block-newsletter-module-returns-this-email-address-is-already-registered-error/

Edited by ibndawood (see edit history)
Link to comment
Share on other sites

Guys, I jumped the gun saying the prestashop developers had made the most basic mistake in programming. But its my mistake I failed to look into the code thoroughly. I did look into it and I found out that those assignment operators were intentional.

 


Ok so what was causing the problem. Quick answer : The Hooks. i.e. if the module is hooked to more than one place then this error will occur.


 


Long Answer :


Lets assume you have hooked block newsletter to Left Column and to Footer or Home. You hide the left column in the home page (note : you are only hiding the left column. This doesn’t mean the left column hook is not executed) and just display the newsletter block in the home page. When you submit the email. This is what happens.


 


*  First the left column hook is executed, which will take your email and save it to the database.


Next footer (or home) hook is executed. So what happens now while executing the footer hook (or home) is that the module tries to save the email again. Since we had already saved the email while executing the left column hook. We get “This email address is already registered” error.


 


What is the fix ?


We’ll have to make sure that the Email save process is called only when its corresponding hook is called and should do nothing when other hooks are executed. That is when you click on submit from the form in the footer, the save process should be called only in hookFooter and not during executing of other hooks.


 


I have implemented the fix here : blocknewsletter.zip


 


Once again, I am sorry for my carelessness.


 


Note : If your theme overrides blocknewsletter module then make sure you copy the blocknewsletter.tpl file to themes/<theme-name>/modules/blocknewsletter/


Please let me know if you have any problems.


Edited by ibndawood (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 5 months later...

Hi!

 I know that subject is solved. But I've spent several days with that problem in my template build and tested on PS v.1.5.6.2 and BlockNewsletter v.1.4.
 
 After long time search and tries, ibndawwod pointed a good aproach but doesn't solved it in my case. The problem is certainly that the module is read more than once. I make the call with the smarty method:
 

 {hook h='displayLeftColumn' mod='blocknewsletter'}

Finally I solved with 2 minor changes, both in function _prepareHook in blocknewsletter.php:

Original file:
 

private function _prepareHook($params)
{
	if (Tools::isSubmit('submitNewsletter'))
	{
		$this->newsletterRegistration();
		if ($this->error)
		{
			$this->smarty->assign(array('color' => 'red',
				'msg' => $this->error,
				'nw_value' => isset($_POST['email']) ? pSQL($_POST['email']) : false,
				'nw_error' => true,
				'action' => $_POST['action'])
			);
		}
		else if ($this->valid)
		{
			$this->smarty->assign(array('color' => 'green',
				'msg' => $this->valid,
				'nw_error' => false)
			);
		}
	}
	$this->smarty->assign('this_path', $this->_path);
}

I've changed the way to asign values to $this->context->smarty->assign and then, for checking if the user has been registered just now, I look if msg value has been setted. That's my final code:

 

private function _prepareHook($params)
{
        $variable = $this->context->smarty->getTemplateVars('msg'); 
        if (Tools::isSubmit('submitNewsletter') && !isset($variable))
	{
		$this->newsletterRegistration();
		if ($this->error)
		{
			$this->context->smarty->assign(array('color' => 'red',
				'msg' => $this->error,
				'nw_value' => isset($_POST['email']) ? pSQL($_POST['email']) : false,
				'nw_error' => true,
				'action' => $_POST['action'])
			);
		}
		else if ($this->valid)
		{
			$this->context->smarty->assign(array('color' => 'green',
				'msg' => $this->valid,
				'nw_error' => false)
			);
		}
	}
	$this->context->smarty->assign('this_path', $this->_path);
}

 If I've done something really wrong, I'll be glad if one of the experts can tell it. 
 Otherwise I hope this helps to others.

Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...