## martes, 18 de marzo de 2014

### [Prestashop 1.6][Guide] Enable Smarty Console on the new Prestashop 1.6

This could not have started worse!. Yesterday was launched the new "awesome" Prestashop version called Prestashop 1.6, and the first "bug" we found is that the Smarty Console (used to debug all the templates) was removed intentionally.

We don't know if this movement is part of have more blessing for the "official" web agencies that paid for the "Prestashop Seal", but this is not exception and we can serve one more time to the community.

On the initFieldsetSmarty() function we must add to the "fields_forms" variable the next code:

array(
'label' => $this->l('Smarty Console'), 'name' => 'smarty_console', 'values' => array( array( 'id' => 'smarty_console_2', 'value' => 2, 'label' =>$this->l('Always display'),
'hint' => $this->l('This option should be used in a production environment.') ), array( 'id' => 'smarty_console_1', 'value' => 1, 'label' =>$this->l('Display through URL'),
'hint' => $this->l('It should be used in a production environment when you need debug.') ), array( 'id' => 'smarty_console_0', 'value' => 0, 'label' =>$this->l('Never display'),
'hint' => $this->l('Not display.') ) ) ), array( 'type' => 'text', 'label' =>$this->l('Smarty Console Key'),
'name' => 'smarty_console_key'
)


On the same file, search for postProcess() function and near the line 650 aprox. that start with if ($this->tabAccess['edit'] === '1'). We can see how the function update two "config" variables, SMARTY_FORCE_COMPILE y el SMARTY_CACHE, but the two for the Smarty console are missing. On the next you can find the complete code block: if ($this->tabAccess['edit'] === '1')
{
Configuration::updateValue('PS_SMARTY_FORCE_COMPILE', Tools::getValue('smarty_force_compile', _PS_SMARTY_NO_COMPILE_));
Configuration::updateValue('PS_SMARTY_CACHE', Tools::getValue('smarty_cache', 0));
Configuration::updateValue('PS_SMARTY_CONSOLE_KEY',Tools::getValue('smarty_console_key','SMARTY_DEBUG'));
Configuration::updateValue('PS_SMARTY_CONSOLE', Tools::getValue('smarty_console', 0));
$redirectAdmin = true; }  /config/smarty.config.inc.php On this file we need to paste the next code block above the comment that says /* Use this constant if you want to load smarty without all PrestaShop functions */ near the 40th line. // Production mode$smarty->debugging = false;
$smarty->debugging_ctrl = 'NONE'; if (Configuration::get('PS_SMARTY_CONSOLE') == _PS_SMARTY_CONSOLE_OPEN_BY_URL_) {$smarty->debugging_ctrl = 'URL';
$smarty->smarty_debug_id = Configuration::get('PS_SMARTY_CONSOLE_KEY'); } else if (Configuration::get('PS_SMARTY_CONSOLE') == _PS_SMARTY_CONSOLE_OPEN_)$smarty->debugging = true;


/tools/smarty/sysplugins/smarty_internal_templatebase.php

Search for the commentary // display or fetch that is near over 350 line, and change the conditional if($display), to the next code: // display or fetch if ($display || strpos($template->template_resource,'global.tpl')!==false) {  If we go back to the backoffice, we can see that the options are recovered. One more thing. If we go throug "URL", once we put SMARTY_DEBUG (or what you decide), the system make a "cookie" that always open the Smarty Console. You can erase the cookie or put the next parameter on the URL: http://ourshop.com/?SMARTY_DEBUG=off #### 7 comentarios: 1. Hi Dani, Thanks for the writeup, and for translating it to English. FYI, I use an alternative method that you might find interesting... one that doesn't change the core code (and doesn't try to imitate 1.5). The article can be found here: http://rocinantesoftware.blogspot.com.es/2015/07/prestashop-16-smarty-debug-console.html 1. User must do hard code to disable functionality in production upon your method however in this tutorial users can disable UI simply just using UI controsl. 2. Nice tutorial :) 3. I just found this tutorial but it doesn't work for me (PS 1.6.1.24). I throws this error: Notice on line 320 in file D:\home\to161\domains\to161.nl\public_html\tools\smarty\sysplugins\smarty_internal_templatebase.php [8] Trying to get property of non-object Any idea how I can solve that? 1. Hi @Toeareg, As this is very old now, maybe the template files changed also over time on the most recent v1.6.X versions, so I recommend you to try simply to put the {debug} smarty piece of code directly on your tpl to display the toolbox. You can follow this another tutorial about this if it's works: http://rocinantesoftware.blogspot.com.es/2015/07/prestashop-16-smarty-debug-console.html 2. Thanks for you reply. Problem is that the {debug} command does not format the output in a properly readable format. Especially the objects and arrays are unreadable due to the lack of formatting. 3. I was trying to get your code to work and I noticed that the object name has changed from$template to \$_template
With the underscore in place, the error message is gone.

Now I need to find out why it does not open a new window but appends all debug info (unformatted) to the end of the page like {debug} does.

If you have any suggestion where I would have to look, that would be great.