<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Damián Culotta &#187; Php</title>
	<atom:link href="http://www.damianculotta.com.ar/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.damianculotta.com.ar</link>
	<description>Sería un &#34;bienvenidos a mi&#34;, pero Rozitchner me ganó de mano</description>
	<lastBuildDate>Thu, 05 Jan 2012 09:10:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Cómo crear una clase para el Shell en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/#comments</comments>
		<pubDate>Mon, 25 Apr 2011 07:00:28 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2216</guid>
		<description><![CDATA[Cuando pensamos en módulos para Magento nos quedamos, normalmente, con agregar funcionalidad para el frontend o para el backend. Creo que cuando pensamos en un módulo debemos imaginarnos los cuatro posibles entornos para su aplicación. Por los cuatro entornos me &#8230; <a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Cuando pensamos en módulos para <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/">Magento</a> nos quedamos, normalmente, con agregar funcionalidad para el frontend o para el backend.</p>
<p>Creo que cuando pensamos en un módulo debemos imaginarnos los cuatro posibles entornos para su aplicación. Por los cuatro entornos me refiero:</p>
<ul>
<li>Frontend o tienda propiamente dicha.</li>
<li>Backend o administración.</li>
<li>API.</li>
<li>Consola.</li>
</ul>
<p>Si bien ésta división puede parecer arbitraria, éstas serán las posibles puertas de entrada que normalmente utilicemos (dependiendo sobre si nos toca ser usuario, administrador, desarrollador o el encargado del mantenimiento; o todo).</p>
<p>Claro está que no todos los módulos requieren funcionalidad en los cuatro entornos, pero en muchos casos deberíamos cuidar las formas y proveer de herramientas para cada caso.</p>
<p>En mi caso, desde hace ya un buen tiempo, me ha tocado desarrollar unas cuantas integraciones que importan o exportan información. Normalmente, con procesos manejados a través del Cron de <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/">Magento.</a></p>
<p>Uno de las situaciones con las que nos vamos a encontrar cuando trabajemos con módulos que funcionan con un cronjob, es la de la prueba de ejecución. Está claro que podemos programar la tarea para que se ejecute y esperar a que suceda. Luego de la quinta prueba es muy probable que empecemos a perder un poco la paciencia.</p>
<p>Lo que vamos a ver hoy es cómo crear una clase para el shell respetando el estilo de la plataforma. Si bien podemos hacerlo por fuera de éstos lineamientos, vamos a tratar de ser lo más respetuosos posible. La idea es lograr tener siempre extensiones prolijas para que puedan ser reutilizadas y no nos generen conflictos con otras extensiones (o al menos que esos casos sean los menos posibles).</p>
<p><span id="more-2216"></span>Para seguir con los ejemplos, y partiendo de un punto que cualquiera podría replicar para partir desde el mismo lugar, voy a seguir con mi módulo Dc_Test, creado con el <a title="artículo en la wiki de Magento" href="http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table">generador de módulos</a>.</p>
<p>Ahora bien, nuestro modulito nos provee ya de la grilla y el formulario para cargar datos en el backend.</p>
<p>Más allá que en éste caso no tenemos motivo aparente para tener funcionalidad en la consola, vamos a pasar por alto ésta cuestión y pensemos que necesitamos poder tener información sobre los datos manejados por éste módulo.</p>
<p>Lo primero que tenemos que hacer es crear nuestra clase que, para mantener la lógica, vamos a llamar Dc_Shell_Test y la vamos a guardar en el archivo /shell/test.php.</p>
<p>La versión más simple de nuestra clase contará con dos métodos: run() y usageHelp(). Más allá de lo obvio, el método usageHelp es el que usaremos para brindar información sobre el uso de la clase.</p>
<p>Un ejemplo de su contenido podría ser:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> usageHelp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;USAGE
Usage:  php -f test.php -- [options]
&nbsp;
  --help              This help
&nbsp;
USAGE</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Hasta ahora, dado que nuestra clase no tiene acciones posibles, sólo podemos mostrar que la ayuda nos permite invocar a la ayuda (si, muy <a title="información en IMDB" href="http://www.imdb.com/title/tt1375666/">Inception</a> style).</p>
<p>El otro método posible, en nuestra adolescente clase, es run(). De más está decir que éste es el método que será invocado y que será el responsable de ejecutar la o las acciones que desarrollemos.</p>
<p>Aquí podemos aplicar dos formas para invocar a las acciones.</p>
<p>La primera, para el caso más sencillo, sería la siguiente.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_action'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #666666; font-style: italic;">//Tareas a realizar por la acción my_action</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usageHelp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>En éste momento, nuestra clase se debe ver de la siguiente forma. (Nótese que agregué información en el método usageHelp() para describir nuestra acción).</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Dc_Shell_Test <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_action'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #666666; font-style: italic;">//Tareas a realizar por la acción my_action</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usageHelp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> usageHelp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;USAGE
Usage:  php -f test.php -- [options]
&nbsp;
  --myaction        Test action
  --help            This help
&nbsp;
USAGE</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>La clase ya es funcional, pero a nuestro archivo le faltan aún tres líneas.</p>
<p>Primero, debemos hacer un include para la clase abstracta que <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/">Magento</a> utiliza para el Shell.</p>
<p>Luego, al final de nuestro archivo otras dos líneas que nos van a instanciar la clase y luego a ejecutarla.</p>
<p>El ejemplo completo debe verse así.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span> <span style="color: #0000ff;">'abstract.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> Dc_Shell_Test <span style="color: #000000; font-weight: bold;">extends</span> Mage_Shell_Abstract <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_action'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción de my_action<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usageHelp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> usageHelp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;USAGE
Usage:  php -f test.php -- [options]
&nbsp;
  --myaction        Test action
  --help            This help
&nbsp;
USAGE</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$shell</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Dc_Shell_Test<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$shell</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahora si, nos vamos a la consola, y dando por sentado que estamos en el directorio correcto, hacemos nuestra primera prueba.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php <span style="color: #7a0874; font-weight: bold;">test</span> --my_action</pre></div></div>

<p>Nos devolverá.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Acción de my_action</pre></div></div>

<p>Si en cambio pasamos un parámetro no soportado.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php <span style="color: #7a0874; font-weight: bold;">test</span> --my_test</pre></div></div>

<p>Tendríamos que obtener lo siguiente.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Usage:  php -f test.php -- [options]
  --myaction          Test action
  --help              This help</pre></div></div>

<p>Como ven, es una lógica muy sencilla. Básicamente, si el nombre del argumento coincide con uno de los definidos como acción, se ejecutará. Caso contrario, se muestra la ayuda.</p>
<p>Si tuviéramos varias acciones, podemos, o bien tener varios if else if y toda la lógica dentro del método run(), o bien hacer un poco más ordenada nuestra clase y separar cada acción en métodos independientes y modificar un poquito a run().</p>
<p>A manera de ejemplo, vamos a suponer que tenemos 5 acciones posibles, a las que llamaremos: accion1, accion2, accion3, accion4 y accion5.</p>
<p>Para cada acción vamos a crear un método privado. Sólo para el ejemplo, probemos con:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 2<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 3<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion4<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 4<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion5<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 5<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ahora vamos a cambiar un poquito a run() para evitarnos una lista interminable de if else if.</p>
<p>No sólo vamos a pasar un argumento, sino que vamos a asignarle un valor.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_action'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$action</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Action <span style="color: #006699; font-weight: bold;">$action</span> not exists<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usageHelp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usageHelp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Lo que cambia ahora es que además de validar que exista el parámetro, vamos a tomar el valor del argumento y lo vamos a utilizar para invocar uno de nuestros métodos.</p>
<p>Si el método no existe, notificamos y mostramos la ayuda. (Siempre que agreguemos nuevas acciones tendríamos que agregar la correspondiente descripción en la ayuda).</p>
<p>La clase completa debería verse así.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Dc_Shell_Test <span style="color: #000000; font-weight: bold;">extends</span> Mage_Shell_Abstract <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$action</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getArg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'my_action'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$action</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$method</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$action</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">method_exists</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #000088;">$method</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #000088;">$method</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Action <span style="color: #006699; font-weight: bold;">$action</span> not exists<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usageHelp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">usageHelp</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #990000;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion1<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 1<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion2<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 2<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion3<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 3<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion4<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 4<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> accion5<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Acción 5<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> usageHelp<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;USAGE
Usage:  php -f test.php -- [options]
&nbsp;
  --my_action accion1     Acción 1
  --my_action accion2     Acción 2
  --my_action accion3     Acción 3
  --my_action accion4     Acción 4
  --my_action accion5     Acción 5
  --help                  This help
&nbsp;
USAGE</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Con ésta modificación, vamos a cambiar la forma de pasar los parámetros. Si quisiéramos llamar a la Acción 3, lo haríamos de ésta forma.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">php test.php --my_action accion3</pre></div></div>

<p>Y obtendríamos éste resultado.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Acción 3</pre></div></div>

<p>Y si enviáramos un parámetro incorrecto, por ejemplo: php test.php &#8211;my_action accion6, deberíamos obtener el mensaje de nuestra ayuda.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Action accion6 not exists
Usage:  php -f test.php -- [options]
&nbsp;
  --my_action accion1     Acción 1
  --my_action accion2     Acción 2
  --my_action accion3     Acción 3
  --my_action accion4     Acción 4
  --my_action accion5     Acción 5
  --help                  This help</pre></div></div>

<p>Ahora si, ya tenemos una forma prolija y ordenada de realizar acciones en Magento desde la consola.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2216" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2010/02/15/provincias-en-un-formulario-de-contacto-personalizado-en-magento/" title="Provincias en un formulario de contacto personalizado en Magento">Provincias en un formulario de contacto personalizado en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2009/10/08/accediendo-a-configuraciones-de-magento/" title="Accediendo a configuraciones de Magento">Accediendo a configuraciones de Magento</a></li><li><a href="http://www.damianculotta.com.ar/2009/09/04/opciones-de-formatdate-en-magento/" title="Opciones de formatDate en Magento">Opciones de formatDate en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2009/06/07/cambiar-formato-a-un-valor-de-tipo-fecha-en-magento/" title="Cambiar formato a un valor de tipo Fecha en Magento">Cambiar formato a un valor de tipo Fecha en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2009/04/19/debuggear-variables-dentro-de-magento/" title="Debuggear variables dentro de Magento">Debuggear variables dentro de Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collabtive-CI 0.6.5.2</title>
		<link>http://www.damianculotta.com.ar/2011/04/17/collabtive-ci-0-6-5-2/</link>
		<comments>http://www.damianculotta.com.ar/2011/04/17/collabtive-ci-0-6-5-2/#comments</comments>
		<pubDate>Sun, 17 Apr 2011 03:01:54 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Collabtive-CI]]></category>
		<category><![CDATA[Laboratorio]]></category>
		<category><![CDATA[collabtive]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2209</guid>
		<description><![CDATA[Al comienzo es fácil mantener el ritmo, así que vamos a aprovechar la inercia. Versión 0.6.5.2 de Collabtive-CI con otro cambio referente a las tareas. En ésta oportunidad, agregué la posibilidad, opcional, de cargar para una tarea la cantidad de &#8230; <a href="http://www.damianculotta.com.ar/2011/04/17/collabtive-ci-0-6-5-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Al comienzo es fácil mantener el ritmo, así que vamos a aprovechar la inercia.</p>
<p><a title="nueva versión de Collabtive-CI" href="https://github.com/barbanet/collabtive-ci/tree/0.6.5.2">Versión 0.6.5.2 de Collabtive-CI</a> con otro cambio referente a las tareas. En ésta oportunidad, agregué la posibilidad, opcional, de cargar para una tarea la cantidad de tiempo estimado que va a llevar.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-22-collabtive-tiempo-tarea.png"><img class="aligncenter size-medium wp-image-2211" title="Indicar tiempo estimado de una tarea en Collabtive-CI" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-22-collabtive-tiempo-tarea-300x241.png" alt="" width="300" height="241" /></a></p>
<p>La idea será avanzar sobre el control de tiempo para luego poder medir la estimación contra el tiempo real demandado.</p>
<p>A diferencia de las prioridades, éste campo no es obligatorio al momento de crear la tarea.</p>
<p>Como ya he dicho, ante cualquier error o comentario, éste es el link del <a title="gestión de incidencias de Collabtive-CI" href="https://github.com/barbanet/collabtive-ci/issues">Gestor de Incidencias de Collabtive-CI</a>.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2209" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2011/04/16/collabtive-ci-0-6-5-1/" title="Collabtive-CI 0.6.5.1">Collabtive-CI 0.6.5.1</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/16/collabtive-y-collabtive-ci/" title="Collabtive y Collabtive-CI">Collabtive y Collabtive-CI</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/" title="Extendiendo la configuración gráfica del cron en Magento">Extendiendo la configuración gráfica del cron en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/" title="Configuración gráfica para un cron job en Magento">Configuración gráfica para un cron job en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/04/17/collabtive-ci-0-6-5-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Collabtive-CI 0.6.5.1</title>
		<link>http://www.damianculotta.com.ar/2011/04/16/collabtive-ci-0-6-5-1/</link>
		<comments>http://www.damianculotta.com.ar/2011/04/16/collabtive-ci-0-6-5-1/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 21:10:17 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Collabtive-CI]]></category>
		<category><![CDATA[Laboratorio]]></category>
		<category><![CDATA[collabtive]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2201</guid>
		<description><![CDATA[El primer set de cambios ya se encuentra publicados bajo la versión 0.6.5.1 de Collabtive-CI. Los cambios implementado son: Cambios en las plantillas de mail, enviando ahora mayor información al agregar o editar una tarea. Correcciones de traducciones. Se agregó &#8230; <a href="http://www.damianculotta.com.ar/2011/04/16/collabtive-ci-0-6-5-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>El primer set de cambios ya se encuentra publicados bajo la <a title="nueva versión de Collabtive-CI" href="https://github.com/barbanet/collabtive-ci/tree/0.6.5.1">versión 0.6.5.1 de Collabtive-CI</a>.</p>
<p>Los cambios implementado son:</p>
<ul>
<li>Cambios en las plantillas de mail, enviando ahora mayor información al agregar o editar una tarea.</li>
<li>Correcciones de traducciones.</li>
<li>Se agregó la constante CL_BRANCH_VERSION y se implementó su uso junto a CL_VERSION en el footer.</li>
<li>Creación automática de las carpetas files y templates_c al momento de la instalación.</li>
<li>Se quitó el indicador de usuarios online y el chat de la barra lateral.</li>
<li>Se restauró el calendario en la barra lateral.</li>
<li>Se muestran todos los proyectos a los cuales el usuario está asociado, para dar la posibilidad de cambiar de proyecto si tener que pasar por el Escritorio.</li>
<li>Se implementaron prioridades para las tareas.</li>
</ul>
<p><span id="more-2201"></span>El cambio más significativo, y del cuál se ha hablado bastante en los foros, es el de las prioridades.</p>
<p>De ésta forma puede verse en el Escritorio.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-17-collabtiveci-escritorio.png"><img class="aligncenter size-medium wp-image-2202" title="Escritorio de Collabtive-CI mostrando las prioridades de las tareas" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-17-collabtiveci-escritorio-300x264.png" alt="" width="300" height="264" /></a></p>
<p>El listado de tareas dentro del proyecto también muestra la nueva columna.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-18-collabtiveci-tareas-proyecto.png"><img class="aligncenter size-medium wp-image-2203" title="Listado de tareas en Collabtive-CI 0.6.5.1" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-18-collabtiveci-tareas-proyecto-300x168.png" alt="" width="300" height="168" /></a></p>
<p>La nueva columna funciona de la misma forma que las demás. Podemos utilizarla como criterio para ordenar la lista.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-19-collabtiveci-tarea-prioridad.png"><img class="aligncenter size-full wp-image-2204" title="Detalle de la prioridad de la tarea" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-19-collabtiveci-tarea-prioridad.png" alt="" width="166" height="255" /></a></p>
<p>En la creación (o edición) de tareas, tenemos el dropdown en el cual debemos seleccionar el tipo de prioridad.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-20-collabtiveci-nueva-tarea.png"><img class="aligncenter size-medium wp-image-2205" title="Creación de tareas con selección de prioridad" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-20-collabtiveci-nueva-tarea-300x222.png" alt="" width="300" height="222" /></a></p>
<p>Para finalizar, el cambio en la barra lateral.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-21-collabtiveci-menu-lateral.png"><img class="aligncenter size-medium wp-image-2206" title="Calendario y Mis proyectos para la barra lateral" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-21-collabtiveci-menu-lateral-157x300.png" alt="" width="157" height="300" /></a></p>
<p>Ante cualquier error o comentario, pueden usar el <a title="gestión de incidencias de Collabtive-CI" href="https://github.com/barbanet/collabtive-ci/issues">Gestor de Incidencias de Collabtive-CI</a> o comunicarse a través del blog.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2201" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2011/04/17/collabtive-ci-0-6-5-2/" title="Collabtive-CI 0.6.5.2">Collabtive-CI 0.6.5.2</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/16/collabtive-y-collabtive-ci/" title="Collabtive y Collabtive-CI">Collabtive y Collabtive-CI</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/" title="Extendiendo la configuración gráfica del cron en Magento">Extendiendo la configuración gráfica del cron en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/" title="Configuración gráfica para un cron job en Magento">Configuración gráfica para un cron job en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/04/16/collabtive-ci-0-6-5-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Collabtive y Collabtive-CI</title>
		<link>http://www.damianculotta.com.ar/2011/04/16/collabtive-y-collabtive-ci/</link>
		<comments>http://www.damianculotta.com.ar/2011/04/16/collabtive-y-collabtive-ci/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 21:00:44 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Collabtive-CI]]></category>
		<category><![CDATA[Laboratorio]]></category>
		<category><![CDATA[collabtive]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2183</guid>
		<description><![CDATA[Desde hace ya un buen tiempo utilizo Collabtive para intentar gestionar proyectos, tareas, ideas, etc. Es una herramienta bastante cómoda y sencilla (tanto para trabajar de forma individual como grupal). Básicamente, la aplicación presenta una pantalla general en la que &#8230; <a href="http://www.damianculotta.com.ar/2011/04/16/collabtive-y-collabtive-ci/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Desde hace ya un buen tiempo utilizo <a title="Colaboración Open Source" href="http://collabtive.o-dyn.de/">Collabtive</a> para <del>intentar</del> gestionar proyectos, tareas, ideas, etc. Es una herramienta bastante cómoda y sencilla (tanto para trabajar de forma individual como grupal).</p>
<p>Básicamente, la aplicación presenta una pantalla general en la que veremos los proyectos en los que estamos involucrados y todas las tareas que tenemos asignadas.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-07-collabtive-escritorio.png"><img class="aligncenter size-medium wp-image-2184" title="Escritorio de Collabtive" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-07-collabtive-escritorio-300x219.png" alt="" width="300" height="219" /></a></p>
<p><span id="more-2183"></span>A nivel proyecto, la pantalla principal nos permite hacer la carga de tiempo consumido para una tarea, ver el calendario y los logs del mismo.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-08-collabtive-detalle-proyecto.png"><img class="aligncenter size-medium wp-image-2185" title="Página principal de un proyecto en Collabtive" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-08-collabtive-detalle-proyecto-254x300.png" alt="" width="254" height="300" /></a></p>
<p>La lógica que presenta la herramienta es bastante sencilla.</p>
<ol>
<li>Creamos un proyecto.</li>
<li>Dentro del mismo podemos (o no) tener hitos (si, suena raro para milestone).</li>
<li>Luego creamos listas de tareas que pueden o no estar asociadas a un milestone.</li>
<li>Dentro de cada lista de tareas creamos nuestras tareas.</li>
</ol>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-09-collabtive-nueva-tarea.png"><img class="aligncenter size-medium wp-image-2186" title="Creación de tareas en Collabtive" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-09-collabtive-nueva-tarea-300x243.png" alt="" width="300" height="243" /></a></p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-10-collabtive-tareas-proyecto.png"><img class="aligncenter size-medium wp-image-2187" title="Lista de tareas pendientes en Collabtive" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-16-05-10-collabtive-tareas-proyecto-300x142.png" alt="" width="300" height="142" /></a></p>
<p>Además, por cada proyecto podemos cargar archivos y dejar mensajes que pueden ser contestados. Cuenta también con un sencillo chat y con un buscador.</p>
<p>Toda ésta introducción no es precisamente para hablar del proyecto original, sino que debido al ritmo con qué se ha venido actualizando en el último año, publiqué mi versión modificada a través de <a title="social coding" href="https://github.com/">GitHub</a>.</p>
<p>Con ésta versión sólo busco hacer públicos los cambios que he implementado para mi, algunos por necesidad, otros en base a comentarios en los <a title="foros oficiales" href="http://collabtive.o-dyn.de/forum/">foros de Collabtive</a>.</p>
<p>El nombre, <a title="repositorio oficial" href="https://github.com/barbanet/collabtive-ci">Collabtive-CI</a>, está relacionado con una idea a largo plazo, partiendo de la versión original. Además de darle mayores funcionalidades, hay una reescritura completa planificada.</p>
<p>Hasta que llegue ese punto voy a estar manteniendo compatibilidad 100% con el proyecto original.</p>
<p>Si alguien tiene ganas de probarlo y dar feedback, sugerir funcionalidades o avisar de bugs; puede dejar un comentario, enviar un mail o usar el <a title="gestión de incidencias de Collabtive-CI" href="https://github.com/barbanet/collabtive-ci/issues">Gestor de Incidencias del proyecto en GitHub</a>.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2183" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2011/04/17/collabtive-ci-0-6-5-2/" title="Collabtive-CI 0.6.5.2">Collabtive-CI 0.6.5.2</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/16/collabtive-ci-0-6-5-1/" title="Collabtive-CI 0.6.5.1">Collabtive-CI 0.6.5.1</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/" title="Extendiendo la configuración gráfica del cron en Magento">Extendiendo la configuración gráfica del cron en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/" title="Configuración gráfica para un cron job en Magento">Configuración gráfica para un cron job en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/04/16/collabtive-y-collabtive-ci/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Extendiendo la configuración gráfica del cron en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/#comments</comments>
		<pubDate>Fri, 01 Apr 2011 07:00:40 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2166</guid>
		<description><![CDATA[Para evitar tener que lidiar con la configuración por xml, en Magento podemos crear la configuración gráfica para los cron jobs de nuestros módulos, de manera que estamos dando mayor flexibilidad al usuario y nos evitamos riesgos que podrían ocasionarse &#8230; <a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Para evitar tener que lidiar con la configuración por xml, en <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/">Magento</a> podemos crear la <a title="Configuración gráfica para un cron job en Magento" href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/">configuración gráfica para los cron jobs</a> de nuestros módulos, de manera que estamos dando mayor flexibilidad al usuario y nos evitamos riesgos que podrían ocasionarse por una mala edición de los archivos.</p>
<p>Normalmente las opciones que nos ofrece la configuración suelen ser suficiente.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-03-28-00-38-magento-cron-opciones.png"><img class="aligncenter size-medium wp-image-2167" title="Opciones por defecto para configurar un cron job en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-03-28-00-38-magento-cron-opciones-300x78.png" alt="" width="300" height="78" /></a></p>
<p>En otros casos, es posible que no nos alcance con sólo poder configurar una ejecución diaria, semanal o mensual. En éste esquema, nos estamos perdiendo la posibilidad de configurar la ejecución con repetición por horas o por minutos.</p>
<p>Para poder obtener esas opciones vamos a necesitar crear dos modelos para nuestro módulo, que serán los encargados de brindarnos esas nuevas posibilidades (y de paso vamos a arreglar otras que no funcionan desde la implementación original).</p>
<p><span id="more-2166"></span>Lo primero será crear un nuevo set de opciones de frecuencia de ejecución. Para esto, podemos crear la siguiente clase (pensando que el módulo se llama Dc_Modulo): Dc_Modulo_Model_Config_Cron_Frequency, que estaría ubicada en /app/code/local/Dc/Modulo/Model/Config/Cron/Frequency.php.</p>
<p>La clase contendría lo siguiente.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Dc_Modulo_Model_Config_Cron_Frequency
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> static <span style="color: #000088;">$_options</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">const</span> CRON_MINUTELY <span style="color: #339933;">=</span> <span style="color: #0000ff;">'I'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CRON_HOURLY   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'H'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CRON_DAILY    <span style="color: #339933;">=</span> <span style="color: #0000ff;">'D'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CRON_WEEKLY   <span style="color: #339933;">=</span> <span style="color: #0000ff;">'W'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CRON_MONTHLY  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'M'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toOptionArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_options</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Minutely'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MINUTELY</span><span style="color: #339933;">,</span>
                <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Hourly'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_HOURLY</span><span style="color: #339933;">,</span>
                <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Daily'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_DAILY</span><span style="color: #339933;">,</span>
                <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Weekly'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_WEEKLY</span><span style="color: #339933;">,</span>
                <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                    <span style="color: #0000ff;">'label'</span> <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Monthly'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MONTHLY</span><span style="color: #339933;">,</span>
                <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #000088;">$_options</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Luego vamos a crear (o modificar) el modelo encargado de capturar los valores ingresados en la configuración para convertirlos en una expresión de tiempo cron.</p>
<p>Siguiendo el ejemplo, la clase podría llamarse Dc_Modulo_Model_Config_Cron_Process, la cual se encontraría en /app/code/local/Dc/Modulo/Model/Config/Cron/Process.php.</p>
<p>Aquí es donde vamos a insertar unas cuantas modificaciones y correcciones al modelo original ofrecido por <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/">Magento</a>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Dc_Modulo_Model_Config_Cron_Process <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Config_Data
<span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">const</span> CRON_STRING_PATH <span style="color: #339933;">=</span> <span style="color: #0000ff;">'crontab/jobs/mi_modulo_mi_cron_job/schedule/cron_expr'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CRON_MODEL_PATH <span style="color: #339933;">=</span> <span style="color: #0000ff;">'crontab/jobs/mi_modulo_mi_cron_job/run/model'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _afterSave<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'groups/cronjob_execution/fields/time/value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequency</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'groups/cronjob_execution/fields/frequency/value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$frequencyMinutely</span> <span style="color: #339933;">=</span> Dc_Modulo_Model_Config_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_MINUTELY</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequencyHourly</span> <span style="color: #339933;">=</span> Dc_Modulo_Model_Config_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_HOURLY</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequencyDaily</span> <span style="color: #339933;">=</span> Dc_Modulo_Model_Config_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_DAILY</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequencyWeekly</span> <span style="color: #339933;">=</span> Dc_Modulo_Model_Config_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_WEEKLY</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequencyMonthly</span> <span style="color: #339933;">=</span> Dc_Modulo_Model_Config_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_MONTHLY</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$cronDayOfWeek</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'N'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$cronDayOfMonth</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'j'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$minutelyValue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$frequencyMinutely</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$minutelyValue</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'*/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$minutelyValue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$hourlyValue</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$frequencyHourly</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$hourlyValue</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'*/'</span> <span style="color: #339933;">.</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$frequencyMinutely</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$hourlyValue</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$hourlyValue</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$cronExprArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #000088;">$minutelyValue</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$hourlyValue</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$frequencyMonthly</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$cronDayOfMonth</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$frequencyWeekly</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$cronDayOfWeek</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$cronExprString</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cronExprArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        try <span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/config_data'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_STRING_PATH</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cronExprString</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_STRING_PATH</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/config_data'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MODEL_PATH</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MODEL_PATH</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MODEL_PATH</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Unable to save Cron expression'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>El paso final es indicar en la configuración de system.xml, que para éste módulo estaría ubicado en /app/code/local/Dc/Modulo/etc/, que para la configuración utilice nuestros modelos.</p>
<p>En éste caso, la definición de estos campos quedaría de la siguiente forma.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;time</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Start Time<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>time<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/time<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frequency</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Frequency<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modulo/config_cron_frequency<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;backend_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modulo/config_cron_process<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/backend_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frequency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Una vez aplicados estos cambios, nuestra opción de configuración debería verse de ésta forma.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-03-28-00-39-magento-cron-opciones-extendidas.png"><img class="aligncenter size-medium wp-image-2168" title="Extendiendo las posibilidades de configuración de un cron job en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-03-28-00-39-magento-cron-opciones-extendidas-300x89.png" alt="" width="300" height="89" /></a></p>
<p>Ahora veamos el resultado práctico de cada una de las configuraciones que ahora podemos aplicar.</p>
<p>Si configuramos la ejecución por minutos.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-55-magento-cron-por-minuto.png"><img class="aligncenter size-medium wp-image-2170" title="Configuración de cron jobs para ejecución por minutos en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-55-magento-cron-por-minuto-300x62.png" alt="" width="300" height="62" /></a></p>
<p>El resultado de ésta configuración será la siguiente expresión.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+-----------+---------+----------+--------------------------------------------------------+--------------+
| config_id | scope   | scope_id | path                                                   | value        |
+-----------+---------+----------+--------------------------------------------------------+--------------+
|      1041 | default |        0 | crontab/jobs/mi_modulo_mi_cron_job/schedule/cron_expr  | */30 * * * * |
+-----------+---------+----------+--------------------------------------------------------+--------------+</pre></div></div>

<p>Si la opción fuera por hora.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-56-magento-cron-por-hora.png"><img class="aligncenter size-medium wp-image-2171" title="Configuración de cron jobs para ejecución por hora en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-56-magento-cron-por-hora-300x59.png" alt="" width="300" height="59" /></a></p>
<p>Obtendríamos ésta expresión.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+-----------+---------+----------+--------------------------------------------------------+--------------+
| config_id | scope   | scope_id | path                                                   | value        |
+-----------+---------+----------+--------------------------------------------------------+--------------+
|      1041 | default |        0 | crontab/jobs/mi_modulo_mi_cron_job/schedule/cron_expr  | 0 */2 * * *  |
+-----------+---------+----------+--------------------------------------------------------+--------------+</pre></div></div>

<p>Ahora, una de las opciones conocidas: una vez por día.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-57-magento-cron-por-dia.png"><img class="aligncenter size-medium wp-image-2172" title="Configuración de cron jobs para ejecución por día en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-57-magento-cron-por-dia-300x63.png" alt="" width="300" height="63" /></a></p>
<p>Nos devuelve lo que ya conocemos.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+-----------+---------+----------+--------------------------------------------------------+--------------+
| config_id | scope   | scope_id | path                                                   | value        |
+-----------+---------+----------+--------------------------------------------------------+--------------+
|      1041 | default |        0 | crontab/jobs/mi_modulo_mi_cron_job/schedule/cron_expr  | 15 3 * * *   |
+-----------+---------+----------+--------------------------------------------------------+--------------+</pre></div></div>

<p>Para el caso de la ejecución semanal.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-58-magento-cron-por-semana.png"><img class="aligncenter size-medium wp-image-2173" title="Configuración de cron jobs para ejecución un día por semana en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-58-magento-cron-por-semana-300x63.png" alt="" width="300" height="63" /></a></p>
<p>Ahora si grabará correctamente el valor.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+-----------+---------+----------+--------------------------------------------------------+--------------+
| config_id | scope   | scope_id | path                                                   | value        |
+-----------+---------+----------+--------------------------------------------------------+--------------+
|      1041 | default |        0 | crontab/jobs/mi_modulo_mi_cron_job/schedule/cron_expr  | 30 4 * * 5   |
+-----------+---------+----------+--------------------------------------------------------+--------------+</pre></div></div>

<p>El último caso es el de la ejecución una vez por mes.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-59-magento-cron-por-mes.png"><img class="aligncenter size-medium wp-image-2174" title="Configuración de cron jobs para ejecución un día por mes en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-04-01-00-59-magento-cron-por-mes-300x60.png" alt="" width="300" height="60" /></a></p>
<p>Luego de la corrección, ahora si, nos devolverá la siguiente expresión.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">+-----------+---------+----------+--------------------------------------------------------+--------------+
| config_id | scope   | scope_id | path                                                   | value        |
+-----------+---------+----------+--------------------------------------------------------+--------------+
|      1041 | default |        0 | crontab/jobs/mi_modulo_mi_cron_job/schedule/cron_expr  | 45 5 1 * *   |
+-----------+---------+----------+--------------------------------------------------------+--------------+</pre></div></div>

<p>Si bien éste cambio nos permite una mejora sustancial en la configuración de un cron job, para crear configuraciones más avanzadas tenemos sólo dos opciones:</p>
<ol>
<li>Configurar por xml la expresión de tiempo.</li>
<li>Habilitar un campo de texto en el cual el usuario ingresará la expresión como si lo estuviera haciendo en el xml.</li>
</ol>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2166" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/" title="Configuración gráfica para un cron job en Magento">Configuración gráfica para un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/" title="Crear un cron job en Magento">Crear un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/" title="Cómo crear un renderer para las grillas en Magento">Cómo crear un renderer para las grillas en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/" title="Dropdowns en los formularios de backend de Magento">Dropdowns en los formularios de backend de Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Configuración gráfica para un cron job en Magento</title>
		<link>http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/#comments</comments>
		<pubDate>Wed, 22 Sep 2010 03:17:12 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=1974</guid>
		<description><![CDATA[Siempre que se habla de crear cron jobs para un módulo en Magento, se explica cómo configurar el crontab y el xml del módulo. Si bien vamos a lograr el objetivo, esto siempre obliga a quien administra el proceso a &#8230; <a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Siempre que se habla de crear cron jobs para un módulo en <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/" target="_self">Magento</a>, se explica cómo configurar el crontab y el <a title="definición en Wikipedia" href="http://es.wikipedia.org/wiki/Extensible_Markup_Language" target="_self">xml</a> del módulo.</p>
<p>Si bien vamos a lograr el objetivo, esto siempre obliga a quien administra el proceso a estar editando un archivo y corrigiendo los tiempos de ejecución.</p>
<p>De ésta forma no sólo estamos ante una situación incómoda sino que, además, podríamos estar comprometiendo la integridad del módulo.</p>
<p>Voy a dar por sentado que ya nuestro cron job funciona como queremos y que hemos creado la configuración de otros parámetros del módulo. Sólo nos vamos a concentrar en agregar la configuración gráfica para la ejecución.</p>
<p>Ahora bien, el primer paso es crear un nuevo modelo que será el encargado de transformar los valores que ingresemos en la configuración a valores que el Cron Manager de <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/" target="_self">Magento</a> entienda.</p>
<p><span id="more-1974"></span>Si bien no hay por qué seguir ningún estándar en particular, para éste tipo de modelos suele usarse la siguiente nomenclatura.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">/app/code/local/Dc/Modulo/Model/Config/Cron/Proceso.php</pre></div></div>

<p>Ahora bien, vamos a crear la clase.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Dc_Modulo_Model_Config_Cron_Proceso <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Model_Config_Data <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">const</span> CRON_STRING_PATH <span style="color: #339933;">=</span> <span style="color: #0000ff;">'crontab/jobs/mi_modulo_mi_cron_job/schedule/cron_expr'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">const</span> CRON_MODEL_PATH <span style="color: #339933;">=</span> <span style="color: #0000ff;">'crontab/jobs/mi_modulo_mi_cron_job/run/model'</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _afterSave<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #000088;">$time</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'groups/cronjob/fields/time/value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequency</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'groups/cronjob/fields/frequency/value'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$frequencyDaily</span> <span style="color: #339933;">=</span> Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_DAILY</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequencyWeekly</span> <span style="color: #339933;">=</span> Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_WEEKLY</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$frequencyMonthly</span> <span style="color: #339933;">=</span> Mage_Adminhtml_Model_System_Config_Source_Cron_Frequency<span style="color: #339933;">::</span><span style="color: #004000;">CRON_MONTHLY</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$cronDayOfWeek</span> <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'N'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$cronExprArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$time</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$frequencyMonthly</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'1'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span>
            <span style="color: #009900;">&#40;</span><span style="color: #000088;">$frequency</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$frequencyWeekly</span><span style="color: #009900;">&#41;</span> ? <span style="color: #0000ff;">'1'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">'*'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$cronExprString</span> <span style="color: #339933;">=</span> <span style="color: #990000;">join</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$cronExprArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        try <span style="color: #009900;">&#123;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/config_data'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_STRING_PATH</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cronExprString</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_STRING_PATH</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'core/config_data'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MODEL_PATH</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'path'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#41;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getConfig</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getNode</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MODEL_PATH</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setPath</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">self</span><span style="color: #339933;">::</span><span style="color: #004000;">CRON_MODEL_PATH</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">save</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> Exception<span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cron'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Unable to save Cron expression'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>El siguiente paso es indicarle al valor de configuración que para manejar los datos, aplique éste modelo.</p>
<p>Para esto, vamos a abrir el archivo /etc/system.xml de nuestro módulo y vamos a agregar un nuevo parámetro dentro del nodo fields que será el de la configuración específica del cron job.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;time</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Start Time<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>time<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/time<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frequency</span> <span style="color: #000066;">translate</span>=<span style="color: #ff0000;">&quot;label&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Frequency<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/label<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>select<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frontend_type<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>adminhtml/system_config_source_cron_frequency<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/source_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;backend_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modulo/config_cron_proceso<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/backend_model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/sort_order<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_default<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_website<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/show_in_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/frequency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Ahora guardamos y accedemos a la configuración.</p>
<p>El resultado debería ser similar (el mismo en realidad) a lo que vemos a continuación.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-21-23-39-cron-job-configuration.png"><img class="aligncenter size-medium wp-image-1980" title="Configuración gráfica de un cron job en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-21-23-39-cron-job-configuration-300x63.png" alt="" width="300" height="63" /></a></p>
<p>Ahora ya podemos configurar nuestro cron job desde el backend sin tocar los archivos de la plataforma.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1974" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/" title="Extendiendo la configuración gráfica del cron en Magento">Extendiendo la configuración gráfica del cron en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/" title="Crear un cron job en Magento">Crear un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/" title="Cómo crear un renderer para las grillas en Magento">Cómo crear un renderer para las grillas en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/" title="Dropdowns en los formularios de backend de Magento">Dropdowns en los formularios de backend de Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Crear un cron job en Magento</title>
		<link>http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 02:00:26 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=1960</guid>
		<description><![CDATA[Muchas veces vamos a necesitar procesos que se ejecuten sin importar si del otro lado de la pantalla hay algún usuario realizando alguna acción. Por lo general éste tipo de tareas tienen que ver más con procesos administrativos que con &#8230; <a href="http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Muchas veces vamos a necesitar procesos que se ejecuten sin importar si del otro lado de la pantalla hay algún usuario realizando alguna acción.</p>
<p>Por lo general éste tipo de tareas tienen que ver más con procesos administrativos que con la experiencia de compra en si misma.</p>
<p>Una de las funcionalidades de <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/" target="_self">Magento</a> es el cron, que no es más que una extensión del <a title="definición en Wikipedia" href="http://es.wikipedia.org/wiki/Cron_%28Unix%29" target="_self">cron</a> del sistema operativo. La pequeña diferencia sería que desde el sistema operativo ejecutamos un único archivo de la plataforma y ésta, según configuraciones, se encargará de correr los procesos que correspondan.</p>
<p>Un cron job para <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/" target="_self">Magento</a> es, básicamente, un método de un modelo que se encargará de realizar una acción.</p>
<p>Para lograr el nuestro, lo primero sería crear la clase y el método que más tarde invocaremos. Un ejemplo podría ser el siguiente.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Dc_Modulo_Model_Cron <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> runMyCronJob<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">//Acciones a realizar</span>
&nbsp;
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>De más está decir que lo que haga el método quedará librado a la necesidad de cada uno. No hace al ejemplo definir algún proceso.</p>
<p><span id="more-1960"></span>Para lograr que el cron job sea insertado dentro de la lista de ejecución tenemos que agregar algunas líneas a la configuración de nuestro módulo.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    ...
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;crontab<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;jobs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;mi_modulo_mi_cron_job<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;run<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>modulo/cron::runMyCronJob<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/model<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/run<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;schedule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cron_expr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>45 23 * * *<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cron_expr<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
                <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/schedule<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/mi_modulo_mi_cron_job<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/jobs<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/crontab<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/config<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Los datos que acabamos de agregar indican lo siguiente.</p>
<p>&lt;mi_modulo_mi_cron_job&gt; es el nombre del cron job. El nombre debe ser único. Dentro de &lt;run&gt; le indicamos el model a ejecutar. El tag &lt;schedule&gt; es el que, utilizando el mismo tipo de expresión que se aplica para el cron del sistema operativo, va a indicar la hora de ejecución.</p>
<p>De ésta forma, tendremos nuestro proceso corriendo cada vez que se cumpla la condición de la hora.</p>
<p>Para más información sobre cómo configurar la ejecución de los cron jobs y para conocer cuáles procesos ya vienen con <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/" target="_self">Magento</a>, pueden darle una leída al siguiente <a title="artículo en la wiki de Magento" href="http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job" target="_self">artículo en la wiki sobre el cron</a>.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1960" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/" title="Extendiendo la configuración gráfica del cron en Magento">Extendiendo la configuración gráfica del cron en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/" title="Configuración gráfica para un cron job en Magento">Configuración gráfica para un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/" title="Cómo crear un renderer para las grillas en Magento">Cómo crear un renderer para las grillas en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/" title="Dropdowns en los formularios de backend de Magento">Dropdowns en los formularios de backend de Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo crear un renderer para las grillas en Magento</title>
		<link>http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/#comments</comments>
		<pubDate>Mon, 20 Sep 2010 02:00:09 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=1934</guid>
		<description><![CDATA[Si bien tanto para los formularios como para las grilla Magento nos provee de una serie de tipos listos para usar, en algunas oportunidades nos hará falta alguna nueva funcionalidad. En el caso de las grillas, es bastante sencillo agregar &#8230; <a href="http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Si bien tanto para los formularios como para las grilla <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/" target="_self">Magento</a> nos provee de una serie de tipos listos para usar, en algunas oportunidades nos hará falta alguna nueva funcionalidad.</p>
<p>En el caso de las grillas, es bastante sencillo agregar un nuevo tipo de columna.</p>
<p>Normalmente, cuando nuestro formulario permite subir archivos, el resultado en la grilla sería el siguiente.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-19-11-47-magento-grilla.png"><img class="aligncenter size-medium wp-image-1939" title="Grilla por defecto en el backend de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-19-11-47-magento-grilla-300x61.png" alt="" width="300" height="61" /></a></p>
<p>La columna filename se muestra como texto, pero en realidad es una referencia a un archivo que nos gustaría poder ver como imagen.</p>
<p><span id="more-1934"></span>Para lograr éste cambio vamos a crear nuestro propio renderer para esa columna. El primer paso es crear el renderer, que es una clase de tipo Block.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">class</span> Dc_Modulo_Block_Adminhtml_Renderer_Image <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract <span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Este es el método que será devuelto a la grilla.</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> render<span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getFilename<span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">//Separando un poco el código, en éste método aplicamos las transformaciones que necesitemos para el valor.    </span>
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _getFilename<span style="color: #009900;">&#40;</span>Varien_Object <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$image</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filename</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span> ? <span style="color: #0000ff;">'&lt;img src=&quot;'</span> <span style="color: #339933;">.</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getBaseUrl</span><span style="color: #009900;">&#40;</span>Mage_Core_Model_Store<span style="color: #339933;">::</span><span style="color: #004000;">URL_TYPE_MEDIA</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filename</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&quot; alt=&quot;&quot; /&gt;'</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$image</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Una vez que tenemos definido el renderer, vamos a cambiar algunos valores en la definición de la columna de nuestra grilla.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'filename'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'header'</span>    <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'modulo'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Filename'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'align'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'center'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'width'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'300px'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'filter'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'sortable'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'renderer'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'modulo/adminhtml_renderer_image'</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahora sólo debemos volver a mirar nuestra grilla y el resultado debería ser similar a éste.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-19-11-49-magento-grilla-con-renderer.png"><img class="aligncenter size-medium wp-image-1940" title="Agregando un renderer propio a una grilla en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-19-11-49-magento-grilla-con-renderer-300x130.png" alt="" width="300" height="130" /></a></p>
<p>De acá en más, la posibilidad de presentar datos en las grillas tendría que resultarnos algo más sencillo.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1934" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/" title="Extendiendo la configuración gráfica del cron en Magento">Extendiendo la configuración gráfica del cron en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/" title="Configuración gráfica para un cron job en Magento">Configuración gráfica para un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/" title="Crear un cron job en Magento">Crear un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/" title="Dropdowns en los formularios de backend de Magento">Dropdowns en los formularios de backend de Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dropdowns en los formularios de backend de Magento</title>
		<link>http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/</link>
		<comments>http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/#comments</comments>
		<pubDate>Mon, 13 Sep 2010 04:17:59 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[programación]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=1901</guid>
		<description><![CDATA[Uno de los ejemplos que el creador de módulos de Magento no incluye para el caso de los formularios del backend, es el del uso de dropdowns que deben ser llenados con valores de algún modelo que referencia a una &#8230; <a href="http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Uno de los ejemplos que el <a title="artículo en la wiki de Magento" href="http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table" target="_self">creador de módulos de Magento</a> no incluye para el caso de los formularios del backend, es el del uso de dropdowns que deben ser llenados con valores de algún modelo que referencia a una tabla.</p>
<p>Por defecto, nos encontramos con esto.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-12-23-08-dropdown-formulario-magento.png"><img class="aligncenter size-medium wp-image-1909" title="Dropdown en un formulario de backend en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-12-23-08-dropdown-formulario-magento-300x58.png" alt="" width="300" height="58" /></a></p>
<p>Para lograrlo, el código que se utiliza en la composición del formulario es el siguiente.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'status'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'select'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Status'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'status'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'values'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'value'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Enabled'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
            <span style="color: #0000ff;">'value'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">2</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Disabled'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Uno de los problemas de ésta modalidad, es que luego nuestro modelo deberá responder por esos mismos id&#8217;s para poder mostrar, &#8220;hacia afuera&#8221;, los valores como corresponden. Queda claro que dependiendo de la cantidad de opciones que vayan a utilizarse para llenar el dropdown, esto podría convertirse en una situación difícil de mantener.</p>
<p>Supongamos que estamos haciendo un módulo que se compone por más de un formulario, y donde uno de éstos genera valores que serán usado por un segundo. A manera de ejemplo, podríamos pensar en un sencillo módulo de noticias, en donde en el primero de los formularios cargaríamos una categoría y luego en el segundo seleccionaríamos en un dropdown la categoría.</p>
<p>¿Cómo hacer entonces para que los que carguemos como categorías sea utilizable por el segundo formulario sin tener que estar editándolo?.</p>
<p><span id="more-1901"></span>La solución no dista de ser sencilla. Para empezar, vamos a agregar un método al modelo que gestiona (siguiendo el ejemplo) las categorías de nuestro módulo de noticias. En particular vamos a tomar la clase collection.</p>
<p>Supongamos que el módulo se llamara Dc_News. Vamos a buscar el archivo Dc_News_Model_Mysql4_Categories_Collection y le agregamos el siguiente código.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> toOptionArray<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_toOptionArray<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'campo_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'campo_texto_a_mostrar'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ahora volvemos a nuestro formulario y vamos a modificar un poco la definición del campo que estamos rendereando como dropdown.</p>
<p>Previo a la definición vamos a agregar ésta línea.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_categories</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news/categories'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCollection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">toOptionArray</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Luego, en la especificación del campo, en lugar de agregar el array de valores utilizamos la variable que definimos previamente como el value de éste campo.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$fieldset</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'select'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">'label'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'news'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Category'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'required'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'category'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'values'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$_categories</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Una vez hecho esto, y suponiendo que ya cargamos algunos valores, el campo en nuestro formulario debiera de mostrar algo como esto.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-12-23-10-dropdown-formulario-base-de-datos.png"><img class="aligncenter size-medium wp-image-1910" title="Dropdown con los valores obtenidos desde base de datos" src="http://www.damianculotta.com.ar/wp-content/uploads/2010-09-12-23-10-dropdown-formulario-base-de-datos-300x54.png" alt="" width="300" height="54" /></a></p>
<p>Con ésto tenemos las dos variantes para utilizar dropdowns en nuestros módulos de Magento.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1901" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/01/extendiendo-la-configuracion-grafica-del-cron-en-magento/" title="Extendiendo la configuración gráfica del cron en Magento">Extendiendo la configuración gráfica del cron en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/22/configuracion-grafica-para-un-cron-job-en-magento/" title="Configuración gráfica para un cron job en Magento">Configuración gráfica para un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/20/crear-un-cron-job-en-magento/" title="Crear un cron job en Magento">Crear un cron job en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2010/09/19/como-crear-un-renderer-para-las-grillas-en-magento/" title="Cómo crear un renderer para las grillas en Magento">Cómo crear un renderer para las grillas en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2010/09/13/dropdowns-en-los-formularios-de-backend-de-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Url friendly en CodeIgniter</title>
		<link>http://www.damianculotta.com.ar/2010/08/09/url-friendly-en-codeigniter/</link>
		<comments>http://www.damianculotta.com.ar/2010/08/09/url-friendly-en-codeigniter/#comments</comments>
		<pubDate>Mon, 09 Aug 2010 13:00:45 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Php]]></category>
		<category><![CDATA[configuración]]></category>
		<category><![CDATA[frameworks]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=1856</guid>
		<description><![CDATA[CodeIgniter nos permite la utilización de urls amistosas (si, la traducción suena bastante fea). Dado que por defecto ésto no funciona, tenemos que hacer algunos pequeños ajustes. Lo primero será crear un archivo .htaccess con lo siguiente. RewriteEngine on RewriteCond &#8230; <a href="http://www.damianculotta.com.ar/2010/08/09/url-friendly-en-codeigniter/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a title="sitio oficial" href="http://codeigniter.com/" target="_self">CodeIgniter</a> nos permite la utilización de urls amistosas (si, la traducción suena bastante fea).</p>
<p>Dado que por defecto ésto no funciona, tenemos que hacer algunos pequeños ajustes.</p>
<p>Lo primero será crear un archivo .htaccess con lo siguiente.</p>
<pre class="apache">RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]</pre>
<p>A partir de ahora, en lugar de usar:</p>
<pre class="text">http://www.dominio.com.ar/index.php/controlador/accion/</pre>
<p>Vamos a poder usar:</p>
<pre class="text">http://www.dominio.com.ar/controlador/accion/</pre>
<p>Para que la impresión de urls resulte correcta, es necesario hacer un ajuste en el archivo de configuración. Esto aplica en particular si vamos a usar la función site_url del <a title="documentación oficial" href="http://codeigniter.com/user_guide/helpers/url_helper.html" target="_self">helper Url</a>.</p>
<p>Para evitar que al llamar a la función nos devuelva http://www.dominio.com.ar/index.php, vamos a cambiar la línea 23 de /system/application/config/config.php, y vamos a dejar el valor de la key index_page en blanco.</p>
<p>La configuración debería quedar de ésta forma:</p>
<pre class="php">$config['index_page'] = "";</pre>
<p>Con estos pequeños ajustes ya deberíamos estar aplicando urls semánticas sin problemas.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1856" width="1" height="1" style="display: none;" /><h2  class="related_post_title">A lo mejor te interese leer</h2><ul class="related_post"><li><a href="http://www.damianculotta.com.ar/2010/04/08/primeros-pasos-con-codeigniter/" title="Primeros pasos con CodeIgniter">Primeros pasos con CodeIgniter</a></li><li><a href="http://www.damianculotta.com.ar/2010/05/11/creando-un-nuevo-controller-en-codeigniter/" title="Creando un nuevo controller en CodeIgniter">Creando un nuevo controller en CodeIgniter</a></li><li><a href="http://www.damianculotta.com.ar/2009/12/02/iniciar-un-proyecto-con-codeigniter/" title="Iniciar un proyecto con CodeIgniter">Iniciar un proyecto con CodeIgniter</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/25/como-crear-una-clase-para-el-shell-en-magento/" title="Cómo crear una clase para el Shell en Magento">Cómo crear una clase para el Shell en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/04/17/collabtive-ci-0-6-5-2/" title="Collabtive-CI 0.6.5.2">Collabtive-CI 0.6.5.2</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2010/08/09/url-friendly-en-codeigniter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

