2017-01-11 40 views
0

我們正在嘗試在Magento中務實地設置客戶會話。我們正在通過設置會話setCustomerAsLoggedIn方法。但是對於一些客戶,它繼續加載/處理請求,並在最後顯示「網關超時連接超時」錯誤。它的隨機問題,而不是所有的客戶。Magento設置客戶會話網關或連接超時錯誤

我們的Magento安裝有3個網站B2B,B2E,B2C,我們只面對B2B和B2E網站這個問題。請回顧下面的功能並幫助解決可能的問題。

$customer=Mage::getModel('customer/customer')->load($id); 
$session = Mage::getSingleton('customer/session'); 
$session->setCustomerAsLoggedIn($customer); 
$this->_redirect(); 

回答

0

相反直傳客戶對象到會話中,你應該通過如下:

$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; 
+0

其實,我們並沒有要求用戶輸入密碼。我們只有基於電子郵件和OTP確認的登錄系統。因此,我們只需在OTP確認後通過電子郵件加載客戶,並在會話中設置客戶對象。 –

+0

嗯,你可以嘗試通過爲用戶設置一次網站,例如$ customer-> setWebsiteId($ websiteId);也更新了我的答案 –