Magento Ajax登录会话问题

时间:2012-10-04 14:54:01

标签: magento

我正在尝试创建自己的登录页面,该页面在fancybox弹出窗口中使用Ajax。我创建了自己的模块,扩展了默认客户AccountController。它似乎工作正常,但是当用户成功登录时,控制器会将客户数据保存在会话中,但是当我返回主页时,客户会话数据不再存在。我是否需要在返回时设置会话?

我的控制器在

之下
    public function loginPostAction()
{


   $session = Mage::getSingleton('customer/session');

    if ($this->getRequest()->isPost()) {
        $login = $this->getRequest()->getPost('login');

         Mage::log($login['username'].$login['password']);
        if (!empty($login['username']) && !empty($login['password'])) {

            try {
                $session->login($login['username'], $login['password']);
               // Mage::log($session->login($login['username'], $login['password']));
                $this->_welcomeCustomer($session->getCustomer(), true);
                if ($session->getCustomer()->getIsJustConfirmed()) {
                    $this->_welcomeCustomer($session->getCustomer(), true);
                    $response =  "TRUE";
                }
            } catch (Mage_Core_Exception $e) {
                switch ($e->getCode()) {
                    case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                        $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
                        Mage::log("EXCEPTION_EMAIL_NOT_CONFIRMED");
                        $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value);
                        $response = "This account is not confirmed";
                        break;
                    case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                        $message = $e->getMessage();
                        $response = "Invalid email or password";
                        Mage::log("EXCEPTION_INVALID_EMAIL_OR_PASSWORD");
                        break;
                    default:
                        $message = $e->getMessage();
                         Mage::log("EXCEPTION_default");
                }
                //$session->addError($message);
                Mage::log("about setting the username");
                $session->setUsername($login['username']);
            } catch (Exception $e) {
                // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
            }
        } else {
            Mage::log("in the else");
            $session->addError($this->__('Login and password are required.'));
            $response = 'Login and password are required.';
        }
    }
    Mage::log($session->getCustomer());

    //echo $response;
    //$this->_loginPostRedirect();
}

任何帮助都会感激不尽

通过更新config.xml文件修复。我没有超越客户控制器

<router>
    <customer>
            <args>
                <modules>
                    <companyname_loginform before="Mage_Customer">companyname_Loginform</companyname_loginform>
                </modules>
            </args>
        </customer>

2 个答案:

答案 0 :(得分:0)

如果还有人需要magento ajax登录功能,我可以推荐我们公司开发的magento插件。链接在这里 - https://store.plumrocket.com/magento-extensions/popup-login-magento-extension.html

我们还有文档和论坛。随时问我们任何问题。

谢谢!

答案 1 :(得分:-1)

我发现了这个问题。我只是扩展了客户帐户控制器 - 我没有正确地从config.xml

覆盖它