区分Magento中的会话

时间:2012-11-14 16:30:37

标签: ajax magento session login

我遇到了麻烦,我确信答案很简单,但我还没找到。我的问题:

我正在为Magento EE 1.9.1.1构建一个AJAX登录,我已经完成了它,但它没有将customer/sessioncore/session分开。除了推车之外,这不是什么大不了的事。现在发生的事情是当客户登录时,购物车中的商品按预期转移到客户会话,但是,在注销时,商品保留在购物车中 - 然后,如果我要从购物车中取出商品并重新购买登录客户会话中缺少该项目。完整的登录代码如下:

如果有帮助,我找到了这个帖子:StackOverflow,但不明白。

简单地说,我通过POST将用户名和密码传递给以下login.php

Mage::getSingleton('core/session', array('name'=>'frontend'));

if ($_POST['logout'] == "true"){
    Mage::getSingleton('customer/session')->logout();
    echo "Logged out successfully!";
}

else {
/**
 * Login post action
 */

    require_once($_SERVER['DOCUMENT_ROOT'] . "/app/code/core/Mage/Customer/controllers/AccountController.php");
    class Ns_Mylogin_AccountController extends Mage_Customer_AccountController{

    public function loginPostAction()
    {
        $result["error"]=0;

        $session = $this->_getSession();        

        if (!empty($_POST['username']) && !empty($_POST['password'])) {
            try {
                $session->login($_POST['username'], $_POST['password']);
                if ($session->getCustomer()->getIsJustConfirmed()) {
                    $this->_welcomeCustomer($session->getCustomer(), true);

                }
            } catch (Mage_Core_Exception $e) {
                switch ($e->getCode()) {
                    case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED:
                        $result["error"]=1;
                        $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', Mage::helper('customer')->getEmailConfirmationUrl($login['username']));
                        break;
                    case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD:
                        $result["error"]=1;
                        $message = $e->getMessage();
                        break;
                    default:
                        $result["error"]=1;
                        $message = $e->getMessage();
                }
                $session->setUsername($_POST['username']);

            } catch (Exception $e) {
                // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password
            }
            if(!$message || $message == '') {
                echo "Successful login!";
                }
            else{
                    echo $message;            
                    }            
        } 
        else {
            echo "Login and password are required!";
        }


}

}

$loginObject = new Ns_Mylogin_AccountController();
$loginObject->loginPostAction();
}
?>

正如我所提到的,登录/注销工作得很好,就购物车而言,它只是没有正确处理会话。任何帮助将这些会议分开的人都将不胜感激!

0 个答案:

没有答案