6
votes

Trying to add a group_id radio button set in Magento Pro v1.11

Following along with
http://phpmagento.blogspot.com/2012/01/how-to-show-customer-group-selecter-in.html and
http://developersindia.info/magento/magento-override-frontend-controller.html,
which is working to a point, but the group_id is not getting written to the db.

my module, thus far:

Directory Structure

app/code/local
- WACI
-- Customer
--- controllers
---- AccountController.php
--- etc
---- config.xml



config.xml

<config>
    <modules>
        <WACI_Customer>
            <version>0.1.0</version>
        </WACI_Customer>
    </modules>
    <global>
        <fieldsets>
            <customer_account>
                <group_id><create>1</create></group_id>
            </customer_account>
        </fieldsets>
    </global>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <WACI_Customer before="Mage_Customer_AccountController">
                            WACI_Customer
                        </WACI_Customer>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>



AccountController.php

<?php
/**
 *Customer account controller
 *
 * @package     WACI_Customer
 */

require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';

class WACI_Customer_AccountController extends Mage_Customer_AccountController
{

    /**
    * Create customer account action
    */
    public function createPostAction()
    {

// contents of createPostAction(), with some extra logic

            /**
             * Initialize customer group id
             */

            /* catch groupid at account creation */

            if($this->getRequest()->getPost('group_id')){ 
                $customer->setGroupId($this->getRequest()->getPost('group_id'));
            } else {
                $customer->getGroupId(); 
            } 



 // rest of method

    }

}




theme../persistent/customer/form/register.phtml

<div class="input-box">
    <label for="group_id"><?php echo $this->__('Select your customer group') ?></label><br />
    <?php 
        $groups = Mage::helper('customer')->getGroups()->toOptionArray();
        foreach ($groups as $group){
            echo '<input type="radio" name="group_id" value="'.$group['value'].'" class="validate-radio" >'.$group['label'].'</input><br/>';
        }
    ?>
</div>

So, the radio buttons with the groups show up fine at registration, but the data isn't being written to the db, as group still shows as general in the admin/manage customers

  • I don't really want to modify core files, as the article describes,
  • I'm not certain that I'm properly overwriting the mage accountController class (maybe theres a better way to do this?)

What am I mucking up?

2

2 Answers

6
votes

See below URL I think it is very help full to you.

How to let customer choose customer group at registration

http://www.magentocommerce.com/boards/viewthread/24208/

selecting customer group during registration in magento

http://sabujcse.wordpress.com/2010/03/09/selecting-customer-group-during-registration-in-magento/

How to Add Customer Group field while register in magento

http://xhtmlandcsshelp.blogspot.in/2010/12/add-customer-group-while-register-in.html

How to add group in register form

http://sapnandu-magento.blogspot.in/2011/07/how-to-add-group-in-register-form.html

3
votes

Check your config.xml:

<frontend>
    <routers>
        <customer>
            <args>
                <modules>
                    <WACI_Customer before="Mage_Customer_AccountController">
                        WACI_Customer
                    </WACI_Customer>
                </modules>
            </args>
        </customer>
    </routers>
</frontend>

Should be:

<frontend>
    <routers>
        <customer>
            <args>
                <modules>
                    <WACI_Customer before="Mage_Customer">WACI_Customer</WACI_Customer>
                </modules>
            </args>
        </customer>
    </routers>
</frontend>

You also need to pay attention with:

<WACI_Customer before="Mage_Customer">WACI_Customer</WACI_Customer>

and

<WACI_Customer before="Mage_Customer">
    WACI_Customer
</WACI_Customer>

You have to make sure no empty spaces between <tag> and content and </tag>