Mostrando entradas con la etiqueta developer. Mostrar todas las entradas
Mostrando entradas con la etiqueta developer. Mostrar todas las entradas

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

jueves, 2 de agosto de 2012

[Tutorial] Sencillo chat con Codeigniter (PHP + MySQL + JSON)

Os traigo un pequeño tutorial de como montar un sencillo chat con la ayuda del framework de PHP Codeigniter. Este chat se basará en la tecnología que nos brinda PHP junto a MySQL y recogiendo los datos en objectos JSON para trabajar con ellos de una manera rápida.

Tomaros está guía como una ayuda al resultado que realmente estáis buscando, y no como una guía del chat definitivo, pues tal y como esta contemplado es para un proyecto en el que va incorporado esto, con lo que retocaré la información que os daré para que se ajuste a hacer un chat simple y espero que no se me escape nada. Aun así, si teneis dudas, no temáis en preguntar! En esta guía tampoco pasaré a detallar configuraciones de Codeigniter, ya que la documentación que trae es suficiente para que al menos sepáis configurar la base de datos del proyecto.

Lo primero de todo será crear en nuestro esquema de la base de datos una tabla que pasaremos a llamar "chat_mensaje". Os dejo el script SQL para que solo tengáis que copiar, pegar y ejecutar.

CREATE TABLE  `chat_mensaje` (
  `id_chat_mensaje` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `m_chat_usuario` varchar(15) NOT NULL,
  `chat_mensaje` varchar(140) NOT NULL,
  `creado_en` datetime NOT NULL,
  PRIMARY KEY (`id_chat_mensaje`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1; 

martes, 24 de julio de 2012

[App Inventor] Primeros Pasos


Para los que no lo conozcáis, App Inventor es una plataforma de desarrollo, ahora distribuida libremente por Google, que te permite crear aplicaciones para Android de una manera rápida y sencilla. ¡Y sin necesidad de tener grandes nociones de programación ni tener que configurar un engorroso IDE!

¿Qué como funciona? Muy facil...
Tiene una interfaz visual con la que vas arrastrando los distintos controles a la pantalla de lo que va a ser tu aplicación. Un área de texto, una imagen, una etiqueta, un botón, etc... y todo point&click, sin necesidad de picar una sola linea de código.

Pantalla de paleta de controles de App Inventor
Luego, solo tenéis que arrancar el "Blocks Editor" y con unos simples bloques de código a modo de piezas de puzle podemos recoger los distintos eventos de los controles (por ejemplo del botón tendremos el Click) e ir dando las órdenes para realizar distintas acciones.
Una sencilla acción que hará que al pulsar nuestro botón
escriba "¡Hola Mundo!" en la pantalla.

Si os habéis quedado con ganas de más, os recomiendo que os registréis para poder usar esta aplicación, ya que muy pronto en San Binario iremos colgando tutoriales para hacer fantásticas aplicaciones para poner luego a la venta en el Market. Os esperamos! :)