2012-01-07 53 views
3

我想將用戶重定向到登錄着陸頁面登錄,當用戶沒有登錄Magento的重定向到登錄頁面,而用戶沒有登陸

例如: - 。

example.com ->(not logged in)-> redirect to login page. 

example.com ->(logged in)-> redirect to Home page. 

哪有我這樣做?

,我發現了一些功能,像這樣

public function preDispatch() 
{ 
    parent::preDispatch(); 

    if (!Mage::getSingleton('customer/session')->authenticate($this)) { 
     $this->setFlag('', 'no-dispatch', true); 
    } 
} 

如何使用或我應該在哪裏使用。

希望有些人會有這方面的經驗。在此先感謝

+1

嘗試此鏈接,自由伸展[自定義登錄重定向(http://www.magepsycho.com/shop/free-stuffs/custom-login-redirect.html) – 2012-01-07 22:22:56

+0

,這是另一個網站[重定向沒有記錄的客戶](http://blog.chapagain.com.np/magento-redirect-customer-to-login-page-if-not-logged-in/) – 2012-01-07 22:27:17

回答

18

這一個救就是我,

if(!$this->helper('customer')->isLoggedIn()){ 

    Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account')); 

} 

而且我把它叫做在CMS頁面block.Hope這個幫助別人。

2
$customerId = (int) $this->getRequest()->getParam('id'); 
$customer = Mage::getModel('customer/customer') 
        ->load($customerId); 

$userSession = Mage::getSingleton('customer/session'); 
$userSession->setCustomer($customer); 
Mage::dispatchEvent('customer_login', array('customer'=>$customer)); 

$this->getResponse()->setRedirect(Mage::getUrl('customer/account')); 

希望這有助於

+0

:感謝您的代碼,但我應該在哪裏在模板中添加代碼。 – Gowri 2012-01-09 04:08:28

+0

您可以創建一個phtml文件並將其放入您的模板中,並通過使用 {{block type =「core/template」name =「redirect_block」template =「your_template/your_phtml.phtml」}}將其添加到您的主頁cms} – 2012-01-09 14:44:25

+0

你的代碼不適合我。+ 1是個好主意。謝謝 – Gowri 2012-01-10 06:48:49

1
$redirect_url = Mage::getUrl('customer/account/login/'); 
$current_url = Mage::helper('core/url')->getCurrentUrl(); 
if((!$this->helper('customer')->isLoggedIn()) && ($current_url != $redirect_url)){ 
    Mage::app()->getFrontController()->getResponse()->setRedirect($redirect_url); 
} 
相關問題