1

I need to override a controller (../Mage/Customer/controllers/AccountController.php) in order to enable user to upload a photo from "Account Information" form. I've manually created "photo" file upload field and added "enctype=multipart/form-data" to form .phtml file.

Now I need to handle submisison so that the actual file is saved on the server and path is saved into my database.

When I put Varien_File_Uploader code into original AccountController.php the file is saved on the server. I don't want to modify core files so I've created my own module with "etc/config.xml" and "controllers/AccountController.php".

etc/config.xml

<?xml version="1.0"?>
<config>
<modules>
    <Abcdef_Photoupload>
        <version>0.1.0</version>
    </Abcdef_Photoupload>
</modules>

<frontend>
    <routers>
        <customer>
            <args>
                <modules>
                    <Abcdef_Photoupload before="Mage_Customer_AccountController">
                        Abcdef_Photoupload_Frontend_Customer
                    </Abcdef_Photoupload>
                </modules>
            </args>
        </customer>
    </routers>
</frontend>

</config>

for now, in my controllers/AccountController.php I've put

<?php
echo "test";
exit;

require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';

 class Abcdef_Photoupload_Frontend_Customer_AccountController extends Mage_Customer_AccountController
 {[my code]}

neither "echo", nor [my code] get executed. Module is enabled and visible in back-end. How do I get my customized controller to work?

2
  • you need put exit function on a function
    – Amit Bera
    Sep 8, 2014 at 8:12
  • Please take your time to accept an answer if it helped you so that the question does not count as unanswered anymore Dec 18, 2015 at 14:37

4 Answers 4

2

Please try replacing following code in your config.xml

<routers>
        <customer>
           <use>standard</use>
            <args>
                <modules>
                    <Abcdef_Photoupload before="Mage_Customer">                                         
                             Abcdef_Photoupload
                    </Abcdef_Photoupload>
                </modules>
            </args>
        </customer>
    </routers>

and in the /controllers/AccountController.php file change the class name from

class Abcdef_Photoupload_Frontend_Customer_AccountController extends Mage_Customer_AccountController

To

class Abcdef_Photoupload_AccountController extends Mage_Customer_AccountController

both following extension could also help for customer profile image: http://www.magentocommerce.com/magento-connect/upload-profile-image.html http://www.magentocommerce.com/magento-connect/avatar.html

6
  • This doesn't work either.
    – Alan
    Sep 8, 2014 at 13:52
  • Please clear the cache and then check and have you added exit in the function not on the file as commented by Amit. can you please specify the magento version. Sep 9, 2014 at 4:37
  • Hi Namita. I've cleared the cache and added exit in the function and outside of it, no success. The magento version is 1.8.1.
    – Alan
    Sep 9, 2014 at 5:38
  • please check for any spell mistake at with folder name or in file. OR any installed extension override same controller file, Because the above code did work for me on same magento version 1.8.1.0 Sep 9, 2014 at 7:19
  • 1
    If you want to add the profile image for the customer you can also try following free extension. link Sep 9, 2014 at 7:30
1
<modules>
                    <Abcdef_Photoupload before="Mage_Customer_AccountController">
                        Abcdef_Photoupload_Frontend_Customer
                    </Abcdef_Photoupload>
                </modules>

Should be:

<module>
                    <Abcdef_Photoupload before="Mage_Customer_AccountController">
                        Abcdef_Photoupload_Frontend_Customer
                    </Abcdef_Photoupload>
                </module>
1
  • Unfortulatly this doesn't help.
    – Alan
    Sep 8, 2014 at 9:03
1

Check you create this folder structure:

app/code/local/Abcdef/Photoupload/controllers/Frontend/Customer/AccountController.php

Please Refer this link to override Customer Account controller .

http://inchoo.net/dev-talk/how-to-extend-magento-core-controller/

1

The correct configuration is:

<routers>
    <customer>
       <use>standard</use>
        <args>
            <modules>
                <Abcdef_Photoupload before="Mage_Customer">Abcdef_Photoupload_Frontend_Customer</Abcdef_Photoupload>
            </modules>
        </args>
    </customer>
</routers>

Note that it's before=Mage_Customer, not before=Mage_Customer_AccountController. You don't override single controllers, but define - by class prefix - which controllers may handle a module, i.e. Mage_Customer, and in which order the actions are looked up (that's why you need the "before" definition, if you override existing actions in Mage_Customer_AccountController).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.