How to Extend/Override Admin Controller for Login in Magento

adminhtmlcontrollers

I would like to set the admin to be a different locale to the locale of the base shop. For this I need to add a 'setLocale' line into the admin index controller loginAction. This works great if I edit the core file or copy that over to local. However I would prefer to do this the proper Magento way.

I have a small module:

app/code/local/Woolfie/AdminExtras/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Woolfie_AdminExtras>
            <version>0.1.0</version>
        </Woolfie_AdminExtras>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Woolfie_AdminExtras before="Mage_Adminhtml">Woolfie_AdminExtras</Woolfie_AdminExtras>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

With a file:

app/code/local/Woolfie/AdminExtras/controllers/Adminhtml/IndexController.php

This simply contains:

<?php
require_once "Mage/Adminhtml/controllers/IndexController.php";
class Woolfie_AdminExtras_Adminhtml_IndexController extends Mage_Adminhtml_IndexController{

  public function loginAction()
  {
    if (Mage::getSingleton('admin/session')->isLoggedIn()) {
        $this->_redirect('*');
        return;
    }
    Mage::getSingleton('adminhtml/session')->setLocale('en_GB');
    $loginData = $this->getRequest()->getParam('login');
    $username = (is_array($loginData) && array_key_exists('username', $loginData)) ? $loginData['username'] : null;

    $this->loadLayout();
    $this->renderLayout();
  }


}

I have no idea why this won't run, however, it should change the admin login screen to always be English (en_GB).
Any ideas or alternatives to this problem (other than changing my admin store locale which I cannot do).

Best Answer

Change this:

<modules>
    <Woolfie_AdminExtras before="Mage_Adminhtml">Woolfie_AdminExtras</Woolfie_AdminExtras>
</modules>

to this:

<modules>
    <Woolfie_AdminExtras before="Mage_Adminhtml">Woolfie_AdminExtras_Adminhtml</Woolfie_AdminExtras>
</modules>

but there is an easier way to do this. No coding involved.
Go to system->configuration->General->Locale Options and set the en_GB locale.

Save it and then select you website or store view from the top left store selector and change the same field to what locale you need.

Related Topic