Magento:在注册时选择客户组

时间:2012-08-30 16:53:50

标签: php magento controller

尝试在 Magento Pro v1.11

中添加 group_id 单选按钮集

跟随着 http://phpmagento.blogspot.com/2012/01/how-to-show-customer-group-selecter-in.html
http://developersindia.info/magento/magento-override-frontend-controller.html,正在处理某个问题,但是group_id没有写入数据库。

我的模块,到目前为止:

目录结构

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

    }

}




主题../持久/客户/形式/ 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>

因此,带有组的单选按钮在注册时显示正常,但数据没有写入数据库,因为组仍然在admin/manage customers

中显示为一般
  • 我并不想修改核心文件,正如文章所描述的那样,
  • 我不确定我是否正确覆盖了法师 accountController课程(也许是更好的方法吗?)

我在搞什么?

2 个答案:

答案 0 :(得分:6)

请参阅以下网址我认为对您来说非常有帮助。

如何让客户在注册时选择客户群

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

在magento注册期间选择客户群

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

如何在magento中注册时添加客户组字段

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

如何以注册形式添加群组

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

答案 1 :(得分:3)

检查config.xml:

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

应该是:

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

您还需要注意:

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

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

您必须确保<tag>content</tag>之间没有空格