last day (14 days later) » 

2:45 PM
1
A: URL link for custom module in Prestashop 1.6

SarcoMRevert all modify that you have done :). Try this way: For example, this is core module file rootofps/modules/vpages/vpages.php class VPages extends Module { public function __construct(){ $this->name = 'vpages'; $this->author = 'you'; $this->tab = 'front_office_feature...

 
Hi, I have tried it like in your answer, but it doesn't work at all.. I still have the ugly url link.. :(
 
Check if the database it's 'dirty' of your previous tests (ps_meta, ps_meta_lang), remove any override of dispatcher.
 
I don't have any override regarding this topic, so it should be clean right now.. but I don't get it why it's not working..
 
By the way, notice that the url like this mydomain.com/flower-deliveries?id_country=1&country=fran‌​ce&city=paris don't will be 'transformed' in a clearly url.
 
You were right, it works! I forgot to uninstall and then reinstall the module back again! But now, it troughs an error: "is not a valid module name" or if I disable the MODE DEV, it gives me a 404 error.. Do you know why is that?
 
2:45 PM
Check if there are a syntax errors, like vpage instead of vpages, it's a common mistake :)
 
hi! thank you for your help until now
there are no errors..
 
I'm glad to hear that :=
:)
 
can I show you the real pages?
 
Yeah, why not
 
just that maybe you can figure why it is not working
 
2:48 PM
ok ;)
 
this is the page container for all the countries list
 
ok
 
and they should appear as: /flower-deliveries-1-germany.html
all links should be like that
sorry
without the city here
but if I use the route as you showed me
it will give me a error
 
how do you 'create' the link under the flags?
 
$link->getModuleLink('vpages', 'dpage',
$params)|escape:'html':'UTF-8'}
that's how
they are in a different tpl file
 
2:51 PM
mmm, let me think a minute..
 
i have 2 tpl files, vpage.tpl and dpage.tpl
every of them has a different controller
should I use 2 routes?
 
how many front controllers do you have?
 
2 of them
for this module
vpage controller is responsible for the page I have sent you
and the other one is responsible for the city as well
 
ok, I understand
now I'm in a 'city' europeanflora.com/module/vpages/… and it works, the problem it's that you don't have a clearly url?
 
exactly
they work ok
but they are not clean urls
:(
and I thought that with a single route I can change both pages
 
2:57 PM
ok, maybe you have to make an override of dispatcher or of Link class, but if I remember correctly the dispatcher generate the url
give me a minute, i'll check a thing
 
ok
look, right now, the links are friendly url but don't work.. :(
 
but flower-deliveries how controller is?
dpage?
 
no
vpages
 
have you set in a moduleRoutes hook? or in backoffice?
 
I have 2 controller:
vpages -> flowers-world
dpage -> flower-deliveries
 
3:05 PM
You have to set at least in one of them :)
yes
 
what do you mean by setting in a moduleRoutes
?
 
for dpage we have wrote a rule in the hook, but for vpages?
in hookModuleRoutes() function
 
vpages has a url page inside backoffice
flowers-world
and is linked to the controller vpages
 
okok, I see now
flower-deliveries is dpage
 
exactly
and based on the parameters it will display a list of cities or a single city
if city is set, it will show the city page other ways it will display a list of all cities from that country
it's a simple if inside the tpl file
 
3:10 PM
but when I click on a flag I have 404, I guess it's because the city it's not set as parameter
ok, I understand
mmm no... it's strange
 
no, it's not that
I can enable the mode dev
to see the exact error
"is not a valid module name."
that's the single line of error
 
ok, disable the url rewriting
 
check that link, it's a country page link
done
it's disabled
 
how I can reach the flag page?
 
and I have one error
miss required parameter "city" for route "module-vpages-dpage"
it's because I use the routee like this:
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
 
3:15 PM
yes :) it's clear
 
but, if I use it like:
'country' => array('regexp' => '[\w]+'), it will work
and that happens also for id_country and city
 
Ok, wait, to avoid conflicts change the name of controller 'vpages'
 
