相反直傳客戶對象到會話中,你應該通過如下:
$session = Mage::getSingleton('customer/session', array('name' => 'frontend'));
$session->login($email, $password);
$session->setCustomerAsLoggedIn($session->getCustomer());
因此,從會議傳遞的客戶對象的登錄完成後。
請嘗試讓我們知道這是否適合您。
如果您要登錄通過電子郵件的用戶只有你還可以用以下方法
$customer = Mage::getModel('customer/customer')->load($customerId);
if ($customer->getWebsiteId()) {
Mage::init($customer->getWebsiteId(), 'website');
$session = Mage::getSingleton('customer/session');
$session->loginById($customerId);
return $session;
}
你需要先使用電子郵件進行上述工作,以獲取客戶ID,併網是關鍵
嘗試
工作代碼:
下面是我控制住了自己在演示現場,工作代碼:
include("app/Mage.php");
Mage::app();
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getStore()->getWebsiteId());
$customer->loadByEmail('[email protected]');
$customerId = $customer->getId();
Mage::init($customer->getWebsiteId(), 'website');
$session = Mage::getSingleton('customer/session');
$session->loginById($customerId);
return $session;
exit;
其實,我們並沒有要求用戶輸入密碼。我們只有基於電子郵件和OTP確認的登錄系統。因此,我們只需在OTP確認後通過電子郵件加載客戶,並在會話中設置客戶對象。 –
嗯,你可以嘗試通過爲用戶設置一次網站,例如$ customer-> setWebsiteId($ websiteId);也更新了我的答案 –