How to Generate a Custom URL in Prestаshоp

June 1, 2015 Alex Simonchik Prestashop
How to Generate a Custom URL in Prestаshоp

If your module is using front controller then it generates URLs according to the below principle.

For instance, the controller “ view ” of the module “ belvg_fаq ” will have the address:

All our modules use the prefix ‘ belvg_ ‘ by default, that is why when generating a controller the end user will see our company name in the browser address bar. Of course, this is quite pleasant for us but not quite good for our users. But in Prestashop there is a way to hide the original address of the controller with the help of the hook “ mоduleRоutes “.

But let’s take a more complicated example with some parameters included.

This method lets you generate addresses with the following structure:

http://{your_site}/view/8-howtomakeorder.html

In addition, the controller Tools::getVаlue( ‘id_view’ ), returns 8.

Unfortunately, this method also has some drawbacks. If you decide to use {id_view} at the end of the address, for example:

http://{your_site}/view/howtomakeorder-8.html,

then Dispatcher::loadRoutes(), that is responsible for loading patterns, will load your custom rule before other rules, therefore the custom rule will have a higher priority than the rule for the product page:

Therefore the customers will not see the product page but will be redirected to the module controller. That is why you should be careful when creating custom rules for module URLs: they should not interfere with the default rules.

Good luck on your work and with new modules :)

Check also: How To Change Header Logo in Prestashop 1.7



Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *