Jump to content

How do i force a redirect after installing my module


danielmoreira

Recommended Posts

Hi,

 

I am developing a module for prestashop.

 

I would like my module to redirect to a admin controller i created once i install the module.

 

By default, if a module has a configuration page generated by the getContent method, it will redirect to this page when the module installed. I want my module to redirect to a different page.

 

Does anyone know how to do this?

 

Thanks for your attention

Link to comment
Share on other sites

  • 4 years later...

I do that in one of mines.

I first declare and leave empty the getContent() method (module main file) :

public function getContent() {}

This will force PrestaShop to display the "configure" button.

Then i plug the module on the "actionDispatcher" hook and add the following code (example) in the hookActionDispatcher() méthod :

public function hookActionDispatcher($args)
{
	if (defined('_PS_ADMIN_DIR_')) {
		if (isset($args['controller_class']) && $args['controller_class'] == 'AdminModulesController') {
			if (Tools::getValue('configure') == '_your_module_name_') {
				$link = new Link();
				Tools::redirectAdmin($link->getAdminLink('_your_controller_tab_name_'));
			}
		}
	}
}

 

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

33 minutes ago, SmartPlugs said:

I do that in one of mines.

I first declare and leave empty the getContent() method (module main file) :


public function getContent() {}

This will force PrestaShop to display the "configure" button.

Then i plug the module on the "actionDispatcher" hook and add the following code (example) in the hookActionDispatcher() méthod :


public function hookActionDispatcher($args)
{
	if (defined('_PS_ADMIN_DIR_')) {
		if (isset($args['controller_class']) && $args['controller_class'] == 'AdminModulesController') {
			if (Tools::getValue('configure') == '_your_module_name_') {
				$link = new Link();
				Tools::redirectAdmin($link->getAdminLink('_your_controller_tab_name_'));
			}
		}
	}
}

 

what if i want to redirect to a diffrant link outside prestashop after the installation of the module directly ?

Link to comment
Share on other sites

Hi kimokimo,

If you have a look on the code i posted i'm sure you gonna find the line that does the redirect, please.
But i'm not sure PrestaShop, addons i mean if your goal is to sell your module on addons, would let  you redirect people to another location after module install...

Yann

Link to comment
Share on other sites

17 hours ago, SmartPlugs said:

Hi kimokimo,

If you have a look on the code i posted i'm sure you gonna find the line that does the redirect, please.
But i'm not sure PrestaShop, addons i mean if your goal is to sell your module on addons, would let  you redirect people to another location after module install...

Yann

hi Yann,

actually i have tried but it didn't work, i have tried doing this code 

       return (parent::install() && this.hookActionDispatcher() );
    }
    public function getContent() {}

    public function hookActionDispatcher()
    {
                    $link = new Link();
                    Tools::redirect('https://mywebsite.com');
    }

but it didn't work unfortunatly, could you help ?

i also tried this code to redirect 

        return (parent::install() && this.header('location: http://www.mysite.com/index.php?pop=yes') );

still no chance

Edited by kimokimo
missing informations (see edit history)
Link to comment
Share on other sites

  • 3 years later...

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