Thursday, April 8, 2010

Adding a sidebar login box

Problem:
How to add a login box on sidebar.
More details here http://www.magentocommerce.com/boards/viewthread/178324/

Possible solution:
First create a phtml file. Let's call it mini.login.phtml.
Place it in app\design\frontend\{interface}\{theme}\template\customer\form\mini.login.phtml
Make sure the form has the same action as in login.phtml Also give the inputs the same name as they have in login.phtml.

Edit app\design\frontend\{interface}\{theme}\layout\customer.xml
under the tag <customer_logged_out> put the following
<reference name="left">
<block type="customer/form_login" name="customer_mini_login" before="-" template="customer/form/mini.login.phtml"/>
</reference>
Clear the cache and refresh.
This will put the mini.login at the top of your left column.If you want it lower play with the 'before' attribute. (You can even replace it with after)
See more details here. http://www.magentocommerce.com/design_guide/articles/intro-to-layouts

The side effect of this is that all the pages that contain this block will have the meta-tille 'Customer Login'. (at least for version 1.4.0.1)
To avoid this you have 2 options.
The 'quick and dirty' one.
Edit app\code\core\Mage\Customer\Block\Form\Login.php and in method _prepareLayout() remove this line:
$this->getLayout()->getBlock('head')->setTitle(Mage::helper('customer')->__('Customer Login'));
or remove the method completely (same effect).
This will work but the problem will reappear after an upgrade.
The 'by the book' option.
Overwrite the Mage_Customer_Block_Form_Login block. See tutorial here:
[http://magedev.com/2009/06/03/magento-overriding-model-block-or-helper/
After that in the the class that extends Mage_Customer_Block_Form_Login create the method _prepareLayout() that does nothing. Just returns the current object.
protected function _prepareLayout()
{
return $this;
}

3 comments:

  1. it work's thank you !

    ReplyDelete
  2. thanks - great tutorial. but after overriding the default login-page isn't working anymore. any solution?

    ReplyDelete
    Replies
    1. What Magento version are you using? I wrote this a long time ago for version 1.3 or 1.4 (not really sure). I will try it (and fix it if necessary) on 1.7 and update the post if it works.

      Delete