Tuesday, January 10, 2012

How to show customer group selecter in registration form

Make a 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 and save it to app > code >local>config.xml and in this file add the following line of code into the customer account fieldset:



<fieldsets>
<customer_account>
............
<group_id><create>1</create><update>1</update></group_id>
...........
</customer_account>
</fieldsets>


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>


also change some code in app\code\core\Mage\Customer\controllers\AccountController.php now
replace $customer->getGroupId();
with

 if($this->getRequest()->getPost('group_id'))
 { $customer->setGroupId($this->getRequest()->getPost('group_id'));
 } else {
$customer->getGroupId(); }


Enjoy!!!



6 comments:

  1. This is not working in magento 1.8. Customer group not saved in db. Urgent please help me.

    ReplyDelete
  2. It's working well with magento 1.9.. But how save data if group is changed in account page? Thank you

    ReplyDelete
  3. Thanks for the post. I used to have such a selector on a registration page but now I need a customer to choose his occupation, add company name and number of employees also, so I decided to use an extension to avoid too much coding I’m not good at. As a solution, I used customer attributes by amasty.

    ReplyDelete
  4. You can simply observe the event: customer_save_before. With this extension you have have customer group selector even at checkout page:
    http://www.magepsycho.com/customer-group-selector-switcher.html

    ReplyDelete
  5. It is complicated to me now, but in typical, the efficiency and significance is annoying. Very much thanks again and best of luck!Thanks for sharing. Magento Development Companies in Bangalore

    ReplyDelete
  6. I am trying to implement it in magento 1.9 and its not working

    ReplyDelete