Magento Forum

Overloading controller problem
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

I tried overloading Customer/controllers/AccountController.php as explained in the wiki, but my overrided function (editPostAction) is not being called.

Can someone tell me what am I missing?

Here are the files I saved in apropriate folders:

/app/code/local/Ff/Vat/etc/config.xml

<?xml version="1.0" encoding="windows-1250"?>
<config>
    <
modules>
        <
Ff_Vat>
            <
version>0.1.0</version>
        </
Ff_Vat>
    </
modules>
    <global>
        <!-- 
This rewrite rule could be added to the database instead -->
        <
rewrite>
            <!-- 
This is an identifier for your rewrite that should be unique -->
            <
Ff_Vat_customer_account>
                <
from><![CDATA[#^/customer/account/$#]]></from>
                
<!--
                    - 
mymodule matches the router frontname below
                    
checkout_cart matches the path to your controller
                   
                    Considering the router below
"/mymodule/checkout_cart/" will be
                    
"translated" to "/MyNameSpace/MyModule/controllers/Checkout/Cart.php" (?)
                -->
                <
to>/vat/customer_account/</to>
            </
Ff_Vat_customer_account>
        </
rewrite>
    </global>
    <!--
    If 
you want to overload an admin-controller this tag should be <admininstead,
    or <
adminhtml> if youre overloading such stuff (?)
    -->
    <
frontend>
        <
routers>
            <
Ff_Vat>
                <!-- 
should be set to "admin" when overloading admin stuff (?) -->
                <use>
standard</use>
                <
args>
                    <
module>Ff_Vat</module>
                    <!-- 
This is used when "catching" the rewrite above -->
                    <
frontName>vat</frontName>
                </
args>
            </
Ff_Vat>
        </
routers>
    </
frontend>
</
config>

app/code/local/Ff/Vat/controllers/Customer/AccountController.php

<?php
  
require_once 'Mage/Customer/controllers/AccountController.php';
  
  class 
Ff_Vat_Customer_AccountController extends Mage_Customer_AccountController
  {
    
//overloading editPost action
    
public function editPostAction()
    
{
        
if ($this->getRequest()->isPost()) {
            $customer 
Mage::getModel('customer/customer')
                ->
setId($this->_getSession()->getCustomerId())
                ->
setWebsiteId($this->_getSession()->getCustomer()->getWebsiteId())
                ->
setData('firstname'$this->getRequest()->getParam('firstname'))
                ->
setData('lastname'$this->getRequest()->getParam('lastname'))
                ->
setData('email'$this->getRequest()->getParam('email'))
                ->
setData('vat'$this->getRequest()->getParam('vat'));
                
            
$this->_getSession()->addSuccess('Yes, I did it!');

            
$errors $customer->validate();
            if (!
is_array($errors)) {
                $errors 
= array();
            
}

            
/**
             * we would like to preserver the existing group id
             */
            
if ($this->_getSession()->getCustomerGroupId()) {
                $customer
->setGroupId($this->_getSession()->getCustomerGroupId());
            
}

            
if ($this->getRequest()->getParam('change_password')) {
                $currPass 
$this->getRequest()->getPost('current_password');
                
$newPass  $this->getRequest()->getPost('password');
                
$confPass  $this->getRequest()->getPost('confirmation');

                if (empty(
$currPass) || empty($newPass) || empty($confPass)) {
                    $errors[] 
$this->__('Pasword fields can\'t be empty.');
                }

                if ($newPass != $confPass) {
                    $errors[] = $this->__('
Please make sure your passwords match.');
                }

                $oldPass = $this->_getSession()->getCustomer()->getPasswordHash();
                if (strpos($oldPass, '
:')) {
                    list($_salt, $salt) = explode('
:', $oldPass);
                } else {
                    $salt = false;
                }

                if ($customer->hashPassword($currPass, $salt) == $oldPass) {
                    $customer->setPassword($newPass);
                } else {
                    $errors[] = $this->__('
Invalid current password');
                }
            }

            if (!empty($errors)) {
                $this->_getSession()->setCustomerFormData($this->getRequest()->getPost());
                foreach ($errors as $message) {
                    $this->_getSession()->addError($message);
                }
                $this->_redirect('
*/*/edit');
                return $this;
            }


            try {
                $customer->save();
                $this->_getSession()->setCustomer($customer)
                    ->addSuccess($this->__('Account information was successfully saved'));

                $this->_redirect('customer/account');
                return;
            }
            catch (Mage_Core_Exception $e) {
                $this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
                    ->addError($e->getMessage());
            }
            catch (Exception $e) {
                $this->_getSession()->setCustomerFormData($this->getRequest()->getPost())
                    ->addException($e, $this->__('Can\'t save customer'));
            }
        }
        $this->_redirect('*/
*/edit');
    }

  }

/app/etc/modules/Ff_All.xml

<?xml version="1.0"?>
<config>
    <
modules>
        <
Ff_Vat>
            <
active>true</active>
            <
codePool>local</codePool>
        </
Ff_Vat>
    </
modules>
</
config>

And I also added this to layout/customer.xml

<vat_customer_account_editPost>
        <
update handle="customer_account_editPost"/>
    </
vat_customer_account_editPost>

Any ideas?

Thanks!

Bojan Hrnkas

 
Magento Community Magento Community
Magento Community
Magento Community
 
nicolas46
Sr. Member
 
Total Posts:  210
Joined:  2008-04-09
Toulouse
 

Did you solve your problem ? if yes can you write what you have done please

 
Magento Community Magento Community
Magento Community
Magento Community
 
Heikki
Jr. Member
 
Total Posts:  8
Joined:  2009-01-29
 

Hello there, the same case unsolved here ...  Magento ver 1.21 ... Getting error msg “401 Page not found...”

Is there any error logs so I can find what do I do wrong…

Tring to be nice and not mess with the original core ‘ Mage/Customer/controllers/AccountController.php ‘ file…

So please HELP !

 
Magento Community Magento Community
Magento Community
Magento Community
 
subesh
Sr. Member
 
Avatar
Total Posts:  145
Joined:  2009-01-08
 

<Ff_Vat_customer_account>
                <
from><![CDATA[#^/customer/account/editPost/$#]]></from>
                
<to>/vat/customer_account/editPost</to>
</
Ff_Vat_customer_account>

Try this.......... this may work....

 
Magento Community Magento Community
Magento Community
Magento Community
 
MI
Sr. Member
 
Total Posts:  172
Joined:  2008-12-11
Spain
 

I have the same problem.

How do you resolve it?

Thanks!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Heikki
Jr. Member
 
Total Posts:  8
Joined:  2009-01-29
 

I copied entire module to local pool ... changed the module settings in app/etc/modules/ ... and chenged stuff in controller .php files ...

Too bad magento doesn’t have even better error reporting which would make the community “mad"…

 
Magento Community Magento Community
Magento Community
Magento Community
 
SwiftCol
Sr. Member
 
Total Posts:  85
Joined:  2008-05-22
 

Can you give specific file and code details on how you did that?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top