Prestashop: switch theme on the fly and read cookie to check param in url

我的未来我决定 提交于 2019-12-13 06:43:47

问题


In order to setup an A/B testing (through GG Analytics), I planned to duplicate my current theme (for organisations purposes) in order to use the duplicated theme to do the alternate versions of the test. I use Prestashop 1.4.9.2 .

What I already did, and works:


Added this to /classes/FrontController.php, in displayHeader() function (I know I should override, but not the point ;)):

if(isset($_GET['alternate']))
{
    $cookie->alternate = "1";
    $cookie->write();
} 

Replaced in /config/settings.inc.php :

define('_THEME_NAME_', 'my_usual_theme');

by

if(isset($_GET['alternate']) || $cookie->alternate == "1")
{
    define('_THEME_NAME_', 'my_alternate_theme');       
}
else
{
    define('_THEME_NAME_', 'my_usual_theme');
} 

This way, when I load my Prestahop url with "?alternate" at the end, it loads the alternative theme. Fine.

PROBLEM: I can't check the cookie value in settings.inc.php, and so when I click a link, it loads the default theme.

QUESTION: Any clue to check the cookie in this file ? Or config.inc.php ? Or "re-define" the theme name in another file, overriding the settings.inc.php setup ?

Please note I check the cookie in another single file to validate the process, and it works well. I also tried to use classic setcookie method, but if I can read/check, I can't write with this way... And for a reason I don't get, PHP activation in Smarty just don't work (tried to setcookie directly in template, but error 500 even with a simple echo).

Thanks.


回答1:


I think that the simplest way is moving define('_THEME_NAME_', 'prestashop'); to place where you can use the global $cookie variable.

Regards



来源:https://stackoverflow.com/questions/14282955/prestashop-switch-theme-on-the-fly-and-read-cookie-to-check-param-in-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!