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

[Prestashop 1.6] Activar la consola de depuración Smarty


La primera en la frente. Ayer se lanzó oficialmente la nueva versión de Prestashop y la primera "gracia" que nos encontramos es que han quitado apropósito la consola de Smarty que a aquellos aventureros con esta plataforma de ecommerce les servía para depurar algunas variables en el motor de plantillas que trae dicha plataforma.

¿Qué les ha llevado a quitarlo? Todavía no lo sabemos, ya que no se trata de un "error", si no de algo que deliberadamente han eliminado en esta primera revisión pública final.

Pero pocas cosas se resisten, y aquí está el método para volver a recuperar dicha funcionalidad.

Lo primero de todo es abrir el fichero que podemos encontrar en:

/controllers/admin/AdminPerformanceController.php

De la función que contiene initFieldsetSmarty() debemos añadir al "fields_forms" los siguientes inputs a los que ya trae por defecto:

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'
    )

En el mismo archivo, debemos buscar la función postProcess() y encontrar el fragmento cerca de la línea 650 aprox. que comienza con if ($this->tabAccess['edit'] === '1'). Podemos observar como actualiza dos variables de configuración, el SMARTY_FORCE_COMPILE y el SMARTY_CACHE, pero nos faltan los dos para la consola. En el siguiente framento de código vienen las dos líneas que se añaden dentro del bloque completo

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;
}

El siguiente fichero a modificar es:

/config/smarty.config.inc.php

Por encima de la línea que tiene el siguiente comentario /* Use this constant if you want to load smarty without all PrestaShop functions */ debemos poner el siguiente fragmento de código.

// 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;

El último fichero a modificar sería:

/tools/smarty/sysplugins/smarty_internal_templatebase.php

Búscamos por el comentario // display or fetch que estará cerca de la línea 305, y cambiamos el condicional if($display), por el siguiente código:

// display or fetch
if ($display || strpos($template->template_resource,'global.tpl')!==false) {


Si volvemos al backoffice veremos que ya por fin aparece otra vez toda la configuración de la consola.

Una cosa a destacar, es que cuando navegamos con la URL, una vez que pongamos el parámetro de SMARTY_DEBUG (o el que decidamos), nos crea una cookie que ya siempre hace que sea visible la consola en esa sesión de navegador. Para quitar la cookie, o la borramos a mano, o ponemos el parámetro http://nuestratienda.com/?SMARTY_DEBUG=off

miércoles, 15 de enero de 2014

[Tutorial] Excel a XML

Puedes convertir tu archivo Excel a un XML, o viceversa. Esto te permite intercambiar datos entre distintas aplicaciones. Para empezar, habilita la pestaña de 'Desarrollador' en tu Excel;

Esta es la información que queremos convertir a XML:


Excel File