Jump to content

Redirect to internal link


Recommended Posts

Hi everyone,

 

I´ve searched the forum and posted in a few topics, but I didn´t had solved this problem:

I want to redirect, after registration, the user to a cms page I´ve made.

I´ve changed AuthController, and pasted after " // if register process is in two steps, we display a message to confirm account creation", but it only works with external links:

Tools::redirect('http://www.google.com');

does not work with content from my domain:

Tools::redirect('cms.php?id_cms=5');

 

Tools::redirect('registsucess.php');

 

Tools::redirect('http://MYDOMAIN.COM');

 

I´ve tried with tinyurl as well, but didn´t work too.

Can someone tell me what´s wrong?

Thanks in advance!!

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

  • 3 weeks later...

I succeeded with this:

$linktoAboutUs = $this->context->link->getCMSLink(4);
Tools::redirect($linktoAboutUs);

It's kind of weird that according to this advice we could use the friendly name of the CMS page, but I couldn't get it to work.

Tried getCMSLink('about-us') and even getCMSLink('About us').

 

And in the link.php class function the $cms parameter is described "can be an ID, but deprecated". This would indicate that we actually SHOULD NOT use an ID.. but how, when it is ALL that works??

/**
* Create a link to a CMS page
*
* @param mixed $cms CMS object (can be an ID CMS, but deprecated)
* @param string $alias
* @param bool $ssl
* @param int $id_lang
* @return string
*/
public function getCMSLink($cms, $alias = null, $ssl = false, $id_lang = null)
Edited by Beluga (see edit history)
Link to comment
Share on other sites

  • 6 months later...

where you pasted this code? everything depends on it ;) i just thing that your code is not executed

If I comment  header("location: http://www.linksite....tration-success"); the script stop on exit, and I view a wite page.

If I not comment the redirect line, the script continue and redirec to access page, I would redirect to specific CMS page

 

Have solutions?

Link to comment
Share on other sites

  • 3 months later...

prestashop 1.6.0.8

 

I Found the solution without modify anything in the presta files.

 

enable ssl and force the ssl on all pages but uncheck html purifier library (very important). you could enable it after insert the image.

 

then go on CMS (exemple: about us) the image who's already there when you install prestashop work well even in ssl so you have to copy how they wrote the code. 

 

<img title="cms-img" src="../img/cms/cms-img.jpg" alt="cms-img" width="370" height="192" />

 

replace by your name image 

 

<img title="your name image" src="../img/cms/your name image.jpg" alt="your name image" width="370" height="192" />

 

write this way on the little popup window [insert/edit image] right after uploaded and chose the image from your file manager.

 

 source             ../img/cms/your name image.jpg

 image description   ....

 dimensions             ...

 

Save it and go to enable the html filter purifier if you done to put new images.

Now it should work. your image is here and your page is still SSL.

 

ps: you'll have to disable html purifier library every time you need to add a new picture from your file manager otherwise it will appear this famous question mark instead of the image and your page won't be SSL

 

It tooks 2weeks to found that, I hope you'll appreciate this post. That's the most annoying bug on prestashop, I don't even know why the Presta team didn't fix that so far!!!!????

 

 

I still have a problem with the homeslider who's disappear when running on Safari, need to refresh the page every time I come back on the home page!!! if somebody have the Solution I'll appreciate to know it ;) thanks

 

vince

Link to comment
Share on other sites

  • 3 years later...
On 7/10/2014 at 6:03 AM, vincent89 said:

prestashop 1.6.0.8

 

I Found the solution without modify anything in the presta files.

 

enable ssl and force the ssl on all pages but uncheck html purifier library (very important). you could enable it after insert the image.

 

then go on CMS (exemple: about us) the image who's already there when you install prestashop work well even in ssl so you have to copy how they wrote the code. 

 

<img title="cms-img" src="../img/cms/cms-img.jpg" alt="cms-img" width="370" height="192" />

 

replace by your name image 

 

<img title="your name image" src="../img/cms/your name image.jpg" alt="your name image" width="370" height="192" />

 

write this way on the little popup window [insert/edit image] right after uploaded and chose the image from your file manager.

 

 source             ../img/cms/your name image.jpg

 image description   ....

 dimensions             ...

 

Save it and go to enable the html filter purifier if you done to put new images.

Now it should work. your image is here and your page is still SSL.

 

