本文介紹了Magento 客戶以編程方式登錄的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有代碼:
function loginUser( $email, $password )
{
/** @var $session Mage_Customer_Model_Session */
$session = Mage::getSingleton( 'customer/session' );
try
{
$session->login( $email, $password );
$session->setCustomerAsLoggedIn( $session->getCustomer() );
return 1;
}
catch( Exception $e )
{
return $e;
}
}
$test = loginUser("login","password");
echo "test";
print_r($test);
die;
但我總是得到
Mage_Core_Exception Object ( [_messages:protected] => Array ( ) [message:protected] => 無效的登錄名或密碼.
登錄名和密碼正確,我嘗試了很多帳戶,結果都一樣.
Login and password is correct, I tried many accounts, with the same result.
如何正確登錄?
推薦答案
<?php
function loginUser( $email, $password )
require_once ("app/Mage.php");
umask(0);
ob_start();
session_start();
Mage::app('default');
Mage::getSingleton("core/session", array("name" => "frontend"));
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
try {
$customer->loadByEmail($email);
$session = Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer);
$session->login($email, $password);
}catch(Exception $e){
}
}
?>
這篇關于Magento 客戶以編程方式登錄的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!