one moment please
to modify them
 
;)
 
3:29 PM
:(
and it gives me one error
damn
it works now
but still with the same error
so, there were no conflicts, right?
it has to be something else
..
 
yeah.. mmm.
 
vpages controller is now called countrypages
just to have an accurate naming conveention
and is responsible only for the page with the flags
 
but... the error is in 'module-vpages-dpage'
and i think is in the line of code of smarty
$link->getModuleLink etc etc
 
            {assign var=params value=[
                'module_action' => 'list',
                'id_country'=> $page.id_country,
                'country'=> $page.country,
                'setCountry'=> $page.id_country
            ]}
<a style="color:normal" href="{$link->getModuleLink('vpages', 'dpage',
$params)|escape:'html':'UTF-8'}" title="{$meta_title|escape:'html':'UTF-8'}">
<img width="98" height="70" src="{$modules_dir}/vpages/flags/{$page.country}.png" style="padding-right: 3px;" />
<br />
{$page.country|escape:'html':'UTF-8'}
</a>
 
it wants city
 
3:34 PM
that's how I build the list of flags
and the page with error is this one, the flags one
 
okok, but it wants city mandatorily :)
 
yes, because in the route
 
it says it's required
 
we have them all mandatory
                'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
                'city' => array('regexp' => '[\w]+', 'param' => 'city'),
                'country' => array('regexp' => '[\w]+', 'param' => 'country'),
 
yeah
 
3:35 PM
and I don't know how to say they are optional
 
switch city with country
and try this:

{assign var=params value=[
'module_action' => 'list',
'id_country'=> $page.id_country,
'country'=> $page.country,
'city' => null,
'setCountry'=> $page.id_country
]}
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
 
it works
:)
but the next step it's not working..
 
yeah, i see
you have to add the module name
 
?fc=module&id_country=230&country=Albania&controller=dpage
 
3:38 PM
where?
 
it's missing the module name?
?fc=module&module=vpages&id_country=230&country=Albania&controller=dpage
 
yes it works like that
but where in the route should I put that?
 
how do you made the link? like before?
 
$link->getModuleLink etc etc?
 
3:41 PM
and also, in the route I have this
'module' => array('regexp' => 'vpages', 'param' => 'module'),
so I am passing the module name
:(
 
mmm
 
but it's not placed as a url parameter
it's in the keywords array
 
paste here the hookModuleRoutes
 
public function hookModuleRoutes($params){
    $my_link = array(
        'module-vpages-dpage' => array(
            'controller' => 'dpage',
            'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
            'keywords' => array(
                'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
                'setCountry' => array('regexp' => '[0-9]+', 'param' => 'setCountry'),
                'country' => array('regexp' => '[\w]+', 'param' => 'country'),
 
oh my, what a mess :D
wait
 
3:43 PM
:)
 
you need module_action right?
$my_link = array(
'module-vpages-dpage' => array(
'controller' => 'dpage',
'rule' => 'flower-deliveries{-:id_country}{-:country}{-:city}.html',
'keywords' => array(
'id_country' => array('regexp' => '[0-9]+', 'param' => 'id_country'),
'setCountry' => array('regexp' => '[0-9]+', 'param' => 'setCountry'),
'country' => array('regexp' => '[\w]+', 'param' => 'country'),
'city' => array('regexp' => '[\w]+', 'param' => 'city'),
'module_action' => array('regexp' => '[\w]+', 'param' => 'module_action'),
 
no, but the link is built with it
so I had to put it as well
 
if you don't use it in controller, remove it :)
 
it works!
I already ckecked it with friendly url
:D
 
great ;)
send me 1000€ ahahahah
i'm joking ;)
 
3:48 PM
thank you so much!
 
you're welcome, but now I had to work :D
 
so, basically the problem was inside the route
..
 
yeah :)
 
I still have a lot to learn about PS
thanks again for this course!
;)
 
Never mind ;) have a good day ;)
 
3:49 PM
bye bye!
 

last day (14 days later) »