Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
Page 1 of 2
How to let customer choose customer group at registration? 
 
Jonas Lagneryd
Member
 
Total Posts:  61
Joined:  2008-09-01
 

Hi,

I wonder how to let the customer choose customer group at registration. In our case for instance we would like the customer to be able to choose student in order to get the student discounts.

Kind regards,
Jonas

 
Magento Community Magento Community
Magento Community
Magento Community
 
Yooplaboom
Jr. Member
 
Total Posts:  30
Joined:  2008-11-25
 

looking for the same thing smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
Chelramsey
Member
 
Total Posts:  33
Joined:  2008-12-01
 

Same here.

Please do not tell me I have to manually set each customer to a group.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tilzinger
Sr. Member
 
Total Posts:  118
Joined:  2007-12-27
 

I’m looking for the same thing. Anyone figure it out yet?

 
Magento Community Magento Community
Magento Community
Magento Community
 
xoail
Jr. Member
 
Total Posts:  12
Joined:  2009-01-02
 

So am I.... anybody have any idea how to go about registering a user under a group?

 
Magento Community Magento Community
Magento Community
Magento Community
 
flmag
Member
 
Total Posts:  49
Joined:  2008-12-08
 

You have to modify only 2 files for this customer/form/register.phtml and app/code/core/Mage/customer/etc/config.xml
(maybe form/edit.phtml if you want to allow the user to change his group after registering)

config.xml :
Add the group_id row

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

register.phtml

Add this code where you see fit 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>

The same code is valid for edit.phtml

And there you have it.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Spheric
Member
 
Total Posts:  69
Joined:  2008-10-15
 

I am using Magento version 1.2.1.1. By dropping this code into “/app/etc/modules” I am able to update the Customer Group during registration. (Actually, I added it to MyCompany_All.xml at the global level.)

<?xml version="1.0"?>
<config>
  <global>
    <
fieldsets>
      <
customer_account>
        <
group_id><create>1</create><update>1</update></group_id>
      </
customer_account>
    </
fieldsets>
  </global>
</
config>

That is all it took. I can now allow the user to select to be included in the Members Group by adding this checkbox to “app/design/frontend/default/my_default_theme/template/customer/form/register.phtml”:

<li>
   <
input type="checkbox" name="group_id" id="group_id" value="4" title="<?php echo $this->__('Membership') ?>" <?php if($this->getFormData()->getGoupId() == 4): ?>checked="checked"<?php endif ?> />
   <
