Jump to content

redirect after login - Prestashop 1.7


dellwen!!@@

Recommended Posts

  • 3 months later...

Hello use 1.7.1.2

I solved this. I spend many time searching but nothing after all I found a answer :lol:

  1. Go to: modules\ps_customersignin\ps_customersignin.php , after line 76
                'my_account_url' => $link->getPageLink('my-account', true),

    I create new url variable

                'login_url' => $link->getPageLink('authentication', true),

     

  2. Go to: themes\yourtheme\modules\ps_customersignin\ps_customersignin.tpl change this:
          <a
            href="{$my_account_url}"
            title="{l s='Log in to your customer account' d='Shop.Theme.Customeraccount'}"
            rel="nofollow"
          >

    for this with new variable
     

          <a
            href="{$login_url}"
            title="{l s='Log in to your customer account' d='Shop.Theme.Customeraccount'}"
            rel="nofollow"
          >

     

  This is all!!

Explanation:
When we are in 'authentication' after login by default redirect to  'base_url'  but when we are in 'my-account' the link have a parameter ...?back=my-account.

I hope that this solution can apply for you.

I only modified a module customersignin. Maybe in next time someone can fin the way to change the parameter in the ?back.

Regards from Colombia.

  • Like 1
  • Thanks 3
Link to comment
Share on other sites

  • 1 year later...
  • 3 months later...
  • 3 months later...
  • 6 months later...
On 11/21/2017 at 1:14 AM, hardstonepaul said:

Hello use 1.7.1.2

I solved this. I spend many time searching but nothing after all I found a answer :lol:

  1. Go to: modules\ps_customersignin\ps_customersignin.php , after line 76
    
                'my_account_url' => $link->getPageLink('my-account', true),

    I create new url variable

    
                'login_url' => $link->getPageLink('authentication', true),

     

  2. Go to: themes\yourtheme\modules\ps_customersignin\ps_customersignin.tpl change this:
    
          <a
            href="{$my_account_url}"
            title="{l s='Log in to your customer account' d='Shop.Theme.Customeraccount'}"
            rel="nofollow"
          >

    for this with new variable
     

    
          <a
            href="{$login_url}"
            title="{l s='Log in to your customer account' d='Shop.Theme.Customeraccount'}"
            rel="nofollow"
          >

     

  This is all!!

Explanation:
When we are in 'authentication' after login by default redirect to  'base_url'  but when we are in 'my-account' the link have a parameter ...?back=my-account.

I hope that this solution can apply for you.

I only modified a module customersignin. Maybe in next time someone can fin the way to change the parameter in the ?back.

Regards from Colombia.

This solution works perfectly if applied correctly even today on Prestashop 1.7.6.2.

Thanks a lot!

Edited by Maryando
Mistake (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...

Hi! after a long search i found a possible solution for prestashop 1.7.3.

Go to /controllers/front/AuthController.php

find the next code:

            if (Tools::isSubmit('submitLogin')) {
                if ($login_form->submit()) {
                     $should_redirect = true;
                }
            }

commet the line  $should_redirect = true; and add a Tools::redirectLink. 

Finally result:

            if (Tools::isSubmit('submitLogin')) {
                if ($login_form->submit()) {
                    // $should_redirect = true;
                    Tools::redirectLink(__PS_BASE_URI__);
                }
            }

__PS_BASE_URI__ i use this for redirecct to home. 

Save, upload the php to your server, clean cache from BO Advanced parameters > performance

and thats all, after user log redirecct to home.

Sorry for my english

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...
On 13/03/2020 at 08:02, loza said:

Oi! após uma longa pesquisa, encontrei uma possível solução para o prestashop 1.7.3.

Vá para /controllers/front/AuthController.php

encontre o próximo código:

            if (Tools :: isSubmit ('submitLogin')) {
                if ($ login_form-> submit ()) {
                     $ should_redirect = true;
                }
            }

confirmar a linha $ should_redirect = true; e adicione um Tools :: redirectLink. 

Finalmente resultado:

            if (Tools :: isSubmit ('submitLogin')) {
                if ($ login_form-> submit ()) {
                    // $ should_redirect = true;
                    Ferramentas :: redirectLink (__ PS_BASE_URI__);
                }
            }

__PS_BASE_URI__ eu uso isso para redirecionar para casa. 

Salve, envie o php para o servidor, limpe o cache do BO Advanced Parameters> performance

e isso é tudo, após o log do usuário redirecionar para casa.

Desculpe pelo meu Inglês

 

hello i need to redirect to (my address) after the customer registration, what is the way to change? can you help me?  

thank you

att: Alex Weiss

Prestashop 1.7.6.1

https://www.shoppingdoestudante.com/

Link to comment
Share on other sites

  • 1 year later...

Hello, 

I have Prestashop 1.7.7.4 and i found on web this solution that works form me

If You want to redirect people to index or other pages after login in prestashop 1.7 go to:
classes/form/CustomerLoginForm.php

Find this line:
Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);

