gpt4 book ai didi

ajax - Magento 客户从外部 magento 登录

转载 作者:行者123 更新时间:2023-12-02 03:49:15 24 4
gpt4 key购买 nike

我正在尝试以客户身份登录。我正在请求以下代码 (AJAX) 和这个外部 magento 商店。

<?php
require_once "../app/Mage.php";
umask(0);
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
$user = $_POST['user'];
$password = $_POST['password'];
$session = Mage::getSingleton('customer/session');
$flag = 0;
$resultArr = array();
function customerLogin($user,$password){
try{
$session = Mage::getSingleton('customer/session');
$result = $session->login($user,$password);
$customer = $session->getCustomer();
$session->setCustomerAsLoggedIn($customer);

$resultArr['flag'] = 1;
$resultArr['msg'] ='Logged in as '.$customer->getName();
$jsonReturn = json_encode($resultArr);
return $jsonReturn;
}catch(Exception $e){
$resultArr['flag'] = 0;
$resultArr['msg'] = $e->getMessage();
$jsonReturn = json_encode($resultArr);
return $jsonReturn;
}
}
echo customerLogin($user,$password);
?>

我发现上面的代码是 Creating the session files at var/session directory successfully but unable to write customer entry in log_customer DB table 。任何人都知道这里有什么问题。谢谢 :)

已更新Okie 以下更新的代码 (customerLogin.php) 在一个条件下工作

<?php
function customerLogin($user,$password){
require_once "./app/Mage.php";
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
$user = $_POST['user'];
$password = $_POST['password'];
$flag = 0;
$resultArr = array();
$session = Mage::getSingleton('customer/session');
try{
$result = $session->login($user,$password);
//$customer = $session->getCustomer();
$session->setCustomerAsLoggedIn($session->getCustomer());
$resultArr['flag'] = 1;
$resultArr['msg'] ='Logged in as '.$session->getCustomer()->getName();
$cusArr = array(
'isLoggedIn' => true,
'name' => $session->getCustomer()->getName(),
'id' => $session->getId(),
'email' =>$session->getCustomer()->getEmail(),
);
$resultArr['customerData'] = $cusArr;
$jsonReturn = json_encode($resultArr);
return $jsonReturn;
}catch(Exception $e){
$resultArr['flag'] = 0;
$resultArr['msg'] = $e->getMessage();
$jsonReturn = json_encode($resultArr);
return $jsonReturn;
}
}

echo customerLogin($user,$password);
?>

如果我遵循这样的目录结构:

|-- app
|-- **customerLogin.php**
|-- downloader
|-- install.php
|-- js
|-- lib
|-- media
|-- var

但是如果我将代码放在一个目录级别下,它就不起作用了:

|-- app
|-- **customerLogin**
`--**customerLogin.php**
|-- downloader
|-- install.php
|-- js
|-- lib
|-- media
|-- var

任何人都知道问题出在哪里。我想知道为什么当我将代码放在下一层时,magento 无法在 log_customer 表中写入 session 条目。

最佳答案

获取您的客户 ID,然后使用以下代码。

Mage::getSingleton('customer/session')->loginById($customerId);

关于ajax - Magento 客户从外部 magento 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15065002/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com