私は問題を抱えており、答えはかなり簡単だと確信していますが、まだそれを見つけていません。私の問題:
customer/session
Magento EE 1.9.1.1のAJAXログインを構築していて、完了しましたが、とが分離されていません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();
}
?>
私が言ったように、ログイン/ログアウトは素晴らしい働きをします、それはカートに関する限りセッションを正しく扱っていないだけです。これらのセッションを分離するための助けをいただければ幸いです。