Hello All,
I am writing here a script for displaying a select box of customers group.
There exists a Helper file for Customer at app/code/core/Mage/Customer/Helper/Data.php .
We need to extend this class for using the default function
Create a sample module inside local
I have used the Namespace ‘Decryptweb’ for my custom module.
For custom module you need to add a file in etc/modules/Decryptweb_Customer.xml
The content will be
<?xml version="1.0"?> <config> <modules> <Decryptweb_Customer> <active>true</active> <codePool>local</codePool> </Decryptweb_Customer> </modules> </config>
So your helper will be app/local/Decryptweb/Customer/Helper/Data.php
Paste this content inside it
<?php class Decryptweb_Customer_Helper_Data extends Mage_Customer_Helper_Data { public function getGroupsHtml() { $opt = array('value' => '','label' => 'Please Select Group'); $options = $this->getGroups()->toOptionArray(); if(!empty($options)) { array_unshift($options,$opt); $select_options = $options; }else { $select_options = $opt; } $select = Mage::app()->getLayout()->createBlock('core/html_select') ->setName('group_id') ->setId('group_id') ->setOptions($select_options) ->setClass('validate-select'); return $select->getHtml(); } } ?>
Now for displaying the select box in any view file
use the below script
<?php $custmer_helper = new Decryptweb_Customer_Helper_Data; $select_box = $custmer_helper->getGroupsHtml(); //get customers group echo $select_box; ?>
For knowledge of select box you can check this post Select Box In Magento
Hope its helpful
Hi all, is there a way to use this inside a payment module on the backend? Thanks a lot
@ElenaMBelda – Do you want it to show in Payment Methods in Configuration menu ?
Hi,
Good post. I buy use this select box to register form.
Its’s posible?
Thanks, greats!
@Miguel – Yes you can display the select box of customer groups in any view file
Buy using this code