Your shopping cart is empty. Browse our Store

Magento

Open Source eCommerce Evolved

Magento Forum

   
Overloading controller problem
 
Bojan Hrnkas
Jr. Member
 
Total Posts:  9
Joined:  2008-04-16
 

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
Magento Community
Magento Community
    Back to top
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International) to request a call-back.
© Copyright 2008 Varien. Magento is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
32156 users|362 users currently online|72054 forum posts