I developed a custom module for Prestashop, and I have some issues regarding the friendly url parameters retrieval. If I disable the friendly url, everything works as supposed, but whenever I try with friendly url it doesn't work
So, the problem is the following:. I have a friendly url link just like the one below:
domain.com/22-flower-delivery-Hong+Kong.html
and the other link:
domain.com/22-flower-delivery-Hong+Kong-Sai+Kung.html
The first link gets a country page and the other one is showing a city inside that country.
The route in Prestashop is done like below:
$my_link = array(
'module-vpages-dpage' => array(
'controller' => 'dpage',
'rule' => '{id_country:-}flower-delivery{-: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' => '[_a-zA-Z0-9\pL\pS-]*', 'param' => 'city'),
'module_action' => array('regexp' => '[\w]+', 'param' => 'module_action')
),
'params' => array(
'fc' => 'module',
'module' => 'vpages'
)
)
);
The main issue is that this works if the country or the city has a single word as name, but if there are 2 words (Hong Kong, New Zeeland, etc) then it will crash. A am using urlencode() and decode just to be sure that everything is passed ok but still with no luck.
Could someone help sort it out?
Related
A similar question was posted here before but it only applied to an On-Site SugarCRM instance (it was also a long time ago).
In my case I would like to change the "Billing Country" field from 'TextField' to 'DropDdown' on an On-Demand instance where I don't have access to the config files. How can I do this?
So far I have tried different PHP files using the Module Loader but it's not working either.
Please find my PHP script below:
<?php
$manifest = array(
'acceptable_sugar_flavors' => array('CE', 'PRO', 'CORP', 'ENT', 'ULT'),
'acceptable_sugar_versions' => array(
'exact_matches' => array(),
'regex_matches' => array(
0 => '6\\.5\\.(.*?)',
1 => '6\\.7\\.(.*?)',
2 => '7\\.2\\.(.*?)',
3 => '7\\.2\\.(.*?)\\.(.*?)',
4 => '7\\.5\\.(.*?)\\.(.*?)',
5 => '7\\.6\\.(.*?)\\.(.*?)'
),
),
'name' => 'Textfield to Dropdown',
'description' => 'Converting Billing Country textfield to Dropdown Field',
'author' => 'myname',
'icon' => '',
'is_uninstallable' => true,
'published_date' => '2015-01-09 19:00:00',
'type' => 'module',
'version' => '1.0',
);
$dictionary['Account']['fields']['billing_address_country']['type'] = 'enum';
$dictionary['Account']['fields']['billing_address_country']['ext1'] = 'countries_dom';
The module loads fine but there's no change after a Quick Repair. I have tried with the following variables, as well:
$dictionary['Account']['fields']['billing_address_country']['isDropDown']=yes;
and...
$dictionary['Account']['fields']['billing_address_country']['Options']='countries_dom';
Can anyone tell me what I am doing wrong? I'd appreciate any help or guidance you have. Please advise.
Cheers,
H
P.S. I am using SugarCRM On-Demand Version 7.6.1
You need to create the manifest.php file and have that point to the file(s) you want to copy/upload for customization:
manifest.php:
<?php
$manifest = array(
'built_in_version' => '7.6.1.0',
'acceptable_sugar_versions' =>
array(
0 => '',
),
'acceptable_sugar_flavors' =>
array(
0 => 'PRO',
1 => 'CORP',
2 => 'ENT',
3 => 'ULT',
),
'readme' => '',
'key' => 'SO',
'author' => 'Eric',
'description' => 'Convert Accounts Billing Country TextField to Enum',
'icon' => '',
'is_uninstallable' => true,
'name' => 'TextFieldToDropdownPkg',
'published_date' => '2016-01-10 03:01:01',
'type' => 'module',
'version' => 1452378413,
'remove_tables' => 'prompt',
);
$installdefs = array(
'id' => 'TextFieldToDropdownPkg',
'copy' => array(
0 => array(
'from' => '<basepath>/custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php',
'to' => 'custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php',
),
),
);
Then create:
custom/Extension/modules/Accounts/Ext/Vardefs/custom_billing_address_country.php
<?php
$dictionary['Account']['fields']['billing_address_country']['comments']='Country for primary address';
$dictionary['Account']['fields']['billing_address_country']['group']='primary_address';
$dictionary['Account']['fields']['billing_address_country']['options']='countries_dom';
$dictionary['Account']['fields']['billing_address_country']['type']='enum';
ZIP those files up and use Module Loader.
In my web application I use tabs and load part of the views per Ajax. So it's possible, that I do load the same CGridView multiple times without reloading the page. If that occurs I become duplicate Ajax requests if I use CGridView Filters.
The filters and requests are standard. Following images show those simple filter and 10 GET requests if type the search value once.
Here is the code of Tabs-widget I use:
$this->widget('bootstrap.widgets.TbTabs', array(
'id' => 'thirdPartyCatTabs',
'title' => Translate::t('project', 'Categories'),
'type' => 'tabs',
'placement' => 'top',
'events' => array(
'shown' => 'js:loadContent'
),
'tabs' => array(
array(
'id' => 'standardCat',
'label' => Translate::t('project', 'Standard Categories'),
'linkOptions' => array(
'data-tab-url' => Yii::app()->createUrl('/thirdParty/settings/thirdPartyCategoryStandard'),
),
),
array(
'id' => 'standardCatMap',
'label' => Translate::t('project', 'Standard Category-Mapping'),
'linkOptions' => array(
'data-tab-url' => Yii::app()->createUrl('/thirdParty/settings/showCategoryMapTab'),
),
),
)
));
I guess I have to use uniqid() at some place, but can't figure out where.
Thanks.
I need to create a router configuration in Zend Framework 2 like:
http://www.example.com/en
http://www.example.com/fr
http://www.example.com/es
Then the route of the modules like my "cms" module must match:
http://www.example.com/en/cms/test.html (english version)
http://www.example.com/fr/cms/test.html (french version)
http://www.example.com/es/cms/test.html (spanish version)
of course this link must match the english default language:
http://www.example.com/cms/test.html (english version)
I have already used the SimLocale without success because it doesn't handle the asset links as well. So I prefer to handle the language selection manually by a simple parameter for all my custom modules.
The question has been solved on #zftalk IRC today (thanks Michelangelo to contribute back based one what we explained to you...).
To solve the problem, we had to have a look at the defined routes:
'router' => array(
'routes' => array(
'language' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/:lang]',
'defaults' => array(
'__NAMESPACE__' => 'Cms\Controller',
'controller' => 'Index',
'action' => 'page',
'lang' => 'en',
'slug' => 'homepage'
),
'constraints' => array(
'lang' => '[a-z]{2}'
)
),
'may_terminate' => true,
'child_routes' => array(
'list' => array(
'type' => 'Segment',
'options' => array(
'route' => '/cms',
'defaults' => array(
'__NAMESPACE__' => 'Cms\Controller',
'controller' => 'Index',
'action' => 'index',
'page' => 1
),
),
),
'page' => array(
'type' => 'Segment',
'options' => array(
'route' => '[/:slug].html',
'constraints' => array(
'slug' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'action' => 'page',
),
),
),
'search' => array(
'type' => 'Segment',
'options' => array(
'route' => '/search/[query/:query]',
'constraints' => array(
'query' => '[a-zA-Z][a-zA-Z0-9_-]*',
),
'defaults' => array(
'action' => 'search',
'query' => null,
),
),
),
'paginator' => array(
'type' => 'Segment',
'options' => array(
'route' => '/list/[page/:page]',
'constraints' => array(
'page' => '[0-9]*',
),
'defaults' => array(
'page' => 1,
),
),
),
),
),
Then, the updated description of the problem was the following:
mikunos: http://www.example.com/en (homepage) this is ok
mikunos: http://www.example.com/en/cms (cms list) this is ok
mikunos: http://www.example.com/en/cms/about.html (page) this not
Which have led us on changing the 'page' route as a child route of 'list' (/cms).
Then the discussion finished with indications on what to do to setup the default language if none have been selected:
mikunos: as you have seen I need two main routes
mikunos: the first one is /lang/module and the second one is /module
mikunos: so I have to create two branches
mikunos: right?
tdutrion: you may want to use an url rewriting or something here
tdutrion: I would go for a redirect 301 from /module to /en/module so you have no duplicate content
tdutrion: and then no route can be accessed without a language
mikunos: ok
tdutrion: you can do it different ways, but I think the best one would be creating a event listener and do that before routing
tdutrion: you can also do it in your .htaccess of you are using apache, but then what if you migrate to IIS or Ngnix or else...
mikunos: interesting
tdutrion: again I believe Jurian Sluiman’s code does that
You can use subdomains for each language you need witch I suppose you don't want or you really don't need (eg. /en) to change the language of your application and/or web site. Is mandatory to use /en, /fr, etc.?
I am trying to solve the routing problem I am facing right now with no luck (googled for hours, saw dozens of examples and solved questions but none works for me - the closest one is this Routing Zend Framework 2 Language in url but even this is not working for me).
I have created an SSO application (I mean the authentication part) and now I am porting it to ZF2 app (I have it almost working as I workarounded the router but need now the final routing to be done) where only these types of URLs are possible:
http[s]://domain.com/login/asfgsdgdsfgzsdgdsf/
http[s]://domain.com/login/tdhjsdgbndfnfgdnhd/
http[s]://domain.com/logout/asfgsdgdsfgzsdgdsf/
http[s]://domain.com/info/dthnzdfbdfhgnfsd/
Those login, logout or info parts are not the controllers nor actions but the methods names I then call on SSO service from within my IndexController and indexAction(). The rest part of the URL is the client application hash.
Now here is my router config which only matches the home route and when the other parts (method name [and hash]) are provided, I got 404 from the ZF2 app (so at least I am in the app context).
return array(
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'SSO\Controller\Index',
'action' => 'index',
'act' => 'login', // by doing this I am able to workaround the router and work with SSO
'client' => '<my_secret_hash>', // by doing this I am able to workaround the router and work with SSO
),
),
'child_routes' => array(
'action' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '[/:act]',
'defaults' => array(
'act' => 'login',
),
'constraints' => array(
'act' => '(login|logout|info)?', // only login, logout or info are allowed
),
),
'child_routes' => array(
'client' => array(
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '[/:client]',
'constraints' => array(
'client' => '[a-zA-Z0-9]+',
),
'defaults' => array(
'client' => '<my_secret_hash>',
),
'may_terminate' => true,
),
),
),
),
),
),
),
);
(only router part of my module.config is provided...)
Now with that router only http[s]://domain.com[/] is matched and either of http[s]://domain.com/(login|logout|info)[/] or http[s]://domain.com/(login|logout|info)/adfbsDVdfbzdbxfbndzxbxfnb[/] matches into A 404 error occured.
Though I try to define the route parts as optional (just for the testing and development purposes), they should by required in the production environment. Anyway, I tried to define them NOT optional too, but didn't work either.
Question: How should I configure the router to match my routes (URLs) defined in the beginning?
Couple of things:
My guess is that you have too many slashes in there -- a child route of / doesn't need to be defined with a slash at the beginning since it's parent already got it
I don't see a reason for 2 nested routes (of course I don't know the rest of your config, so it's a guess)
home route probably should be Literal and able to terminate (again a guess)
there was one unmatched parenthesis (probably 'misspasted' or something)
I suppose this should work for you:
'router' => array(
'routes' => array(
'home' => array(
'type' => 'Literal',
'may_terminate' => true,
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'SSO\Controller\Index',
'action' => 'index',
),
),
'child_routes' => array(
'whateva' => array(
'type' => 'Segment',
'may_terminate' => true,
'options' => array(
'route' => '[:act[/:client]]', // as Sam suggested
'defaults' => array(
'act' => 'login',
'client' => 'fsadfasf32454g43g43543',
),
'constraints' => array(
'act' => '(login|logout|info)',
'client' => '[a-zA-Z0-9]+',
),
),
),
),
),
),
),
i need to route urls like in zf1.
in particular i need that these urls will be automatically redirect to appropriate actions without specify a new route every time.
/site/getData
/site/getData?param=5&par2=test
/site/getOther
...
So a segment route doesn't work, i've tried a Literal route but i can't reach a working solutions.
Anyone can help me?
Thanks a lot
This should be solved by a pretty default segment route like the one provided in the documentation.
'type' => 'Zend\Mvc\Router\Http\Segment',
'options' => array(
'route' => '/:controller[/:action]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]+',
'action' => '[a-zA-Z][a-zA-Z0-9_-]+',
),
'defaults' => array(
'controller' => 'default-controller-alias',
'action' => 'index',
),
)
Now if you set up your controller names like the following:
'controllers' => array(
'invokables' => array(
'sites' => 'Namespace\Controller\SitesController',
'other' => 'Namespace\Controller\OtherController'
Then you should be able to achieve exactly what you want. And to create params to your route, you simply use the ViewHelper correctly ;)
$this->url('routename',
array(
'controller' => 'site',
'action' => 'getData'
),
array (
'query' => array(
'param1' => 'foo',
'param2' => 'bar',
'paramN' => 'baz',
)
)
)