Add image field to customer groups in Magento

So i have made a few Magento stores for people/clients now that use the customer groups fairly often, and with a few modifications here and there. Today i am going to show how to have an image upload field in the customer groups and then display it on your website for the user of that group. It is very handy when you want to do branding for certain high profile customers in Magento.

So first we need to add the field to the database.
I myself use phpMyAdmin. so if you have a cPanel hosting account you should have this. If not maybe ask your hosting provider how you can access your databases to make modifications.
When in phpMyAdmin or your program of choice find you magento database and go to edit the customer_group table. You want to add a new column at the end of the table.
lets name it customer_group_image and give it a type of text.

now with that in place we need to edit the magento files to actually put values into that column.
so ftp into where your magento files are and find this /app/code/core/Mage/Adminhtml/Block/Customer/Group/Edit/Form.php
and i highly suggest you copy it over to your code/local folder as it is bad practice to edit your core files:

open the file and start editing…

look for this line of code:

and just before it lets add this code:

this will add the field. but now that our form will handle image uploading we need to actually change the form a bit. At the beginning of this file you will find this line of code:

change that line to be like this:

save the file.
If you go into your magento admin panel now and go edit a customer group you will see the new image field. but it wont do anything yet. so lets add some code to make it actually upload the image.

find this file to edit:

again it is bad practice to edit core files but for a controller modification you will need to make your own module. Here i am just going to edit the core file and i will show you how to make your own module in a future post. So if you do the same and edit the core file remember it as if up upgrade your magento you may have to do it again.

so under the saveAction function we need to find this code

and add under that this code:

this will upload the images to your magento folder into /media/group_images_folder/
and the last bit of code will check to see if the delete image checkbox it ticked and if so remove the image from the group.

now look for some code like this:

and just above that add this:

this will save the image file name to the database.

save the file with the new changes and give it a try in your magento admin ( remember to clear your cache first )

With all that done all we need to do is be able to display that image in the front end. Which is very simple and can be done with this code. just put this code in any of your template files you want that image displayed in….

If you have any problems or improvements please post them in the comments area.
This was done for Magento 1.7.2 but should work on earlier versions.