Monday 29 August 2016

Magento : Add ‘Customer Group’ to Registration Form.

Step -1

app/desing/frontend/themepackage/yourtheme/template/customer/form/register.phtml

Add felow start form

<div>
<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>

Step-2

app/code/core/Mage/Customer/controllers/AccountController.php

Go to line no 294 or find $customer = $this->_getCustomer(); add code felow this line

$customer->setGroupId($this->getRequest()->getPost(‘group_id’));

OR

if ($this->getRequest()->getParam('group_id', false)) {      
    $customer->setGroupId($this->getRequest()->getParam('group_id', false)); 
}

This code for if user not select customer group so form send automatic select default value


Step-3

app/code/core/Mage/Customer/etc/config.xml

Find customer_account and Add customer_account node

<group_id><create>1</create><update>1</update></group_id>


Done! :)

No comments:

Post a Comment