Customer Group Registration
A feature that is absent from the Magento frontend is the ability for a customer to choose which customer group they belong to during registration, no different to what is available to the admin when they choose to register new customers. This can be quite important in instances where you wish to apply different tax rules to different types of customer. For example you might have General Customers and VAT Exempt customers.
To enable this ability is actually extremely simple. Firstly, XML.
Make a LOCAL copy of config.xml from app > code > core > Mage > Customer > etc > config.xml and add the following line of code into the customer account fieldset:
<fieldsets>
<customer_account>
<prefix><create>1</create><update>1</update><name>1</name></prefix>
<firstname><create>1</create><update>1</update><name>1</name></firstname>
<middlename><create>1</create><update>1</update><name>1</name></middlename>
<lastname><create>1</create><update>1</update><name>1</name></lastname>
<suffix><create>1</create><update>1</update><name>1</name></suffix>
<email><create>1</create><update>1</update></email>
<group_id><create>1</create><update>1</update></group_id>
<password><create>1</create></password>
<confirmation><create>1</create></confirmation>
<dob><create>1</create><update>1</update></dob>
<taxvat><create>1</create><update>1</update></taxvat>
</customer_account>
</fieldsets>
Now you need to add code to the frontend of the store, in the registration form. Open template/customer/form/register.phtml and add the following code somewhere in the form:
<div class="input-box">
<label for="group_id"><?php echo $this->__('Group') ?><span class="required">*</span></label><br/>
<select name="group_id" id="group_id" title="<?php echo $this->__('Group') ?>" class="validate-group required-entry input-text" />
<?php $groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>
<?php foreach($groups as $group){ ?>
<option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>
<?php } ?>
</select>
</div>
That’s all there is to it – customers can now choose which group they belong to during sign up.

Ello,
Im using ver. 1.3.2.4 and I cannot locate a config.xml in the layout folder, is there another xml that I can place this onto? The 2nd part of your post I can get to show, but it doesn’t submit with the customer sign up form, and I’m assuming it may have to be something with the xml (although im not sure why you have all “1″ on the values, i possible could you explain a little more?)
actually i was able to get this to work correctly, instead of looking for a config.xml in teh layouts, i added it to app\code\code\Mage\Customer\etc\config.xml
under line 96, just an fyi for anyone else, btw thanks for the info
CodeSoda, thanks for your correction. I have updated the post with the correct file location.
Hi
Thank you for this, it’s really easy to do.
Have you an idea how to add the group when you are on “one page checkout”?
It’s easy to display the select with differents groups, but the data isn’t registred
i tried to add 11 in app/code/core/Mage/Checkout/etc/config.xml but didn’t work
This was really helpful but I also need to add it to the one page checkout and I can’t get it to work. Like Thomas I can add the dropdown without a problem but I can’t get it to save the data. Did anyone have any luck with this?
I followed every step and can’t get it to work. Everything works except when I go in the backend and manage customers it looks like the customers are in placed in the general customer group? Can someone help?
Hi guys,
I fixed the problem. It seems that in Magento 1.4.x the code changed so this doesn’t work as stated above anymore. You also need to add something in AccountController.php.
This is what you do;
1. Copy app/code/core/Mage/Customer/controllers/AccountController.php to app/code/local/Mage/Customer/controllers/AccountController.php to preserve changes done throughout upgrades
2. Open app/code/local/Mage/Customer/controllers/AccountController.php and go to line 267. This line reads; “$customer->setData($code, $data[$code]);”
3. Change this line into:
if($code==’group_id’) {
$customer->setGroupId($data['group_id']);
} else {
$customer->setData($code, $data[$code]);
}
Save the file and enjoy! I will look into the onepage problem as well in a day or so.
Ok, after a few hours of trying several things (I think I created over a hundred accounts in the process), I finally figured out how to implement the customer group select option in the Onepage Checkout.
I take it you already know how to add the field itself to the form; the problem was that it just wasn’t registered. This is how I did it (M1.4.1.1 installation).
1. Copy app/code/core/Mage/Checkout/Model/Type/Onepage.php to app/code/local/Mage/Checkout/Model/Type/Onepage.php to preserve the modifications throughout future upgrades.
2. In the function saveBilling, right at the start, add;
$this->getQuote()->setCustomerGroupId($data[’group_id’]);
This is because we need to transfer the variable $data[’group_id’] to another function and this is one of the easiest ways to do that.
3. In the function _prepareNewCustomerQuote, at the end, it says;
$quote->setCustomer($customer)
->setCustomerId(true);
Right before this, add;
$customer->setGroupId($quote->getData(’customer_group_id’));
Et voila! The customer group gets stored in the database!
Hello, your line:
$customer->setGroupId($quote->getData(’customer_group_id’));
doesn’t work. You must retrieve the group_id selected in billing in an appropiate way, and not with $quote->getData(’customer_group_id’), but How?? I dont know…please try something
I would suggest NOT doing what the poster of this article suggests. You should never overwrite core files, which he has you doing with the Customer core module, editing it’s config.xml.
If you want to do it properly, write your own simple module and add the xml changes to your own config.xml file. You can then use your own layout xml file and your own template file and keep everything a little separated, should you ever want to remove this functionality.
Not everyone will know how to write modules, my solution works fine as long as you create config.xml in the local folder.
Writing modules is amazingly easy, especially when all you need is a config.xml. Why not rewrite your post so that you teach people how to do it properly instead? All you will need is 1 extra file in the etc/modules/ directory
I’m just a proponent of doing things properly. I am not keen at all with even utilizing the app/code/local/Mage/ overrides. It works, but it is dirty, and there’s no way to disable the changes.
I agree that modules are a much better practice. For something as simple as this though, many developers prefer a quick fix. I prefer to think I’m just giving people the code, it’s up to them how they utilize it.
Hello
Congratulations on the tutorial, worked perfectly with me.
As we only work with two groups (individual and company) I want to know how overwritten the “select” with “2 radiobuttons.”
graciously.
I did this and it worked kind of. when registering it gave me a drop down box with the groups. I clicked wholesale but when you go to customer info it shows it as signing up as general and no wholesale prices show up. Also, for wholesale accounts i would like them to give business info and sales tax id, and have an approval process. do you know how i can do that?
thanks!
Great it works for me thank you so much.
Easy Peasy – Now Iv got a question for you, I have two store views one with tiered pricing that is only viewable to one customer group, is there a way to redirect customer groups to there appropriate store views on log in?
Please help how to add
” if($code==’group_id’) {
$customer->setGroupId($data['group_id']);
} else {
$customer->setData($code, $data[$code]);
}”
This code in magento 1.4.2..please help me where to add this code
Try this code……It works…..
if($this->getRequest()->getPost(‘group_id’))
{
$customer->setGroupId($this->getRequest()->getPost(‘group_id’));
}
else
{
$customer->getGroupId();
}
/*Add this code in AccountController.php of app/code/core/Mage/Customer/controllers/*/