ps: you'll have to disable html purifier library every time you need to add a new picture from your file manager otherwise it will appear this famous question mark instead of the image and your page won't be SSL

 

It tooks 2weeks to found that, I hope you'll appreciate this post. That's the most annoying bug on prestashop, I don't even know why the Presta team didn't fix that so far!!!!????

 

 

I still have a problem with the homeslider who's disappear when running on Safari, need to refresh the page every time I come back on the home page!!! if somebody have the Solution I'll appreciate to know it ;) thanks

 

vince

This didnt solve my problem at all..

Link to comment
Share on other sites

  • 6 months later...
  • 2 weeks later...
2 hours ago, lucascaibe said:

can you tell me the solution? I have the same problem.

edit the file /controllers/front/AuthController.php (backup the file before you modify anything)


find below
$should_redirect = false;

add after above
$ggw_should_redirect = false;


find below
if ($hookResult && $register_form->submit()) {
                    $should1_redirect = true;

and replace above with

if ($hookResult && $register_form->submit()) {
                    $ggw_should_redirect = true;

find if clause  if ($should_redirect && !$this->ajax) {
 and after end if clause add below if clause

if ($ggw_should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
    return $this->redirectWithNotifications('address');
            }

            if ($this->authRedirection) {
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }


 

Link to comment
Share on other sites

Quote

 

Hello rmiho, thanks for your help, I try to implement your solution but nothing happen, prestashop still send me to home page after registration, can you ple take a look on my file in order to check if a implement the modifications correctly?

 

 * International Registered Trademark & Property of PrestaShop SA
 */

class AuthControllerCore extends FrontController
{
    public $ssl = true;
    public $php_self = 'authentication';
    public $auth = false;

    public function checkAccess()
    {
        if ($this->context->customer->isLogged() && !$this->ajax) {
            $this->redirect_after = ($this->authRedirection) ? urlencode($this->authRedirection) : 'my-account';
            $this->redirect();
        }

        return parent::checkAccess();
    }

    public function initContent()
    {
        $should_redirect = false;
        $ggw_should_redirect = false;

        if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
            $register_form = $this
                ->makeCustomerForm()
                ->setGuestAllowed(false)
                ->fillWith(Tools::getAllValues())
            ;

            if (Tools::isSubmit('submitCreate')) {
                $hookResult = array_reduce(
                    Hook::exec('actionSubmitAccountBefore', array(), null, true),
                    function ($carry, $item) {
                        return $carry && $item;
                    },
                    true
                );
                if ($hookResult && $register_form->submit()) {
                    $ggw_should_redirect = true;
                }
            }

            $this->context->smarty->assign([
                'register_form'  => $register_form->getProxy(),
                'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop')
            ]);
            $this->setTemplate('customer/registration');
        } else {
            $login_form = $this->makeLoginForm()->fillWith(
                Tools::getAllValues()
            );

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

            $this->context->smarty->assign([
                'login_form' => $login_form->getProxy()
            ]);
            $this->setTemplate('customer/authentication');
        }

        parent::initContent();

        if ($should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
                // Checks to see if "back" is a fully qualified
                // URL that is on OUR domain, with the right protocol
                return $this->redirectWithNotifications($back);
            }

            // Well we're not redirecting to a URL,
            // so...
            if ($this->authRedirection) {
                // We may need to go there if defined
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
         if ($ggw_should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
    return $this->redirectWithNotifications('address');
            }

            if ($this->authRedirection) {
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
    }
}


Thanks in advance, have a nice day

Link to comment
Share on other sites

11 minutes ago, Psarco said:

Hello rmiho, thanks for your help, I try to implement your solution but nothing happen, prestashop still send me to home page after registration, can you ple take a look on my file in order to check if a implement the modifications correctly?

 

 * International Registered Trademark & Property of PrestaShop SA
 */

class AuthControllerCore extends FrontController
{
    public $ssl = true;
    public $php_self = 'authentication';
    public $auth = false;

    public function checkAccess()
    {
        if ($this->context->customer->isLogged() && !$this->ajax) {
            $this->redirect_after = ($this->authRedirection) ? urlencode($this->authRedirection) : 'my-account';
            $this->redirect();
        }

        return parent::checkAccess();
    }

    public function initContent()
    {
        $should_redirect = false;
        $ggw_should_redirect = false;

        if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
            $register_form = $this
                ->makeCustomerForm()
                ->setGuestAllowed(false)
                ->fillWith(Tools::getAllValues())
            ;

            if (Tools::isSubmit('submitCreate')) {
                $hookResult = array_reduce(
                    Hook::exec('actionSubmitAccountBefore', array(), null, true),
                    function ($carry, $item) {
                        return $carry && $item;
                    },
                    true
                );
                if ($hookResult && $register_form->submit()) {
                    $ggw_should_redirect = true;
                }
            }

            $this->context->smarty->assign([
                'register_form'  => $register_form->getProxy(),
                'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop')
            ]);
            $this->setTemplate('customer/registration');
        } else {
            $login_form = $this->makeLoginForm()->fillWith(
                Tools::getAllValues()
            );

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

            $this->context->smarty->assign([
                'login_form' => $login_form->getProxy()
            ]);
            $this->setTemplate('customer/authentication');
        }

        parent::initContent();

        if ($should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
                // Checks to see if "back" is a fully qualified
                // URL that is on OUR domain, with the right protocol
                return $this->redirectWithNotifications($back);
            }

            // Well we're not redirecting to a URL,
            // so...
            if ($this->authRedirection) {
                // We may need to go there if defined
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
         if ($ggw_should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
    return $this->redirectWithNotifications('address');
            }

            if ($this->authRedirection) {
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
    }
}


Thanks in advance, have a nice day

What version of prestashop you running? I see your contents identical to mine. Do you have a dev/demo site? Did you clear the cache?

Link to comment
Share on other sites

  • 5 weeks later...
  • 8 months later...
  • 4 months 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

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

  • 1 month later...
On 1/25/2019 at 5:40 AM, Psarco said:

Hello rmiho, thanks for your help, I try to implement your solution but nothing happen, prestashop still send me to home page after registration, can you ple take a look on my file in order to check if a implement the modifications correctly?

 

 * International Registered Trademark & Property of PrestaShop SA
 */

class AuthControllerCore extends FrontController
{
    public $ssl = true;
    public $php_self = 'authentication';
    public $auth = false;

    public function checkAccess()
    {
        if ($this->context->customer->isLogged() && !$this->ajax) {
            $this->redirect_after = ($this->authRedirection) ? urlencode($this->authRedirection) : 'my-account';
            $this->redirect();
        }

        return parent::checkAccess();
    }

    public function initContent()
    {
        $should_redirect = false;
        $ggw_should_redirect = false;

        if (Tools::isSubmit('submitCreate') || Tools::isSubmit('create_account')) {
            $register_form = $this
                ->makeCustomerForm()
                ->setGuestAllowed(false)
                ->fillWith(Tools::getAllValues())
            ;

            if (Tools::isSubmit('submitCreate')) {
                $hookResult = array_reduce(
                    Hook::exec('actionSubmitAccountBefore', array(), null, true),
                    function ($carry, $item) {
                        return $carry && $item;
                    },
                    true
                );
                if ($hookResult && $register_form->submit()) {
                    $ggw_should_redirect = true;
                }
            }

            $this->context->smarty->assign([
                'register_form'  => $register_form->getProxy(),
                'hook_create_account_top' => Hook::exec('displayCustomerAccountFormTop')
            ]);
            $this->setTemplate('customer/registration');
        } else {
            $login_form = $this->makeLoginForm()->fillWith(
                Tools::getAllValues()
            );

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

            $this->context->smarty->assign([
                'login_form' => $login_form->getProxy()
            ]);
            $this->setTemplate('customer/authentication');
        }

        parent::initContent();

        if ($should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
                // Checks to see if "back" is a fully qualified
                // URL that is on OUR domain, with the right protocol
                return $this->redirectWithNotifications($back);
            }

            // Well we're not redirecting to a URL,
            // so...
            if ($this->authRedirection) {
                // We may need to go there if defined
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
         if ($ggw_should_redirect && !$this->ajax) {
            $back = urldecode(Tools::getValue('back'));

            if (Tools::urlBelongsToShop($back)) {
    return $this->redirectWithNotifications('address');
            }

            if ($this->authRedirection) {
                return $this->redirectWithNotifications($this->authRedirection);
            }

            // go home
            return $this->redirectWithNotifications(__PS_BASE_URI__);
        }
    }
}


Thanks in advance, have a nice day

helloo!  yes yes yes! 

for me it worked perfectly, adding exactly this way! thanks to all of you and I hope this works for others as well as it helped me!

thanks! 

Att alex weiss

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