search
top

Customer Groups in Magento

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

4 Responses to “Customer Groups in Magento”

  1. ElenaMBelda says:

    Hi all, is there a way to use this inside a payment module on the backend? Thanks a lot

  2. Miguel says:

    Hi,

    Good post. I buy use this select box to register form.

    Its’s posible?

    Thanks, greats!

    • Pragnesh says:

      @Miguel – Yes you can display the select box of customer groups in any view file

      Buy using this code

      <?php
       
          $custmer_helper = new Decryptweb_Customer_Helper_Data;
       
          $select_box = $custmer_helper->getGroupsHtml(); //get customers group
       
          echo $select_box;
       
      ?>   
      

Leave a Reply

top