Php Magento:客户注册页面中的组字段

Php Magento:客户注册页面中的组字段,php,magento,module,Php,Magento,Module,是否有办法避免编辑Magento Core(app/code/Core/Mage/Customer/controllers/AccountController.php)文件,以便在注册页面中启用客户组选项字段 搜索它,唯一成功的方法是编辑前面提到的核心文件,找到以下代码: $customer->getGroupId(); 并将其替换为: if($this->getRequest()->getPost('group_id')) { $customer->setGro

是否有办法避免编辑Magento Core(app/code/Core/Mage/Customer/controllers/AccountController.php)文件,以便在注册页面中启用客户组选项字段

搜索它,唯一成功的方法是编辑前面提到的核心文件,找到以下代码:

$customer->getGroupId();
并将其替换为:

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

最好的情况是在本地模块文件中包含此代码,类似于app/code/local/Enterprise/module/controllers/AccountController.php。实际上,我有一个包含该函数的模块,但仍然没有找到要添加到该模块上的正确代码。

始终建议为每个新功能创建一个新模块,但如果您只更改一行代码,您也可以将修改后的文件放在以下路径中(请注意,将core替换为local):
app/code/local/Mage/Customer/controllers/AccountController.php

然后,您可以恢复您的核心文件,自动加载程序仍应获得您的修改版本。这样可以避免修改核心,但请记住,当您将Magento升级到新版本时,可能还需要更新此文件

有关详细信息,请查看此链接:

以正确的方式进行: 在模块内扩展控制器

将其放在config.xml中:

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

实际上,我有一个包含该函数的模块,但仍然没有找到要添加到该模块上的正确代码。编辑了显示代码的答案,通过覆盖controllerHi,@Javier,使用模块进行更改,谢谢您的编辑。但是,仍然没有在这里工作。我怀疑你最终把我的问题带到了与我实际需要不同的方向。查看从Mage\u Customer\u AccountController扩展的函数_getCustomer?我认为此函数与Customer Registration Page(我正在打印选择元素以选择客户组)不对应,是吗?Customer Registration Page将表单提交到
AccountController::createPostAction
,该方法从
$this->\u getCustomer()获取客户对象(将被创建)
。因此,如果您想设置一个自定义的groupId,那么这似乎是一个合适的地方。请注意,要使其正常工作,您还必须在提交的表单中创建一个名为
group\u id
的输入字段。
<?php
require_once 'Mage/Customer/controllers/AccountController.php';
class Company_Modulename_AccountController extends       Mage_Customer_AccountController
{
 /**
  * Get Customer Model
  *
  * @return Mage_Customer_Model_Customer
  */
  protected function _getCustomer()
  {
    $customer = $this->_getFromRegistry('current_customer');
    if (!$customer) {
        $customer = $this->_getModel('customer/customer')->setId(null);
    }
    if ($this->getRequest()->getParam('is_subscribed', false)) {
        $customer->setIsSubscribed(1);
    }
    /**
     * Initialize customer group id
     */
    if($this->getRequest()->getPost('group_id')) { 
        $customer->setGroupId($this->getRequest()->getPost('group_id'));
    } else {
        $customer->getGroupId();
    } 
    return $customer;
  }
}