Replace to this:
Tools::redirect('index.php');

Link to comment
Share on other sites

5 hours ago, Pssuido said:

If You want to redirect people to index or other pages after login in prestashop 1.7 go to:
classes/form/CustomerLoginForm.php

Find this line:
Hook::exec('actionAuthentication', ['customer' => $this->context->customer]);

Replace to this:
Tools::redirect('index.php');

Do that and you will lose the change every time you upgrade Prestashop. 

Do it with a proper override, or waayyy better, with a module hooked on actionAuthentication  that does the redirection for you and you will be able to upgrade Prestashop happily. 

Edited by w3bsolutions (see edit history)
Link to comment
Share on other sites

On 5/26/2021 at 9:19 PM, Nickz said:

Even better. Just explain in layman terms how and where to change what.

As promised, attached is a simple module I did to redirect the customer to any page after logging in. Just put the URL you want to redirect to in the module settings: 

  • It can be relative, as in your case for the homepage: index.php
  • Or it can be absolute, any URL such as : https://www.google.com 

You can undo your change to the core class and it will still work :)

w3b_redirectonlogin.zip

  • Like 1
  • Thanks 3
Link to comment
Share on other sites

  • 1 month later...
Le 27/05/2021 à 23h37, w3bsolutions a déclaré :

Comme promis, ci-joint un module simple que j'ai fait pour rediriger le client vers n'importe quelle page après s'être connecté. Il suffit de mettre l'URL vers laquelle vous souhaitez rediriger dans les paramètres du module : 

  • Il peut être relatif, comme dans votre cas pour la page d'accueil : index.php
  • Ou il peut être absolu, n'importe quelle URL telle que : https://www.google.com 

Vous pouvez annuler votre modification de la classe de base et cela fonctionnera toujours :)

w3b_redirectonlogin.zip 7,95 Ko  ·  8 téléchargements

Si vous plait Comment rediriger au page précédente aprés connecté au compte !?

Edited by Marwa Abdelkader (see edit history)
Link to comment
Share on other sites

Si vous plait Commentaire rediriger au page précédente aprés connecté au compte !?

On 27/05/2021 at 23:37, w3bsolutions said:

Comme promis, ci-joint un module simple que j'ai fait pour rediriger le client vers n'importe quelle page après s'être connecté. Il suffit de mettre l'URL vers laquelle vous souhaitez rediriger dans les paramètres du module : 

  • Il peut être relatif, comme dans votre cas pour la page d'accueil : index.php
  • Ou il peut être absolu, n'importe quelle URL telle que : https://www.google.com 

Vous pouvez annuler votre modification de la classe de base et cela fonctionnera toujours :)

w3b_redirectonlogin.zip 7,95 Ko · 8 téléchargements

Si vous plait Comment rediriger au page précédente aprés connecté au compte !?

Link to comment
Share on other sites

Simple;
First find

'my_account_url' => $link->getPageLink('my-account', true),

in ---> "/modules/ps_customersignin/ps_customersignin.php" file and change 'my-account' to "authentication" 

Turkish => 

Basit;
İlk olarak aşağıdaki satırı

'my_account_url' => $link->getPageLink('my-account', true),

bu dosya içinden ---> "/modules/ps_customersignin/ps_customersignin.php" bulun ve  'my-account' ı bununla değiştirin > "authentication" 

 

Edited by Murat Kezli (see edit history)
Link to comment
Share on other sites

English => Ok,  well you can "Disable non PrestaShop modules" in Performance and try agin please

Turkish => Tamam, o zaman  PrestaShop'a ait olmayan modülleri Menu / Advanced / Performance içinden devre dışı bırak tekrar deneyebilir misin?

Link to comment
Share on other sites

@Murat Kezli 

Hello

Hello no does not work  always when I connect it brings me back to the "my-account" page

This is code of /ps_customersignin.php

"

<?php

/**

 * Copyright since 2007 PrestaShop SA and Contributors

 * PrestaShop is an International Registered Trademark & Property of PrestaShop SA

 *

 * NOTICE OF LICENSE

 *

 * This source file is subject to the Academic Free License 3.0 (AFL-3.0)

 * that is bundled with this package in the file LICENSE.md.

 * It is also available through the world-wide-web at this URL:

 * https://opensource.org/licenses/AFL-3.0

 * If you did not receive a copy of the license and are unable to

 * obtain it through the world-wide-web, please send an email

 * to [email protected] so we can send you a copy immediately.

 *

 * DISCLAIMER

 *

 * Do not edit or add to this file if you wish to upgrade PrestaShop to newer

 * versions in the future. If you wish to customize PrestaShop for your

 * needs please refer to https://devdocs.prestashop.com/ for more information.

 *

 * @author    PrestaShop SA and Contributors <[email protected]>

 * @copyright Since 2007 PrestaShop SA and Contributors

 * @license   https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)

 */

 

