2015-04-24 34 views
0

我已經開發了新的網站,英語和使用 Magento的CMS阿拉伯語,我不得不當英語商店登錄 登錄網站後重定向到阿拉伯商店,我查了代碼和 我找不到問題所在,爲什麼從英文登錄 重定向到阿拉伯商店。登錄時從英國商店的網站重定向到阿拉伯語店

public function loginPostAction() 
{ 
    if ($this->_getSession()->isLoggedIn()) { 
     $this->_redirect('*/*/'); 
     return; 
    } 
    $session = $this->_getSession(); 

    if ($this->getRequest()->isPost()) { 
     $login = $this->getRequest()->getPost('login'); 
     if (!empty($login['username']) && !empty($login['password'])) { 
      try { 
       $session->login($login['username'], $login['password']); 
       if ($session->getCustomer()->getIsJustConfirmed()) { 
        $this->_welcomeCustomer($session->getCustomer(), true); 
       } 
      } catch (Mage_Core_Exception $e) { 
       switch ($e->getCode()) { 
        case Mage_Customer_Model_Customer::EXCEPTION_EMAIL_NOT_CONFIRMED: 
         $value = Mage::helper('customer')->getEmailConfirmationUrl($login['username']); 
         $message = Mage::helper('customer')->__('This account is not confirmed. <a href="%s">Click here</a> to resend confirmation email.', $value); 
         break; 
        case Mage_Customer_Model_Customer::EXCEPTION_INVALID_EMAIL_OR_PASSWORD: 
         $message = $e->getMessage(); 
         break; 
        default: 
         $message = $e->getMessage(); 
       } 
       $session->addError($message); 
       $session->setUsername($login['username']); 
      } catch (Exception $e) { 
       // Mage::logException($e); // PA DSS violation: this exception log can disclose customer password 
      } 
     } else { 
      $session->addError($this->__('Login and password are required.')); 
     } 
    } 

    $this->_loginPostRedirect(); 
} 

/** 
* Define target URL and redirect customer after logging in 
*/ 
protected function _loginPostRedirect() 
{ 
    $session = $this->_getSession(); 

    if (!$session->getBeforeAuthUrl() || $session->getBeforeAuthUrl() == Mage::getBaseUrl()) { 

     // Set default URL to redirect customer to 
     $session->setBeforeAuthUrl(Mage::helper('customer')->getAccountUrl()); 
     // Redirect customer to the last page visited after logging in 
     if ($session->isLoggedIn()) { 
      if (!Mage::getStoreConfigFlag(
       Mage_Customer_Helper_Data::XML_PATH_CUSTOMER_STARTUP_REDIRECT_TO_DASHBOARD 
      )) { 
       $referer = $this->getRequest()->getParam(Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME); 
       if ($referer) { 
        $referer = Mage::helper('core')->urlDecode($referer); 
        if ($this->_isUrlInternal($referer)) { 
         $session->setBeforeAuthUrl($referer); 
        } 
       } 
      } else if ($session->getAfterAuthUrl()) { 
       $session->setBeforeAuthUrl($session->getAfterAuthUrl(true)); 
      } 
     } else { 
      $session->setBeforeAuthUrl(Mage::helper('customer')->getLoginUrl()); 
     } 
    } else if ($session->getBeforeAuthUrl() == Mage::helper('customer')->getLogoutUrl()) { 
     $session->setBeforeAuthUrl(Mage::helper('customer')->getDashboardUrl()); 
    } else { 
     if (!$session->getAfterAuthUrl()) { 
      $session->setAfterAuthUrl($session->getBeforeAuthUrl()); 
     } 
     if ($session->isLoggedIn()) { 
      $session->setBeforeAuthUrl($session->getAfterAuthUrl(true)); 
     } 
    } 
    $this->_redirectUrl($session->getBeforeAuthUrl(true)); 
} 
+2

貌似有一個堆棧交易所網站Magento的問題,甚至問題,可以幫助鉛你來一個答案。 http://Marketso.stackexchange.com/questions/29580/redirect-user-after-login –

+0

@MarkLeiber謝謝它適合我 – Myworld

回答

0

嗨,你可以通過這個Magento的的event observer

使用事件customer_login進行此重定向並使用setAfterAuthUrl,這將在customer is loggincustomer/account/loginPost時起作用。

config.xml文件的代碼,如:

<global> 
<models> 
    <magento29859026> 
    <class>Stackoverflow_Magento29859026_Model</class> 
    </magento29859026> 
</models> 
</global> 
<frontend> 
<events> 
    <customer_login> <!-- identifier of the event we want to catch --> 
    <observers> 
     <customer_login_handler> <!-- identifier of the event handler --> 
     <type>singleton</type> <!-- class method call type; valid are model, object and singleton --> 
     <class>magento29859026/observer</class> <!-- observers class alias --> 
     <method>RedirToArabic</method> <!-- observer's method to be called --> 
     </customer_login_handler> 
    </observers> 
</customer_login> 
</events> 
</frontend> 

觀察代碼的樣子:

<?php 
class Stackoverflow_Magento29859026_Model_Observer 
    public function RedirToArabic(){ 
     if(Mage::app()->getFrontController()->getAction()->getFullActionName()=='customer_account_loginPost'): 
      $arbicurl=Mage::getBaseUrl().'?___store=YOUR_STORE_CODE' 
      $session->setAfterAuthUrl($arbicurl); 
     endif; 
    } 
} 
相關問題