本文介紹了Magento 客戶以編程方式登錄的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!
問(wèn)題描述
我有代碼:
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] => 無(wú)效的登錄名或密碼.
登錄名和密碼正確,我嘗試了很多帳戶,結(jié)果都一樣.
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){
}
}
?>
這篇關(guān)于Magento 客戶以編程方式登錄的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!