0

I am trying to make a group selection dropdown on the Magento customer registration page work. I have done all of the following:

Inserted the following code into template/persistent/customer/form/register.phtml:

<label for="group_id" style='margin-top:15px;'><?php echo $this->__('Which group do you belong to? (select "Pet Owner" if you are uncertain)') ?><span class="required">*</span></label>
            <div style='clear:both'><p style='color:red;'>Note: DVM/DACVO and Institution accounts require administrative approval.</p></div>
            <div class="input-box" style='margin-bottom:10px;'>
                    <select style='border:1px solid gray;' 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){ ?>
                            <?php if ($group['label']=="Pet Owner" || $group['label']=="DVM / DACVO" || $group['label']=="Institution"){?>
                                <option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>
                            <?php } ?>
                        <?php } ?>
                    </select>
                    </div>

Then the following in /app/code/local/Mage/Customer/controllers/AccountController.php in the createPostAction():

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

Finally the following in /app/code/local/Mage/Customer/etc/config.xml where group id was added:

  <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>
                <password>
                    <create>1</create>
                </password>
                <confirmation>
                    <create>1</create>
                </confirmation>
                <dob>
                    <create>1</create>
                    <update>1</update>
                </dob>
                <group_id><create>1</create><update>1</update></group_id>
                <taxvat>
                    <create>1</create>
                    <update>1</update>
                </taxvat>
                <gender>
                    <create>1</create>
                    <update>1</update>
                </gender>
            </customer_account>

I have tested it several times and every customer is still being added as the default customer group. Can you see what I am doing wrong?

  • @vinai updated this module today - maybe check out the newest version github.com/Vinai/customer-activation – philwinkle Apr 22 '13 at 3:55
  • He only added some comments. And I have already modified his module to do what I want. I am having trouble now getting the 'Choose which group you belong to:' dropdown in the customer registration to post that data correctly. New accounts are just being added to the default customer group. – CaitlinHavener Apr 22 '13 at 20:18
  • Have you tried to var_dump on $this->getRequest()->getPost('group_id') to see if it's returning something other than 1? – philwinkle Apr 22 '13 at 21:10
  • And can you paste the results of var_dump($customer->getData());die(); in the AccountController.php? – philwinkle Apr 22 '13 at 21:11
  • 1
    @benmarks (╯°□°)╯︵ ┻━┻) – philwinkle Sep 17 '13 at 21:24
2

Controller class definitions are not loaded via the autoloader. It's a common mistake to think that controller class definitions are subject to the same codepool load order as all of the other class types

So, the reason your code is not executing is because you have not implemented a proper controller rewrite mechanism. You'll need to add a directory under the customer frontname and create a proper class definition (and manually include the original AccountController); see https://stackoverflow.com/a/9350848/833795 for an exact implementation.

Note that there is an intended API (classical sense) for this (ref customer attribute used_in_forms and related values; e.g. vat_id).

  • It's been so long since I've worked on this so I can't remember how I managed it, but I'm going ahead and accepting your answer anyway. – CaitlinHavener Sep 17 '13 at 18:15
  • It's okay, it's the right answer :-) – benmarks Sep 17 '13 at 19:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.