label for="group_id"><?php echo $this->__('I wish to take advantage of Member Discount Pricing'?></label>
</
li>

This works just fine.

But, I would like to give the customer a second chance to join the Members Group if they didn’t selct it at registration.

Placing this code in “app/design/frontend/default/my_default_theme/template/customer/form/edit.phtml” under Edit Account Information does not work:

<li>
   <
input type="checkbox" name="group_id" id="group_id" value="4" title="<?php echo $this->__('Membership') ?>" <?php if($this->getCustomer()->getGroupId() == 4): ?>checked="checked"<?php endif ?> />
   <
label for="group_id"><?php echo $this->__('I wish to take advantage of Member Discount Pricing'?></label>
</
li>

I am able to read the group_id with getGroupId(), but the checkbox does not update the database.

I know that the two forms are different, register.phtml uses “/customer/account/createpost/” and edit.phtml uses “customer/account/editPost”. So, obviously I have more work to do to add this field to the form.

Does anyone know how to allow an existing customer to select the Customer Group from a checkbox once they have already created their account?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Spheric
Member
 
Total Posts:  69
Joined:  2008-10-15
 

Problem resolved.

The “editPostAction()” method in “app/code/core/Mage/Customer/controllers/AccountController.php” contains the following code which “hardwires” the group_id to its existing value whenever you edit account information from the customer account frontend:

/**
             * we would like to preserver the existing group id
             */
            if ($this->_getSession()->getCustomerGroupId()) {
                $customer
->setGroupId($this->_getSession()->getCustomerGroupId());
            
}

I overloaded editPostAction() method from the controller using the existing code with this change:

/**
             * we would like to preserver the existing group id if needed
             */
            if (!$this->getRequest()->getParam('group_id')) {
                
if ($this->_getSession()->getCustomerGroupId()) {
                    $customer
->setGroupId($this->_getSession()->getCustomerGroupId());
                
}
            }

It now works perfectly. And, I learned how to overload a controller along the way. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
rianti
Jr. Member
 
Total Posts:  8
Joined:  2009-03-31
 

Hi flmag,

I’ve implemented the code and it works great grin Thanks heaps, I really appreciate your prompt help!

===========================================================================

Group is reset back to General in My Account

Hi, I tried to implement your code and it works fine. However, after registration when I go to My Account, the Customer Group is reset back to “General”. I changed and saved it, but when I check, it’s back to “General” again. Do you have the same problem or did I implement the code incorrectly?

Most likely the problem is in edit.phtml.
Even if the group is saved ok in the db, in my post i didn’t specify how to get the current customer group to be selected in the dropdown.
This should work, just replace the old foreach in the <select></select>

<?php foreach($groups as $group){ ?>
    
<option <?php if($this->getCustomer()->getGroupId() == $group['value']) print 'selected="selected"'?> value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>
<?php } ?>

 
Magento Community Magento Community
Magento Community
Magento Community
 
MartinaL
Member
 
Total Posts:  72
Joined:  2008-03-31
 

I tried to use this code as well but it seems to be over writing what is chosen to whatever is set as the default group for the website?

 
Magento Community Magento Community
Magento Community
Magento Community
 
mkII
Sr. Member
 
Total Posts:  79
Joined:  2009-02-24
 

I want to force the user’s group change on checkout if the user purchased some product (e.g. virtual “membership” product). Does anyone has idea how to implement this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brandon S.
Jr. Member
 
Total Posts:  14
Joined:  2009-04-10
 

@mkll Lucky you. This was just released a little while ago: http://www.magentocommerce.com/extension/packages/module/1666/customer-group-switcher

 
Magento Community Magento Community
Magento Community
Magento Community
 
mkII
Sr. Member
 
Total Posts:  79
Joined:  2009-02-24
 

Brandon, thank you for caring, I already know about it. smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
suricate
Sr. Member
 
Avatar
Total Posts:  127
Joined:  2009-06-25
Brazil
 

Hello,

I’m trying to make this work in onepage, but no success yet, any idea?
PS. registration.phtml is working fine

in billing.phtml i include:

<div class="select">
                    <
label for="billing:group_id"><?php echo $this->__('Tipo de Pessoa'?> <span class="required">*</span></label><br />
                    <
select id="billing:group_id" name="billing[group_id]" title="<?php echo $this->__('Customer Group') ?>" class="validate-select">
                        <
option value=""><?php echo $this->__('A NF &eacute; para Pessoa..(selecione)'?></option>
                        
<?php 
                        $groups 
Mage::getResourceModel('customer/group_collection')
                            ->
addFieldToFilter('customer_group_id', array('gt'=> 0))
                            ->
load()
                            ->
toOptionArray();
                        foreach (
$groups as $a)
                            echo 
"<option value='".$a['value']."'>".$a['label']."</option>";
                        
?>
                    
</select>
                </
div>

in the config.xml

<checkout_onepage_billing>
                <
prefix><to_customer>*</to_customer></prefix>
                <
firstname><to_customer>*</to_customer></firstname>
                <
middlename><to_customer>*</to_customer></middlename>
                <
lastname><to_customer>*</to_customer></lastname>
                <
suffix><to_customer>*</to_customer></suffix>
                <
email><to_customer>*</to_customer></email>
                <
customer_dob><to_customer>dob</to_customer></customer_dob>
                <
customer_taxvat><to_customer>taxvat</to_customer></customer_taxvat>
                <
group_id><to_customer>*</to_customer></group_id>
            </
checkout_onepage_billing>

In other Topic have an explanation on how to make work editing 1 core file, but i tried without success
Link to the other topic if you have experience in php please help us! : http://www.magentocommerce.com/boards/viewthread/9620/P103/

i try with this code without success: (on line 225 on version 1.3.2.1 of app\code\core\Mage\Checkout\Model\Type\OnePage.php)

// CREATE A SESSION VARIABLE WITH $data ARRAY
$_SESSION["customDataForm"]=$data;   // <this is line 227 in my file

and on function saveorder after
case Mage_Sales_Model_Quote::CHECKOUT_METHOD_REGISTER:
$customer = Mage::getModel(’customer/customer’);
i added:

$customer->setGroupId($_SESSION["customDataForm"]["group_id"]);

but i have the error in firebug (and the page dont go to shipping methods, simple reloads): “Undefined variable: data in /var/www/html/app/code/core/Mage/Checkout/Model/Type/Onepage.php on line 227”

Any idea?

Sorry for bad English

Any help is appreciated

Best Regards,

Fernando

 Signature 

Fernando
Loja Online de Equipamentos de Informática
Visite o Blog Suricate de Tecnologia
Follow us on Twitter

 
Magento Community Magento Community
Magento Community
Magento Community
 
poashoas
Jr. Member
 
Total Posts:  13
Joined:  2009-11-11
 

Is it also possible to add a hidden input or selected option to add a new registration to a customer group like “wholesale” automaticly?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Dhiraj Patra
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2009-10-30
India
 

Hi all and specially flmag, thanks for your post regarding group id option added into the registration form. cool smile
After implementing it group id not displaying into the customer registration form. I have refresh / clean cache several times but there is no effect at all.
Kindly anybody can tell me any solution or suggestion?
Regards

 Signature 

All you need for open source LAMP

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2
 
© Copyright 2010 Magento Inc.
Privacy Policy|Terms of Service
Magento Community Count
277237 users|1058 users currently online|346992 forum posts