0

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.

shawndreck
  • 2,039
  • 1
  • 24
  • 30
Tanyio
  • 93
  • 2
  • 6

1 Answers1

1

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

Regards

  • Yes that's what I'm trying to figure out, but I can't make it to at least "overwrite" the original `define('_THEME_NAME_', 'prestashop');`. All my different tries (playing also with `FrontController.php`, `defines.inc.php`) have no effect. Where I can use `$cookie`, I can't switch template. – Tanyio Jan 14 '13 at 16:06
  • Example of last stuff I did in `FrontController.php`: `if (($cookie->alternate) && (_THEME_NAME_ == 'default')) { define('_THEME_NAME_', 'alternate'); echo _THEME_NAME_; die(); }` The echo shows `default`, not `alernate`. It's normal, as this define is already done in `settings.inc.php`, but I hoped I could "re-define" it later. – Tanyio Jan 14 '13 at 16:11
  • You can't overwrite default _THEME_NAME_, because variables assigned with define statement cannot be redefined (without runkit extension - http://php.net/runkit_constant_redefine). But you can remove default define statement from /config/settings.inc.php and define it in another place. – Alexander Simonchik Jan 15 '13 at 09:43