dqrm8199 2015-04-24 23:14
浏览 17

从英国商店登录时,网站重定向到阿拉伯商店

I have developed new website with English and Arabic language using Magento CMS , what I had is when login from English store after logging the website redirect to Arabic store , I checked the code and I cannot find where the problem and why when logging from English redirect to Arabic store .

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));
}
  • 写回答

1条回答 默认 最新

  • duanjianao0592 2015-04-25 05:40
    关注

    Hi you can this by event observer of magento.

    Use event customer_login for this redirection and using setAfterAuthUrl and this will work when customer is loggin through customer/account/loginPost.

    config.xml code like:

       <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>
    

    Observer code look like:

    <?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;
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来