将客户关联到可用网站 [英] associate customer to available websites

查看:79
本文介绍了将客户关联到可用网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 magento admin 中创建了3个网站,但目前它们没有其他网址.

I'd created 3 websites in magento admin but they do not have different urls for now.

我想做的是,在注册页面上,我为website添加了一个字段,在其中我以编程方式创建了一个选择框,如下所示:

The thing I want to do is, on the registration page I'd added one more field for website where I'd programmatically created a select box as:

<select name="website">
    <option value="">Please select...</option>
    <?php
        $websites = Mage::app()->getWebsites();
        foreach ($websites as $web) {
            echo "<option value='" . $web->getId() . "'>" .
                     $web->getName() . "</option>\n";
        }
    ?>
</select>

现在,当用户提交此表单时,基于所选的website,他需要与该表单相关联.

Now when the user submits this form, based on the chosen website he need to be associated with it.

为此,我已经覆盖了Customer/AccountControllercreatePostAction(),但是我想知道如何分配此website id,因为在parent::createPostAction()中存在太多的抽象.

For this I'd already overriden the Customer/AccountController's createPostAction() but I'm wondering how do I assign this website id as in parent::createPostAction() there's too much abstraction.

有没有简单的方法可以做到这一点?

Is there any easy way to do this?

推荐答案

最终发现此答案很有帮助.但是我在观察器中做了一些更改,在这些更改中我确实需要让客户选择website id.

finally found this answer helpful. But I'd made some changes in the observer where I do needed to get the website id selected by the customer.

以下是来自我的观察员的代码

public function setWebsiteId($object) {
    //getting website_id from user selection
    $webid = Mage::app()->getFrontController()->getRequest()
            ->getParam('website_id', Mage::app()->getStore()->getWebsiteId());
    $customer = $object->getCustomer();
    $customer->setWebsiteId($webid);
    return $this;
}

需要处理的事件是:customer_register_success

修订

上面的代码可以正常工作,但是上述实现的问题是,如果用户已经在当前网站中注册,那么他将无法从当前网站中注册其他网站.为了解决这个问题,我重写了Customer/AccountControllercreatePostAction()

The above code works fine but the problem with the above implementation was, if a user is already registered in the current website then from the current website he will not be able to register in the other website. To solve this problem I'd overridden the Customer/AccountController's createPostAction()

public function createPostAction() {
    $post = $this->getRequest()->getPost();
    if (isset($post['website_id'])) {
        $webid = $this->getRequest()->getParam('website_id');
        $customer = $this->_getCustomer();
        $customer->setWebsiteId($webid);
        Mage::register('current_customer', $customer); //this is the important line here
    }
    parent::createPostAction();
}

如果我不执行此操作,则父级createPostAction()将再次获取客户对象,如$customer = $this->_getCustomer();并丢失我先前在其中设置的website_id.

If I'm not doing this Mage::register('current_customer', $customer); then the parent createPostAction() will again fetch customer object as $customer = $this->_getCustomer(); and loss website_id which I had set in there previously.

这篇关于将客户关联到可用网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