Ajax 在Magento中区分会话

Ajax 在Magento中区分会话,ajax,magento,session,login,Ajax,Magento,Session,Login,我遇到了麻烦,我相信答案很简单,但我还没有找到。我的问题: 我正在为Magento EE 1.9.1.1构建一个AJAX登录,我已经完成了,但是它没有将客户/会话和核心/会话分开。除了购物车,没什么大不了的。现在发生的事情是,当客户登录时,购物车中的项目会按预期转移到客户会话,但是,在注销时,项目会留在购物车中——如果我要从购物车中删除项目并重新登录,则客户会话中的项目会丢失。完整的登录代码如下: 如果有帮助的话,我找到了这条线索:,但我不理解它 简单地说,我通过POST将用户名和密码传递到下面

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

我正在为Magento EE 1.9.1.1构建一个AJAX登录,我已经完成了,但是它没有将
客户/会话
核心/会话
分开。除了购物车,没什么大不了的。现在发生的事情是,当客户登录时,购物车中的项目会按预期转移到客户会话,但是,在注销时,项目会留在购物车中——如果我要从购物车中删除项目并重新登录,则客户会话中的项目会丢失。完整的登录代码如下:

如果有帮助的话,我找到了这条线索:,但我不理解它

简单地说,我通过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();
}
?>
Mage::getSingleton('core/session',array('name'=>'frontend');
如果($_POST['logout']==“true”){
Mage::getSingleton('customer/session')->logout();
echo“成功注销!”;
}
否则{
/**
*登录后操作
*/
需要一次($_服务器['DOCUMENT_ROOT'].“/app/code/core/Mage/Customer/controllers/AccountController.php”);
类Ns\u Mylogin\u AccountController扩展了Mage\u Customer\u AccountController{
公共函数loginpostation()
{
$result[“error”]=0;
$session=$this->_getSession();
如果(!empty($\u POST['username'])和($\u POST['password'])为空{
试一试{
$session->login($_POST['username'],$_POST['password']);
如果($session->getCustomer()->getisjustconfirm()){
$this->\u welcomeCustomer($session->getCustomer(),true);
}
}捕获(法师核心例外$e){
开关($e->getCode()){
案例经理\客户\型号\客户::例外情况\电子邮件\未确认:
$result[“error”]=1;
$message=Mage::helper('customer')->(此帐户未确认。若要重新发送确认电子邮件,'),Mage::helper('customer')->getEmailConfirmationUrl($login['username']);
打破
案例图像\u客户\u型号\u客户::异常\u无效\u电子邮件\u或\u密码:
$result[“error”]=1;
$message=$e->getMessage();
打破
违约:
$result[“error”]=1;
$message=$e->getMessage();
}
$session->setUsername($_POST['username']);
}捕获(例外$e){
//Mage::logException($e);//PA DSS冲突:此异常日志可能会泄露客户密码
}
如果(!$message | |$message==''){
echo“成功登录!”;
}
否则{
回声$信息;
}            
} 
否则{
echo“需要登录名和密码!”;
}
}
}
$loginObject=new Ns_Mylogin_AccountController();
$loginObject->loginpostation();
}
?>
正如我提到的,登录/注销工作得很好,就购物车而言,它只是没有正确处理会话。如果您能帮助我们将这些课程分开,我们将不胜感激