Jump to content

User account block with log in functionality


Recommended Posts

Hi all,

 

By default the User Account block only displays when a user is logged in. I wanted to adapt it so that if a user isn't logged in it will display a login form. I managed to get this working by modifying the myaccount block but I'm not sure if I approached it in the right way and would welcome any advice.

 

Firstly I edited modules/blockmyaccount/blockmyaccount.php:

 

Changing:

 

public function hookLeftColumn($params)
{
 global $smarty;

 if (!$params['cookie']->isLogged())
  return false;
 $smarty->assign(array(
  'voucherAllowed' => (int)(Configuration::get('PS_VOUCHERS')),
  'returnAllowed' => (int)(Configuration::get('PS_ORDER_RETURN')),
  'HOOK_BLOCK_MY_ACCOUNT' => Module::hookExec('myAccountBlock')
 ));
 return $this->display(__FILE__, $this->name.'.tpl');
}

 

to

 

public function hookLeftColumn($params)
{
 global $smarty;

 if (!$params['cookie']->isLogged())
  return $this->display(__FILE__, $this->name.'2.tpl');
 $smarty->assign(array(
  'voucherAllowed' => (int)(Configuration::get('PS_VOUCHERS')),
  'returnAllowed' => (int)(Configuration::get('PS_ORDER_RETURN')),
  'HOOK_BLOCK_MY_ACCOUNT_LOGIN' => Module::hookExec('myAccountLoginBlock')
 ));
 return $this->display(__FILE__, $this->name.'.tpl');
}

 

Then I created a copy of blockmyaccount.tpl and called it blockmyaccount2.tpl and replaced the contents with the form from authentication.php

 

<div class="block myaccount">
<h4>Account Holders</h4>
<div class="block_content">
 <form action="authentication.php" method="post" id="login_form" class="std">
  <p class="text">
<label for="email">E-mail address</label>
<span><input type="text" id="email" name="email" value="" class="account_input" /></span>
  </p>
  <p class="text">
<label for="passwd">Password</label>
<span><input type="password" id="passwd" name="passwd" value="" class="account_input" /></span>
  </p>
  <p class="submit">
<input type="submit" id="SubmitLogin" name="SubmitLogin" class="button" value="Log in" />
  </p>
  <p class="lost_password"><a href="password.php">Forgot your password?</a></p>
		<p class="registerforaccount"><a href="authentication.php"><strong>Register Here</strong></a></p>
</form>
</div>
</div>

 

I have since edited more of the php file and config file to make it a completely separate module from blockmyaccount so that my changes aren't overwritten if I update Prestashop.

 

It all seemed a little too easy, surely there's something I've done wrong?

 

Many thanks

Link to comment
Share on other sites

  • 2 weeks later...

Hello, I have proved the modifications that lordmark200 wrote.

 

Apparently it works correctly, but not shows correctly. I have attache 2 pictures to show it.

 

First pictures shows when I click on "Enter" in the top-right of Prestashop.

 

Second pictures shows when I´m in the index.php of Prestashop.

 

Do you know what could be the solution ?

 

Thanks in advance

Regards

post-266141-0-99370100-1324574546_thumb.jpg

post-266141-0-19932200-1324574565_thumb.jpg

Link to comment
Share on other sites

  • 3 weeks 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...