Доброго времени суток!
Magento начал использовать не так давно, потому застопорился на наверное не сильно сложном вопросом для бывалых, однако ответ на него найти не могу нигде, потому прошу о помощи.
Суть задания - необходимо переопределить один из методов контроллера Core/Mage/Customer/controllers/AccountController.php и добавить новый метод. Так как редактировать данный контроллер является неправильно - его необходимо переопределить. Согласно требований проекта переопределенный контроллер должен находиться по адресу local/New/Mage/Customer/controllers/AccountController.php Для этого создал файлы конфигов, но адреса customer/account/test, customer/account/ajax не отзываются, и customer/account/login не переопределяется. Прошу помощи в данной реализации.
Коды:
app/app/etc/modules/New_Mage_Customer.xml
<?xml version="1.0"?> <config> <modules> <New_Mage_Customer> <active>true</active> <codePool>local</codePool> </New_Mage_Customer> </modules> </config>
app/code/local/New/Mage/Customer/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<New_Mage_Customer>
<version>0.0.1</version>
</New_Mage_Customer>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<new_customer before="Mage_Customer">New_Mage_Customer</new_customer>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>app/code/local/New/Mage/Customer/controllers/AccountController.php
<?php
/**
* Customer account controller
*/
require_once 'Mage/Customer/controllers/AccountController.php';
class New_Mage_Customer_AccountController extends Mage_Customer_AccountController {
public function ajaxAction() {
echo 'ajax!!';
}
public function testAction() {
echo 'test222';
}
public function loginAction() {
echo 'index';
}
}
Solved! Go to Solution.
Попробуйте уменьшить вложенность папок своего модуля, должно помочь.
Т.е. как то так:
app/code/local/PavelMorgun/Customer/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<PavelMorgun_Customer>
<version>0.1.0</version>
</PavelMorgun_Customer>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<pm_customer before="Mage_Customer">PavelMorgun_Customer</pm_customer>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>app/app/etc/modules/PavelMorgun_Customer.xml:
<?xml version="1.0"?>
<config>
<modules>
<PavelMorgun_Customer>
<active>true</active>
<codePool>local</codePool>
</PavelMorgun_Customer>
</modules>
</config>app/code/local/PavelMorgun/Customer/controllers/AccountController.php
<?php
require_once(Mage::getModuleDir('controllers','Mage_Customer').DS.'AccountController.php');
class PavelMorgun_Customer_AccountController extends Mage_Customer_AccountController
{
/**
* Customer login form page
*/
public function loginAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$this->getResponse()->setHeader('Login-Required', 'true');
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->renderLayout();
}
}
Так и сделал. Спасибо. Работает.
Просто думал может не хватает способностей реализовать данную процедуру с таким количеством вложений
Попробуйте уменьшить вложенность папок своего модуля, должно помочь.
Т.е. как то так:
app/code/local/PavelMorgun/Customer/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<PavelMorgun_Customer>
<version>0.1.0</version>
</PavelMorgun_Customer>
</modules>
<frontend>
<routers>
<customer>
<args>
<modules>
<pm_customer before="Mage_Customer">PavelMorgun_Customer</pm_customer>
</modules>
</args>
</customer>
</routers>
</frontend>
</config>app/app/etc/modules/PavelMorgun_Customer.xml:
<?xml version="1.0"?>
<config>
<modules>
<PavelMorgun_Customer>
<active>true</active>
<codePool>local</codePool>
</PavelMorgun_Customer>
</modules>
</config>app/code/local/PavelMorgun/Customer/controllers/AccountController.php
<?php
require_once(Mage::getModuleDir('controllers','Mage_Customer').DS.'AccountController.php');
class PavelMorgun_Customer_AccountController extends Mage_Customer_AccountController
{
/**
* Customer login form page
*/
public function loginAction()
{
if ($this->_getSession()->isLoggedIn()) {
$this->_redirect('*/*/');
return;
}
$this->getResponse()->setHeader('Login-Required', 'true');
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->renderLayout();
}
}