1

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

我正在为 Magento EE 1.9.1.1 构建一个 AJAX 登录,并且我已经完成了它,但是它没有将customer/sessionand分开core/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();
}
?>

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

4

0 回答 0