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.

/controllers/admin/AdminPerformanceController.php

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

array(
 'type' => 'radio',
 '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