Prestashop - Module, SEO & URL and parameters?

prestashop, seo

Solution

you need to hook to moduleRoutes,

1) in your module install method:

if (!parent::install()           
    || !$this->registerHook('moduleRoutes')
    || !$this->registerHook('displayFooter'))
       return false;

2) creating corresponding hook

public function hookmoduleRoutes($params) {
    $routes = array();
    $routes['module-examplemodule-handler'] = array(
        'controller'=>'handler',
        'rule'=>'promo{/:code}',
        'keywords'=>array(
            'code'=>array(
                'regexp'=>'[\w]+',
                'param'=>'short_code'
            )
        ),
        'params'=>array(
            'fc'=>'module',
            'module'=>'examplemodule',
            'controller'=>'handler'
        )
    );

    return $routes;
}

module may have multi routes. the convention is module-[MODULE_NAME]-[MODULE_CONTROLLER_NAME]

array explanation:

controller - handler (modules/examplemodule/controllers/front/handler.php)

rule - curly braces are params.. you can get an idea from http://example.com/admin/index.php?controller=AdminMeta

keywords - here you configure your params (curly braces) defined in the rule.

usage example: http://example.com/promo/ADSGD

in controller 'handler':

$short_code = Tools::getValue('short_code');

tested on prestashop 1.6

reference: https://books.google.co.il/books?id=BsSiBQAAQBAJ&pg=PT134&lpg=PT134&dq=prestashop+module+Routes+hook&source=bl&ots=JCb_4oz6el&sig=JwoQfIsOnJ49VJ752fEb01ivMZ8&hl=en&sa=X&ei=vH0QVePiDoXPaNSxgrAP&ved=0CEIQ6AEwBA#v=onepage&q=prestashop%20module%20Routes%20hook&f=false

Problem

I made a module for Prestashop that will display content based on the given ID in parameter (&id=X). I'd like to set a nice url for this module. Using SEO and URLS, I see that it's possible, but it keeps the ?id=X in the url. For example, if I define the url to my module to be ``` /pretty-module ``` I will have the same links but with the different id : ``` /pretty-module?id=1 /pretty-module?id=23 ``` What I'd like to do, is the following : ``` /pretty-module => will set id to 1 /even-prettier-module => will set id to 23 ``` I didn't saw a "parameters" options in the SEO & URLS page in the Backoffice, so I'm wondering if it's possible to do this.

Original source