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?

Alan
  • 927
  • 1
  • 18
  • 33

4 Answers4

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

Namita sheth
  • 164
  • 4
  • This doesn't work either. – Alan Sep 08 '14 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. – Namita sheth Sep 09 '14 at 04: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 09 '14 at 05: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 – Namita sheth Sep 09 '14 at 07:19
  • 1
    If you want to add the profile image for the customer you can also try following free extension. link – Namita sheth Sep 09 '14 at 07:30
  • Thanks for the extension link! I will definitely check it out. I will double check for spelling mistakes but I've already did this before and found none. – Alan Sep 09 '14 at 07:51
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>
Paras Sood
  • 2,540
  • 1
  • 14
  • 23
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/

Anisha Shaikh
  • 429
  • 2
  • 5
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).

Fabian Schmengler
  • 65,791
  • 25
  • 187
  • 421