Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5522

Custom URL in PrestaShop

$
0
0

In this blog, we are going to learn how to show custom URL in PrestaShop using hook moduleRoutes. With the help of moduleRoutes hook we can also create custom rules for module URL’s.

If module is using front controller then it generates URL’s according to the below rule

module/{module}{/:controller}

For instance, the controller demo of the module demo_module will have the address:

module/demo_module/demo

But in Prestashop there is a way to hide the original address of the controller with the help of the hook mоduleRоutes.

Prestashop will use this pattern to compare addresses: module-{module_name}-{controller_name}

public function hookModuleRoutes() {
    return array(
        'module-demo_module-demo' => array( 
            'controller' => 'demo', //front controller name
            'rule' => 'mypage', //the desired page URL
            'keywords' => array(
                'link_rewrite' => array(
                    'regexp' => '[_a-zA-Z0-9-\pL]*', 
                    'param' => 'link_rewrite'
                ),
            ),
            'params' => array(
                'fc' => 'module',
                'module' => 'demo_module', //module name
            )
        ),
    );
}

Using above method PrestaShop, lets you generate custom URL in PrestaShop https://{your_site}/mypage

When ever you open demo_module -> demo controller then the URL will be as https://{your_site}/mypage .

Dispatcher::loadRoutes(), is responsible for loading patterns, will load your custom rule before other rules, therefore the custom rule will have a higher priority than the predefined PrestaShop rule.

That’s all.

If you are facing any issues or doubts in the above process, please feel free to contact us through the comment section.

I would be happy to help.

Also, you can explore our PrestaShop Development Services and a large range of quality PrestaShop Modules.

For any doubt contact us at support@webkul.com.


Viewing all articles
Browse latest Browse all 5522

Trending Articles