Jump to content

Edit History

Pedram

Pedram

Hmm, How are you creating these myshop.com/specialBlogPage  urls ?

if they are CMS pages, IIRC there should be some built-in feature in the Prestashop to redirect them to your custom URL.

 

But instead, if you are creating them using your module controller,  like the content of the page might change depend on the parameters value,

For example controller is "Blog",  and parameter is "Page" and value is "special" then it will open your special blog page.

Then you can add routes using "moduleRoutes" in your module for them.

First, Make a module or go to this link to generate a simple one : https://validator.prestashop.com/generator

Second, Add this Hook to the install section :

$this->registerHook('moduleRoutes')

Third, Add this section to your module code in same file (YourModuleName.php) as the install section above :

public function hookModuleRoutes($params){
      $my_routes = array(
		'YourRouteName1' => array(
              'controller' => 'NameOfController1',
              'rule' => 'blog/{id}-{name}/',
              'keywords' => array(
                  'id' => array('regexp' => '[\w]+', 'param' => 'id'),
                  'name' => array('regexp' => '[\w]+', 'param' => 'name'),
               ),
               'params' => array(
                   'fc' => 'module',
                   'module' => 'YourModuleName'
               )
           ),
		'YourRouteName2' => array(
              'controller' => 'NameOfController2',
              'rule' => 'branchelets/{id}-{name}',
              'keywords' => array(
                  'id' => array('regexp' => '[\w]+', 'param' => 'id'),
                  'name' => array('regexp' => '[\w]+', 'param' => 'name'),
               ),
               'params' => array(
                   'fc' => 'module',
                   'module' => 'YourModuleName'
               )
           )
		);
		
        return $my_routes;
    }

 

This will make it that instead of

MyShop.com/Modules/YourModuleName/?Controller=NameOfController1&id=43&name=Yes-very-special  (If friendly URL turned on)

Your page will show up as  myshop.com/blog/43-yes-verry-special

Same goes for the 2nd URL.

MyShop.com/Modules/YourModuleName/NameOfController2/id=23&name=saphires-and-ruby-bracelet  --> myshop.com/brachelets/23-saphires-and-ruby-bracelet

Pedram

Pedram

Hmm, How are you creating these myshop.com/specialBlogPage  urls ?

if they are CMS pages, IIRC there should be some built-in feature in the Prestashop to redirect them to your custom URL.

 

But instead, if you are creating them using your module controller,  like the content of the page might change depend on the parameters value,

For example controller is "Blog",  and parameter is "Page" and value is "special" then it will open your special blog page.

Then you can add routes using "moduleRoutes" in your module for them.

First, Make a module or go to this link to generate a simple one : https://validator.prestashop.com/generator

Second, Add this Hook to the install section :

$this->registerHook('moduleRoutes')

Third, Add this section to your module code in same file (YourModuleName.php) as the install section above :

public function hookModuleRoutes($params){
      $my_routes = array(
		'YourRouteName1' => array(
              'controller' => 'NameOfController1',
              'rule' => 'blog/{id}-{name}/',
              'keywords' => array(
                  'id' => array('regexp' => '[\w]+', 'param' => 'id'),
                  'name' => array('regexp' => '[\w]+', 'param' => 'name'),
               ),
               'params' => array(
                   'fc' => 'module',
                   'module' => 'YourModuleName'
               )
           ),
		'YourRouteName2' => array(
              'controller' => 'NameOfController2',
              'rule' => 'branchelets/{id}-{name}',
              'keywords' => array(
                  'id' => array('regexp' => '[\w]+', 'param' => 'id'),
                  'name' => array('regexp' => '[\w]+', 'param' => 'name'),
               ),
               'params' => array(
                   'fc' => 'module',
                   'module' => 'YourModuleName'
               )
           )
		);
		
        return $my_routes;
    }

 

This will make it so

instead of MyShop.com/Modules/YourModuleName/?Controller=NameOfController1&id=43&name=Yes-very-special  (If friendly URL turned on)

Your page will show up as  myshop.com/blog/43-yes-verry-special

Same goes for the 2nd URL.

MyShop.com/Modules/YourModuleName/NameOfController2/id=23&name=saphires-and-ruby-bracelet  --> myshop.com/brachelets/23-saphires-and-ruby-bracelet

×
×
  • Create New...