登录Magento后,将客户重定向到自定义URL /页面

Sha*_*med 1 php magento magento-1.7

我在magento中有一个自定义页面.我的条件是"如果用户没有登录,那么在保存任何更改之前我将用户重定向到登录页面,我想在登录后将用户重定向到我的自定义页面." 我正在使用以下代码,它不会在登录后重定向我的自定义页面.

Mage::app('default');
if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() ){                  
    $session = Mage::getSingleton( 'customer/session' );
    $session->setBeforeAuthUrl('http://'.$_SERVER['HTTP_HOST'].'/custom.html');
    header("Location: /customer/account/login");    
}
Run Code Online (Sandbox Code Playgroud)

它将我重定向到登录页面.如果我使用以下代码而不是header它不会将我重定向到登录页面.

Mage::app()->getResponse()->setRedirect(Mage::getUrl("customer/account/login")); 
Run Code Online (Sandbox Code Playgroud)

要么

Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));
Run Code Online (Sandbox Code Playgroud)

1)我在同一个域名.

2)"系统">"配置">"客户配置"部分"登录选项" - >"记录后将客户重定向到帐户仪表板"设置为否.

我想在重定向到登录页面之前设置返回URL.所以登录后它会将用户重定向到返回的URL页面.我的自定义页面不在magento中.

这是我的自定义页面代码.

$mageFilename = 'app/Mage.php';
require_once( $mageFilename );
umask(0);
Mage::app();
if( !Mage::getSingleton( 'customer/session' )->isLoggedIn() ){                  
    $session = Mage::getSingleton( 'customer/session' );
    $session->setBeforeAuthUrl('http://'.$_SERVER['HTTP_HOST'].'/full-custom.php?sid=8');
    header("Location: /customer/account/login");
    //Mage::app()->getResponse()->setRedirect(Mage::getUrl("customer/account/login"));  
    //Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('customer/account'));  
}
Run Code Online (Sandbox Code Playgroud)

请帮忙!!

Deu*_*777 5

我有类似的问题,我使用了不同的解决方案.在我的场景中,Magento将用户重定向到最后一页,他在最后一次登录的同时开启了.

起初它很混乱,因为即使在登录NO后设置管理>系统>配置>客户配置>登录选项>将客户重定向到帐户仪表板我仍然被重定向到仪表板.

最后我意识到这就是我的情况,这是我最近退出后的最后一页.

无论如何,我希望Magento 在登录后始终将用户重定向到他目前所在的最后一页.

我想避免安装任何扩展,或者自己创建额外的扩展(这包括重写AccountController).所以我只是通过本地覆盖Magento/Customer/Model/Session.php来解决它,我添加了$ this-> unsBeforeAuthUrl(); 在登录方法中(成功验证后).

public function login($username, $password)
{
    /** @var $customer Mage_Customer_Model_Customer */
    $customer = Mage::getModel('customer/customer')
        ->setWebsiteId(Mage::app()->getStore()->getWebsiteId());

    if ($customer->authenticate($username, $password)) {
        $this->unsBeforeAuthUrl();  // <-- my addition
        $this->setCustomerAsLoggedIn($customer);
        $this->renewSession();
        return true;
    }
    return false;
}
Run Code Online (Sandbox Code Playgroud)

多亏了这一点,现在每次用户登录时都清除了before_auth_url,这迫使magento将用户重定向到存储在referer参数中的url.

我必须在我的mini.login.phtml表单中添加referer参数.这是这样做的.

首先在template/customer/form/mini.login.phtml的顶部添加:

<?php
    $params = Mage::helper('customer')->getLoginUrlParams();
    $ref = isset($params[Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME])?$params[Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME]:false;
?>
Run Code Online (Sandbox Code Playgroud)

然后在我添加的内部的某处:

<?php if ($ref): ?>
<input type="hidden" name="<?php echo Mage_Customer_Helper_Data::REFERER_QUERY_PARAM_NAME ?>" value="<?php echo $ref ?>"/>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

现在它以我想要的方式工作(至少现在,我今天创造了这个).当我遇到这个解决方案的一些问题时,我会尝试添加一些注释.

我不确定它是否是完美的解决方案(因为它需要添加此引用跟踪) - 也许Magento在其他地方内部存储了最后的URL,并且可以从会话中读取它.