客户无法以编程方式登录magento

时间:2015-10-27 14:30:00

标签: php magento curl soap login

我正在尝试以magento编程方式登录客户。我用过curl并用magento开发我的肥皂api。

要求:我有两个网站,一个在laravel,另一个在magento,所有的电子邮件和密码都在两个网站上设置。当用户登录laravel网站时,客户必须登录magento网站,反之亦然。在概念的唯一标志。

使用Soap Api,将参数电子邮件和密码传递给我的soap客户端。以下是代码:

$string = "login[username]=xyz@mymail.com&login[password]=123456&form_key=B3pr9GSMp75kwW20";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1/performer/index.php/customer/account/loginPost');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.session_id());
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $string);
curl_setopt($ch, CURLOPT_HEADER, true);

$output = (string) curl_exec($ch);

通过soap调用此方法,它将返回会话ID并验证客户身份,但不会在前端登录客户。

我已经尝试过curl来调用customer模块的loginPost动作并传递表单键,下面是curl代码:

http://127.0.0.1/performer/index.php/customer/account/loginPost

这也可以正常运行但客户没有登录。

我已使用操作

在magento root上创建html表单
class Book(model.Model):
    title = CharField()

class Chapter(model.Model):
    book = ForeignKey(Book, related_name='chapters')

和文本字段是电子邮件,密码和表格密钥,在提交表格后它将成功登录到magento。

但无法使用api和curl登录。

1 个答案:

答案 0 :(得分:0)

尝试$ session-> loginById 和$ session-> setCustomerAsLoggedIn

取消了我过去的一个项目:

$session = Mage::getSingleton( 'customer/session' );
try
{
    $session->loginById( $customer->getId());
    $session->setCustomerAsLoggedIn( $session->getCustomer() );
}
catch( Exception $e )
{
    return false;
}
Mage::app()->getResponse()->setRedirect(Mage::getUrl('customer/account/index'));