Jump to content
Vitor Brito

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)

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

you should use something like:

$cms = new CMS(2);
$link->getCmsLink($cms);

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites

does anyone have the solution? I am looking a way to redirect to different page as soon as customer click on save button in registration form.

 

thanks

 

Share this post


Link to post
Share on other sites
On 1/13/2019 at 9:57 AM, rmiho said:

figured it out how to redirect to address page after new user register :)

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

Share this post


Link to post
Share on other sites
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__);
        }


 

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

Thanks for the support

 

I'm runing 1.7.4

No, because I don't have able the cache.

and I just have the site where i'm working right now

Share this post


Link to post
Share on other sites

i was using 1.7.5 and just upgraded to 1.7.5.1 but the changes i did were gone. So i added the code again and working as expected

 

 

Share this post


Link to post
Share on other sites

Hi, could you please share the content of the file post edit so can look into it.

 

may be upgrade the store to latest version?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More