use PrestaShop\PrestaShop\Core\Module\WidgetInterface;

 

if (!defined('_PS_VERSION_')) {

    exit;

}

 

class Ps_CustomerSignIn extends Module implements WidgetInterface

{

    private $templateFile;

 

    public function __construct()

    {

        $this->name = 'ps_customersignin';

        $this->author = 'PrestaShop';

        $this->version = '2.0.3';

        $this->need_instance = 0;

 

        parent::__construct();

 

        $this->displayName = $this->getTranslator()->trans('Customer "Sign in" link', [], 'Modules.Customersignin.Admin');

        $this->description = $this->getTranslator()->trans('Adds a block that displays information about the customer.', [], 'Modules.Customersignin.Admin');

        $this->ps_versions_compliancy = ['min' => '1.7.1.0', 'max' => _PS_VERSION_];

 

        $this->templateFile = 'module:ps_customersignin/ps_customersignin.tpl';

    }

 

    public function getWidgetVariables($hookName, array $configuration)

    {

        $logged = $this->context->customer->isLogged();

 

        if ($logged) {

            $customerName = $this->getTranslator()->trans(

                '%firstname% %lastname%',

                [

                    '%firstname%' => $this->context->customer->firstname,

                    '%lastname%' => $this->context->customer->lastname,

                ],

                'Modules.Customersignin.Admin'

            );

        } else {

            $customerName = '';

        }

 

        $link = $this->context->link;

 

        return [

            'logged' => $logged,

            'customerName' => $customerName,

            /*

            * @deprecated

            */

            'logout_url' => $link->getPageLink('index', true, null, 'mylogout'),

            /*

            * @deprecated

            */

            'my_account_url' => $link->getPageLink('authentication', true),

        ];

    }

 

    public function renderWidget($hookName, array $configuration)

    {

        $this->smarty->assign($this->getWidgetVariables($hookName, $configuration));

 

        return $this->fetch($this->templateFile);

    }

}

 

"

Link to comment
Share on other sites

There is nothing in ps_customersignin module that you can change to redirect the user to the previous page after login. It is not easy to do that because once the user logged in, the previous page is the login form, so what you would need is the page before... You need several changes in the code for that. It's not a 1 line change.

  • Thanks 1
Link to comment
Share on other sites

  • 3 months later...
  • 1 month later...
On 6/30/2021 at 12:09 PM, Marwa Abdelkader said:

Hello,

problem solving

In prestashop 1.7.5

on access / themes / templates / customer / _partials / login-form addition in the button sign in "<input type =" hidden "class =" hidden "name =" back "value =" {$ smarty.server.HTTP_REFERER} "/> {ls = 'Login' d = 'Shop.Theme .Actions'} "

Best solution by far.  Just for others, the code a little cleaned up, so you do not get a smarty parsing error:

Redirect to previous page

        <input type="hidden" class="hidden" name="back" value="{$smarty.server.HTTP_REFERER}" />


Redirect to home page

        <input type="hidden" class="hidden" name="back" value="/" />


 

 

Edited by seyi (see edit history)
Link to comment
Share on other sites

  • 7 months later...
On 5/27/2021 at 11:37 PM, w3bsolutions said:

As promised, attached is a simple module I did to redirect the customer to any page after logging in. Just put the URL you want to redirect to in the module settings: 

  • It can be relative, as in your case for the homepage: index.php
  • Or it can be absolute, any URL such as : https://www.google.com 

You can undo your change to the core class and it will still work :)

w3b_redirectonlogin.zip 7.95 kB · 81 downloads

 

Thank you for the module, very elegant way to solve things in PrestaShop.

 

Sad to see that a simply redirection of 1 line of code in the core would need so many lines in order to fix it😂

Works like a charm for PS 1.7.8.7

Link to comment
Share on other sites

  • 9 months later...
On 12/4/2021 at 9:14 PM, seyi said:

Best solution by far.  Just for others, the code a little cleaned up, so you do not get a smarty parsing error:

Redirect to previous page

        <input type="hidden" class="hidden" name="back" value="{$smarty.server.HTTP_REFERER}" />


Redirect to home page

        <input type="hidden" class="hidden" name="back" value="/" />


 

 

It worked as it would.

thanks for that.

Link to comment
Share on other sites

  • 4 weeks later...
On 5/27/2021 at 11:37 PM, w3bsolutions said:

As promised, attached is a simple module I did to redirect the customer to any page after logging in. Just put the URL you want to redirect to in the module settings: 

  • It can be relative, as in your case for the homepage: index.php
  • Or it can be absolute, any URL such as : https://www.google.com 

You can undo your change to the core class and it will still work :)

w3b_redirectonlogin.zip 7.95 kB · 138 downloads

This module would be improved. In login checkckout redirect must be for checkout again. There are any way to differentiate 2 login forms? (in authentication & checkout).

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...