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.
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)
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.)
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?
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.
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>
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?
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”
Hi all and specially flmag, thanks for your post regarding group id option added into the registration form.
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