<?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; tips</title>
	<atom:link href="http://www.damianculotta.com.ar/tag/tips/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>Mejorando el SEO de nuestros módulos en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 13:30:28 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2420</guid>
		<description><![CDATA[Hoy vamos a ver dos pequeños trucos para lograr una mejor presentación de nuestros módulos. El primero está relacionado con el SEO y el segundo con la navegación. Para no perder la costumbre, vamos a partir de un módulo hecho &#8230; <a href="http://www.damianculotta.com.ar/2011/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Hoy vamos a ver dos pequeños trucos para lograr una mejor presentación de nuestros módulos.</p>
<p>El primero está relacionado con el SEO y el segundo con la navegación.</p>
<p>Para no perder la costumbre, vamos a partir de un módulo hecho por 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">Generador de Módulos</a>. Además, para seguir manteniendo la línea, el módulo ha de llamarse Dc_Test.</p>
<p>Si intentamos acceder al controlador de nuestro módulo en el frontend, vamos a encontrarnos con lo siguiente.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-00-57-magento-sin-breadcrumb.png"><img class="aligncenter size-medium wp-image-2421" title="Navegación sin breadcrumb en nuestro módulo para Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-00-57-magento-sin-breadcrumb-300x130.png" alt="" width="300" height="130" /></a>Si vemos el código fuente, vamos a notar que hay 3 tags que no se están usando correctamente: title, description y keywords.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-00-58-magento-sin-seo.png"><img class="aligncenter size-medium wp-image-2422" title="Html tags generados por nuestro módulo en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-00-58-magento-sin-seo-300x73.png" alt="" width="300" height="73" /></a>La idea del tip de hoy es aprovechar algunas funcionalidades de Magento para darle a nuestro módulo un poco de SEO haciendo uso de los tags html y del breadcrumb.</p>
<p><span id="more-2420"></span>Si miramos el controlador que se generó automáticamente, vamos a encontrar 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;">class</span> Dc_Test_IndexController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Controller_Front_Action
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</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: #004000;">loadLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</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: #009900;">&#125;</span></pre></div></div>

<p>Lo primero que vamos a agregar serán los valores para los tags html.</p>
<p>Para esto, luego del loadLayout, 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;">class</span> Dc_Test_IndexController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Controller_Front_Action
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</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: #004000;">loadLayout</span><span style="color: #009900;">&#40;</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: #000088;">$head</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$head</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mi título'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$head</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contenido del tag Description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$head</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mis,keywords,para,la,pagina'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</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: #009900;">&#125;</span></pre></div></div>

<p>Lo que estamos haciendo aquí es validar si el bloque head existe en el layout. En caso afirmativo asignamos valores para las 3 keys que nos interesan (al menos en el ejemplo).</p>
<p>El segundo paso será agregar el breadcrumb para nuestro módulo. Nuevamente, vamos a tener que agregar algunas líneas en el controlador.</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_Test_IndexController <span style="color: #000000; font-weight: bold;">extends</span> Mage_Core_Controller_Front_Action
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> indexAction<span style="color: #009900;">&#40;</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: #004000;">loadLayout</span><span style="color: #009900;">&#40;</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: #000088;">$head</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'head'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$head</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setTitle</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mi título'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$head</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDescription</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contenido del tag Description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #000088;">$head</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setKeywords</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'mis,keywords,para,la,pagina'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$breadcrumbs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLayout</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getBlock</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'breadcrumbs'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$breadcrumbs</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCrumb</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'home'</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;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Inicio'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
                <span style="color: #0000ff;">'link'</span>  <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getBaseUrl</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
            <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addCrumb</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</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;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Título de la página'</span><span style="color: #009900;">&#41;</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">renderLayout</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: #009900;">&#125;</span></pre></div></div>

<p>Una vez guardados los cambios, actualizamos la página y ya van a verse los cambios.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-01-11-magento-con-breadcrumb.png"><img class="aligncenter size-medium wp-image-2423" title="Agregamos el breadcrumb para nuestro módulo en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-01-11-magento-con-breadcrumb-300x113.png" alt="" width="300" height="113" /></a><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-01-12-magento-con-seo.png"><img class="aligncenter size-medium wp-image-2424" title="Agregamos los valores específicos para los tags de nuestro módulo en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-11-07-01-12-magento-con-seo-300x70.png" alt="" width="300" height="70" /></a>De más está decir que el ejemplo tiene, justamente, ese fin.</p>
<p>Si nuestro módulo utiliza varias acciones, será más correcto tener un método privado en el controlador que se invoque dentro de cada una de ellas para manipular los distintos valores.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2420" 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/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/" title="Cómo hacer un módulo con soporte multistore en Magento">Cómo hacer un módulo con soporte multistore en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agregar validaciones javascript en Magento de forma no obstrusiva</title>
		<link>http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/</link>
		<comments>http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/#comments</comments>
		<pubDate>Mon, 10 Oct 2011 12:00:39 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2378</guid>
		<description><![CDATA[Pequeño tip en pro de seguir con las buenas prácticas. Hace no mucho tiempo me tocó hacer una personalización en la cual el requerimiento pedía agregar una regla adicional de validación para ciertos campos del checkout. Lo que vamos a &#8230; <a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Pequeño tip en pro de seguir con las buenas prácticas.</p>
<p>Hace no mucho tiempo me tocó hacer una personalización en la cual el requerimiento pedía agregar una regla adicional de validación para ciertos campos del checkout.</p>
<p>Lo que vamos a a ver es cómo agregar reglas propias de validación haciendo uso de la clase Validation. Por supuesto, la idea es no tocar el código original agregando código en js/prototype/validation.js o dentro de un phtml (como todavía seguimos viendo incluso en extensiones pagas).</p>
<p>Para el ejemplo vamos a necesitar 3 archivos.</p>
<p>El escenario con el cual voy a trabajar será el siguiente: &#8220;Agregar una nueva validación Javascript a ciertos campos del formulario del checkout sin por esto crear un nuevo módulo&#8221; (más adelante voy a volver sobre este punto).</p>
<p>Lo primero que vamos a hacer es crear nuestra función javascript de validación. Dado que la regla en si misma va más allá del skin, voy a crear el archivo dentro del directorio js. En mi caso, el archivo será /js/dc/validacion.js.</p>
<p><span id="more-2378"></span>Dentro del archivo, vamos a declarar una nueva regla.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">Validation.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'mi-nueva-validacion'</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'Mensaje de error a mostrar.'</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #009966; font-style: italic;">/^[ INGRESAMOS NUESTRA VALIDACION ]*$/</span>.<span style="color: #660066;">test</span><span style="color: #009900;">&#40;</span>v<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>El siguiente paso será lograr que el layout agregue nuestro nuevo archivo junto con todos los demás.</p>
<p>Para que esto suceda vamos a editar el archivo page.xml del layout de nuestro theme y agregamos dentro del nodo &lt;default&gt;, en la definición del bloque head, la llamada a nuestro archivo.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #339933;">&lt;</span>default translate<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;label&quot;</span> module<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
    ...
&nbsp;
    <span style="color: #339933;">&lt;</span>block type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;page/html_head&quot;</span> <span style="color: #000066;">name</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;head&quot;</span> <span style="color: #000066; font-weight: bold;">as</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;head&quot;</span><span style="color: #339933;">&gt;</span>
&nbsp;
        ...
&nbsp;
        <span style="color: #339933;">&lt;</span>action method<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;addJs&quot;</span><span style="color: #339933;">&gt;&lt;</span>script<span style="color: #339933;">&gt;</span>dc<span style="color: #339933;">/</span>validacion.<span style="color: #660066;">js</span><span style="color: #339933;">&lt;/</span>script<span style="color: #339933;">&gt;&lt;/</span>action<span style="color: #339933;">&gt;</span>
&nbsp;
        ...
&nbsp;
    <span style="color: #339933;">&lt;/</span>block<span style="color: #339933;">&gt;</span>
&nbsp;
<span style="color: #339933;">&lt;/</span>default<span style="color: #339933;">&gt;</span></pre></div></div>

<p>Ahora ya tenemos nuestra nueva regla de validación y también el archivo javascript cargado.</p>
<p>Para aplicarlo, necesitamos editar el archivo phtml que contiene el input al cual buscamos agregarle la validación.</p>
<p>Según el ejemplo, vamos a probar con el campo Company de la sección de Billing.</p>
<p>Abrimos el archivo app/design/frontend/[package]/[tema]/template/checkout/onepage/billing.phtml y en la línea 47 deberíamos ver nuestro campo. Al final de la línea se indica que la única clase de este input es &#8220;input-text&#8221;.</p>
<p>Vamos a modificar eso y agregamos, a continuación, el nombre de nuestra regla de validación.</p>
<p>Ahora el código de nuestro input debería verse de la siguiente forma:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;input id=&quot;billing:company&quot; class=&quot;input-text mi-nueva-validacion&quot; title=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Company'</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; type=&quot;text&quot; name=&quot;billing[company]&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">htmlEscape</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getAddress</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCompany</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; /&gt;</pre></div></div>

<p>Una vez que lleguemos al formulario, si ingresamos un valor no permitido, veríamos nuestro mensaje.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-10-10-03-48-magento-validacion-formularios.png"><img class="aligncenter size-medium wp-image-2379" title="Mensaje personalizado de validación JS en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-10-10-03-48-magento-validacion-formularios-300x83.png" alt="" width="300" height="83" /></a></p>
<p>Aplicando estos pasos estamos obteniendo una forma bastante prolija y reutilizable de agregar validaciones para nuestros formularios.</p>
<p>Al comienzo dejé una aclaración con respecto al requerimiento. Esto se debe a que la forma en que estoy agregando la validación no es la única.</p>
<p>Si mi validación fuera sólo para el checkout, quizás lo más correcto hacer la inclusión en la definición de layout del checkout y no en page. Si creamos un módulo que necesita una validación, también podríamos hacer al inclusión en la definición de layout de ese módulo.</p>
<p>Lo importante es evitar ensuciar el phtml y poder reutilizar nuestro código de una forma sencilla.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2378" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/" title="Cómo hacer un módulo con soporte multistore en Magento">Cómo hacer un módulo con soporte multistore en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Configuraciones dependientes en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/#comments</comments>
		<pubDate>Mon, 12 Sep 2011 05:00:15 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2347</guid>
		<description><![CDATA[Normalmente, cuando creamos un módulo y le agregamos opciones de configuración, obtenemos un formulario, al menos, como el siguiente. Está claro, el ejemplo es de lo más básico. Contamos con varios tipos de campos que nos permiten manejarnos con cierta &#8230; <a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Normalmente, cuando creamos un módulo y le agregamos opciones de configuración, obtenemos un formulario, al menos, como el siguiente.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-09-10-03-34-magento-configuracion-reglas.png"><img class="aligncenter size-medium wp-image-2348" title="Formulario standard de configuración en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-09-10-03-34-magento-configuracion-reglas-300x93.png" alt="" width="300" height="93" /></a></p>
<p>Está claro, el ejemplo es de lo más básico. Contamos con varios tipos de campos que nos permiten manejarnos con cierta flexibilidad al momento de definir nuestras configuraciones.</p>
<p>Dentro de esas posibilidades existe una opción (que no suele verse muy seguido) que nos permite indicar que si un campo cambia de valor, nos muestre (o no) otros campos.</p>
<p>Guiándonos por la primera imagen, la lógica sería la siguiente: si el campo &#8220;Condición&#8221; equivale a No, mostramos el campo &#8220;Valor A&#8221;.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-09-10-03-35-magento-configuracion-dependencia.png"><img class="aligncenter size-medium wp-image-2349" title="Configuración con dependencia entre campos en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-09-10-03-35-magento-configuracion-dependencia-300x73.png" alt="" width="300" height="73" /></a></p>
<p>Y ahora, si el campo &#8220;Condición&#8221; cambia a Si, ocultamos el campo &#8220;Valor A&#8221; y mostramos el campo &#8220;Valor B&#8221;.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-09-10-03-36-magento-configuracion-dependencia.png"><img class="aligncenter size-medium wp-image-2350" title="Configuración con dependencia entre campos en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-09-10-03-36-magento-configuracion-dependencia-300x78.png" alt="" width="300" height="78" /></a></p>
<p>Lograr el comportamiento es bastante sencillo (no, no es necesario enviar otro cohete a luna).</p>
<p><span id="more-2347"></span>Repasemos el código usado para la primera imagen.</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;fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;condicion</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>Condicion<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_yesno<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;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>1<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>1<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;/condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valor_a</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>Valor A<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>text<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>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>1<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>1<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;/valor_a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valor_b</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>Valor B<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>text<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>3<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>1<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>1<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;/valor_b<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Desde Magento 1.4 existe un parámetro adicional que nos permite indicar la relación (y visibilidad) de un campo según el valor de otro.</p>
<p>El parámetro se llama &#8220;depends&#8221; e indica el campo con el que se relaciona y el valor que debe tener para que nuestro campo se muestre.</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;depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>El ejemplo completo nos 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;fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;condicion</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>Condicion<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_yesno<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;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>1<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>1<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;/condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valor_a</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>Valor A<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>text<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>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>1<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>1<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;depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/valor_a<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;valor_b</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>Valor B<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>text<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>3<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>1<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>1<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;depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/condicion<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/depends<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Descripción del segundo campo<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/comment<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/valor_b<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fields<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Este pequeño truco nos permite mejorar la presentación de nuestra configuración con muy poco esfuerzo.</p>
<p>Cabe aclarar que no es la única forma en que podemos mejorar la forma de ingresar parámetros de configuración, ya que podemos implementar nuestros propios source para los campos.</p>
<p>Un ejemplo de esto último puede verse en el post de Robert Popovic sobre <a href="http://magebase.com/magento-tutorials/quick-tip-using-a-frontend-model-for-your-module-configuration-parameter/">cómo implementar modelos personalizados para los parámetros de la configuración</a>.</p>
<p>&nbsp;</p>
<p>(Todavía no tengo seguridad sobre si el título describe correctamente el contenido del post)</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2347" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/" title="Cómo hacer un módulo con soporte multistore en Magento">Cómo hacer un módulo con soporte multistore en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo agregar atributos a una categoría en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/#comments</comments>
		<pubDate>Thu, 18 Aug 2011 01:44:43 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[atributos]]></category>
		<category><![CDATA[categorías]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2314</guid>
		<description><![CDATA[Entre las tantas personalizaciones que normalmente se hacen en un tienda, es posible que necesitemos agregar atributos a las categorías. Dado que Magento no ofrece la posibilidad de gestionar los atributos de ésta entidad desde el backend, vamos a ver &#8230; <a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Entre las tantas personalizaciones que normalmente se hacen en un tienda, es posible que necesitemos agregar atributos a las categorías.</p>
<p>Dado que <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/">Magento</a> no ofrece la posibilidad de gestionar los atributos de ésta entidad desde el backend, vamos a ver cómo agregar uno nuevo a través de nuestros módulos.</p>
<p>En éste caso, vamos a usar un módulo (como siempre: Dc_Test) para agregar el atributo.</p>
<p>Dc_Test va a tener sólo tres archivos. El primero, es la configuración del módulo y estará ubicado en /app/code/local/Dc/Test/etc/config.xml.</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</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>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Dc_Test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Dc_Test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dc_Test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<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><span id="more-2314"></span>Luego, vamos a especificar las propiedades de nuestro atributo en el instalador, que se encontrará en /app/code/local/Dc/Test/sql/test_setup/mysql4-install-0.1.0.php.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$installer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'type'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'backend'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'frontend'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'label'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'My test attribute'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'input'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'text'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'class'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'source'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'global'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'required'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'user_defined'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'default'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'searchable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'filterable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'comparable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible_on_front'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'unique'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'position'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Por último, vamos a dejar habilitado el módulo dentro de <a title="la evolución del eCommerce" href="http://www.magentocommerce.com/">Magento</a>, agregando el archivo /app/etc/modules/Dc_Test.xml.</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</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>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Dc_Test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>true<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/active<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>local<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/codePool<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Dc_Test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<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>Paso siguiente, ingresamos al backend y si estamos utilizando cache, lo refrescamos.</p>
<p>La próxima vez que ingresemos a la edición de categorías debería verse lo siguiente.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-00-59-magento-atributo-personalizado-categoria.png"><img class="aligncenter size-medium wp-image-2321" title="Atributo personalizado para la categoría en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-00-59-magento-atributo-personalizado-categoria-300x186.png" alt="" width="300" height="186" /></a></p>
<p>El ejemplo sólo agrega un atributo de tipo texto con un input para llenar el valor, pero podemos utilizar cualquiera de los tipos de campos que nos ofrece la plataforma.</p>
<p>Si necesitáramos un atributo para manejar una imagen adicional, el setup podría quedar así:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$installer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test_picture'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'type'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'varchar'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'backend'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'catalog/category_attribute_backend_image'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'frontend'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'label'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Test Picture'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'input'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'image'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'class'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'source'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'global'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'required'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'user_defined'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'default'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'searchable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'filterable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'comparable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible_on_front'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'unique'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'position'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-01-23-magento-atributo-imagen-categoria.png"><img class="aligncenter size-medium wp-image-2318" title="Atributo de tipo imagen para las categorías en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-01-23-magento-atributo-imagen-categoria-300x116.png" alt="" width="300" height="116" /></a></p>
<p>Puede ser un campo booleano haciendo uso de los modelos de <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: #000088;">$installer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test_yes_no'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'type'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'int'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'backend'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'frontend'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'label'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Test Yes/No'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'input'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'select'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'class'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'source'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'eav/entity_attribute_source_boolean'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'global'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'required'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'user_defined'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'default'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'searchable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'filterable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'comparable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible_on_front'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'unique'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'position'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-01-25-magento-atributo-booleano-categoria.png"><img class="aligncenter size-medium wp-image-2319" title="Atributo de tipo booleano para la categoría en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-01-25-magento-atributo-booleano-categoria-300x132.png" alt="" width="300" height="132" /></a></p>
<p>O incluso podemos crear nuestros propios modelos para llenar los valores de un atributo.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$installer</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">startSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttribute</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'catalog_category'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test_custom'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                        <span style="color: #0000ff;">'type'</span>              <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'int'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'backend'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'frontend'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'label'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Test Custom'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'input'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'select'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'class'</span>             <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'source'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'test/entity_attribute_source_test'</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'global'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'required'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'user_defined'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'default'</span>           <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'searchable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'filterable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'comparable'</span>        <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'visible_on_front'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'unique'</span>            <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
                        <span style="color: #0000ff;">'position'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">,</span>
                    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$installer</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">endSetup</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Y agregamos el modelo que nos dará los valores. El archivo estará, para el ejemplo, en /app/code/local/Dc/Test/Model/Entity/Attribute/Source/Test.php.</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_Test_Model_Entity_Attribute_Source_Test <span style="color: #000000; font-weight: bold;">extends</span> Mage_Eav_Model_Entity_Attribute_Source_Table
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getAllOptions<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: #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: #0000ff;">'none'</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;">'adminhtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'No Test'</span><span style="color: #009900;">&#41;</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: #0000ff;">'test1'</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;">'adminhtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Test 1'</span><span style="color: #009900;">&#41;</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: #0000ff;">'test2'</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;">'adminhtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Test 2'</span><span style="color: #009900;">&#41;</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: #0000ff;">'test3'</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;">'adminhtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Test 3'</span><span style="color: #009900;">&#41;</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></pre></div></div>

<p>Para que éste modelo sea accesible es necesario modificar el archivo config.xml del módulo. La versión final debería verse así:</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;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</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>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Dc_Test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>0.1.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Dc_Test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/modules<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;global<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dc_Test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/module<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Mage_Catalog_Model_Resource_Eav_Mysql4_Setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
               <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>core_setup<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/use<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/connection<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test_setup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/resources<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dc_Test_Model<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/models<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/global<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>El resultado de ésta modificación sería:</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-01-33-magento-atributo-custom-categoria.png"><img class="aligncenter size-medium wp-image-2320" title="Atributo de tipo dropdown con valores propios para las categorías en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-08-17-01-33-magento-atributo-custom-categoria-300x125.png" alt="" width="300" height="125" /></a></p>
<p>&nbsp;</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2314" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/" title="Cómo hacer un módulo con soporte multistore en Magento">Cómo hacer un módulo con soporte multistore en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo modificar valores de configuración vía código en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 09:00:13 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2299</guid>
		<description><![CDATA[En algunos escenarios es posible que ante ciertas acciones o resultados, debamos modificar algún valor que se encuentra en la configuración general de Magento. Para modificar un valor de la configuración general de forma programática (si, suena rara la palabra &#8230; <a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>En algunos escenarios es posible que ante ciertas acciones o resultados, debamos modificar algún valor que se encuentra en la configuración general de Magento.</p>
<p>Para modificar un valor de la configuración general de forma programática (si, suena rara la palabra al traducirla) sólo necesitamos 3 líneas de código, la clave que queremos actualizar y el nuevo valor.</p>
<p>Para el ejemplo, vamos a poner la tienda en modo demo.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_new_value</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$model</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Mage_Core_Model_Config<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$model</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">saveConfig</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'design/head/demonotice'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$_new_value</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'default'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</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;">cleanCache</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>De ésta forma, con éste sencillo tip, podemos modificar comportamientos generales de la tienda.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2299" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/" title="Cómo hacer un módulo con soporte multistore en Magento">Cómo hacer un módulo con soporte multistore en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cómo hacer un módulo con soporte multistore en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/#comments</comments>
		<pubDate>Tue, 31 May 2011 21:20:07 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2242</guid>
		<description><![CDATA[Una de las características que no necesita presentación en Magento es su capacidad de ser multistore. Si estuviéramos armando un módulo para mostrar contenido en el frontend de una tienda, deberíamos tener en cuenta ésta característica. (Por más obvio que &#8230; <a href="http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Una de las características que no necesita presentación en Magento es su capacidad de ser multistore.</p>
<p>Si estuviéramos armando un módulo para mostrar contenido en el frontend de una tienda, deberíamos tener en cuenta ésta característica. (Por más obvio que suena, aún hoy siguen apareciendo módulos que no acusan recibo de esto)</p>
<p>Agregar ésta posibilidad a nuestro módulo es algo realmente sencillo. Para el ejemplo, vas a seguir jugando con el ya ultra modificado módulo Dc_Test.</p>
<p>Una vez que hayamos activado el módulo (como siempre, <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">el creador de Módulos</a> es de gran ayuda), veríamos una grilla y un formulario como los siguientes.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-28-19-39-magento-grilla-generica.png"><img class="aligncenter size-medium wp-image-2251" title="Grilla armada con el generador de Módulos para Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-28-19-39-magento-grilla-generica-300x173.png" alt="" width="300" height="173" /></a></p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-28-19-40-magento-formulario-generico.png"><img class="aligncenter size-medium wp-image-2252" title="Formulario armado con el generador de Módulos para Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-28-19-40-magento-formulario-generico-300x252.png" alt="" width="300" height="252" /></a></p>
<p>Ahora lo que vamos a hacer es agregar la posibilidad de administrar nuestros registros por store view (ya sea que lo quieran usar por idioma o por tienda).</p>
<p><span id="more-2242"></span>Las modificaciones las vamos a hacer en 5 archivos de nuestro módulo:</p>
<ul>
<li>Dc/Test/Block/Adminhtml/Test/Edit/Tab/Form.php</li>
<li>Dc/Test/Block/Adminhtml/Test/Grid.php</li>
<li>Dc/Test/etc/config.xml</li>
<li>Dc/Test/Model/Mysql4/Test/Collection.php</li>
<li>Dc/Test/Model/Mysql4/Test.php</li>
</ul>
<p>La primera modificación la hacemos sobre Dc/Test/Block/Adminhtml/Test/Edit/Tab/Form.php y, sólo como ejemplo, luego del campo Status agregamos el siguiente código.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isSingleStoreMode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <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;">'store_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'multiselect'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'stores[]'</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;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Store View'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'title'</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;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Store View'</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;">'values'</span>    <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getSingleton</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml/system_store'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStoreValuesForForm</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</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>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <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;">'store_id'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'hidden'</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
        <span style="color: #0000ff;">'name'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'stores[]'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'value'</span>     <span style="color: #339933;">=&gt;</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Una vez que guardemos, y siempre y cuando tengan más de un Store View creado, ya se verían los cambios en el formulario.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-02-04-magento-formulario-multi-storeview.png"><img class="aligncenter size-medium wp-image-2253" title="Formulario con soporte multi store view en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-02-04-magento-formulario-multi-storeview-300x224.png" alt="" width="300" height="224" /></a></p>
<p>Ahora necesitamos modificar la grilla para que nos muestre ésta información. Editamos el archivo Dc/Test/Block/Adminhtml/Test/Grid.php y, siempre a manera de ejemplo, antes de la columna Status, agregamos:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isSingleStoreMode</span><span style="color: #009900;">&#40;</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: #004000;">addColumn</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'store_id'</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;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Store View'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'index'</span>         <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'store_id'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'type'</span>          <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'store'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'store_all'</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;">'store_view'</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;">'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;">'filter_condition_callback'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_filterStoreCondition'</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>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Luego agregaremos también estos dos métodos dentro de la misma clase.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _afterLoadCollection<span style="color: #009900;">&#40;</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: #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;">walk</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'afterLoad'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    parent<span style="color: #339933;">::</span>_afterLoadCollection<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _filterStoreCondition<span style="color: #009900;">&#40;</span><span style="color: #000088;">$collection</span><span style="color: #339933;">,</span> <span style="color: #000088;">$column</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: #000088;">$value</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$column</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFilter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getValue</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000088;">$this</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;">addStoreFilter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ahora nuestra grilla nos mostrará la información y nos permitirá filtrar por éstos valores.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-02-07-magento-grilla-multi-storeview.png"><img class="aligncenter size-medium wp-image-2254" title="Grilla con soporte multi sotre view en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-02-07-magento-grilla-multi-storeview-300x62.png" alt="" width="300" height="62" /></a></p>
<p>Hasta acá lo más sencillo. Ahora tenemos que modificar la forma en la que se manejarán esos datos.</p>
<p>Lo primero, será agregar una tabla a la que, para ser ordenados, podemos llamar test_store. En nuestro script de instalación (o actualización) el sql debería verse así:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">CREATE TABLE  <span style="color: #009900;">&#123;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test_store'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#125;</span> <span style="color: #009900;">&#40;</span>
  test_id int<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">11</span><span style="color: #009900;">&#41;</span> unsigned NOT <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span>
  store_id smallint<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span> unsigned NOT <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">,</span>
  PRIMARY <span style="color: #990000;">KEY</span>  <span style="color: #009900;">&#40;</span>test_id<span style="color: #339933;">,</span>store_id<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #990000;">KEY</span> `FK_TEST_STORE_STORE` <span style="color: #009900;">&#40;</span>store_id<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  CONSTRAINT `FK_TEST_STORE_TEST` FOREIGN <span style="color: #990000;">KEY</span> <span style="color: #009900;">&#40;</span>`test_id`<span style="color: #009900;">&#41;</span> REFERENCES `test` <span style="color: #009900;">&#40;</span>`test_id`<span style="color: #009900;">&#41;</span> ON DELETE CASCADE ON UPDATE CASCADE<span style="color: #339933;">,</span>
  CONSTRAINT `FK_TEST_STORE_STORE` FOREIGN <span style="color: #990000;">KEY</span> <span style="color: #009900;">&#40;</span>`store_id`<span style="color: #009900;">&#41;</span> REFERENCES `core_store` <span style="color: #009900;">&#40;</span>`store_id`<span style="color: #009900;">&#41;</span> ON DELETE CASCADE ON UPDATE CASCADE
<span style="color: #009900;">&#41;</span> ENGINE<span style="color: #339933;">=</span>InnoDB <span style="color: #b1b100;">DEFAULT</span> CHARSET<span style="color: #339933;">=</span>utf8<span style="color: #339933;">;</span></pre></div></div>

<p>El siguiente paso es agregar la entidad dentro de nuestros modelos. Para esto vamos a modificar el archivo Dc/Test/etc/config.xml y dentro de los Models, en las entidades, vamos a agregar:</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;test_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>test_store<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Ahora nuestra definición quedaría así.</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;test_mysql4<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Dc_Test_Model_Mysql4<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;entities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>test<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;test_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>test_store<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/table<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test_store<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/entities<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/test_mysql4<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Tercer paso. Buscamos el archivo Dc/Test/Model/Mysql4/Test/Collection.php y vamos a agregar el método addStoreFilter.</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> addStoreFilter<span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span><span style="color: #339933;">,</span> <span style="color: #000088;">$withAdmin</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</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;">$store</span> instanceof Mage_Core_Model_Store<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$store</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$store</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSelect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">join</span><span style="color: #009900;">&#40;</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'store_table'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test/test_store'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'main_table.test_id = store_table.test_id'</span><span style="color: #339933;">,</span>
        <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'store_table.store_id in (?)'</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$withAdmin</span> ? <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$store</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$store</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #339933;">-&gt;</span><span style="color: #004000;">group</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'main_table.test_id'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Para finalizar, editamos Dc/Test/Model/Mysql4/Test.php. Aquí se agregaran 3 métodos que serán los que hagan la magia con los datos.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _afterLoad<span style="color: #009900;">&#40;</span>Mage_Core_Model_Abstract <span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getReadAdapter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">select</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test/test_store'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test_id = ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getReadAdapter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fetchAll</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$select</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$storesArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$storesArray</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$row</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'store_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'store_id'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$storesArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span>_afterLoad<span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</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>Mage_Core_Model_Abstract <span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$condition</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getWriteAdapter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">quoteInto</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test_id = ?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getWriteAdapter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delete</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test/test_store'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$condition</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#41;</span><span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'stores'</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$store</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$storeArray</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$storeArray</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'test_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$storeArray</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'store_id'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$store</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getWriteAdapter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">insert</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test/test_store'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$storeArray</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">return</span> parent<span style="color: #339933;">::</span>_afterSave<span style="color: #009900;">&#40;</span><span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">function</span> _getLoadSelect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$select</span> <span style="color: #339933;">=</span> parent<span style="color: #339933;">::</span>_getLoadSelect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$field</span><span style="color: #339933;">,</span> <span style="color: #000088;">$value</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</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: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStoreId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$select</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">join</span><span style="color: #009900;">&#40;</span>
            <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'ts'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getTable</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test/test_store'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMainTable</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'.test_id = ts.test_id'</span>
        <span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">where</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'is_active=1 AND ts.store_id in (0, ?) '</span><span style="color: #339933;">,</span> <span style="color: #000088;">$object</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStoreId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">order</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'store_id DESC'</span><span style="color: #009900;">&#41;</span>
        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</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: #b1b100;">return</span> <span style="color: #000088;">$select</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Ahora si, con todas nuestras modificaciones implementadas, volvemos al backend a probar el módulo. Deberían estar viendo algo similar a:</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-03-32-magento-formulario-multi-storeview.png"><img class="aligncenter size-medium wp-image-2255" title="Formulario multi store view en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-03-32-magento-formulario-multi-storeview-300x241.png" alt="" width="300" height="241" /></a></p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-03-33-magento-valores-grilla.png"><img class="aligncenter size-medium wp-image-2256" title="Grilla multi store view en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-05-29-03-33-magento-valores-grilla-300x95.png" alt="" width="300" height="95" /></a></p>
<p>De ésta forma, nuestro módulo ya soporta múltiples store views.</p>
<p>El paso final para utilizar éstos valores en el frontend es aplicar el filtro al momento de pedir la colección.</p>
<p>Cuando ejecutemos el getModel de éste módulo, deberíamos hacerlo de la siguiente manera.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">Mage<span style="color: #339933;">::</span><span style="color: #004000;">getModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test/test'</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;">addStoreFilter</span><span style="color: #009900;">&#40;</span>Mage<span style="color: #339933;">::</span><span style="color: #004000;">app</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getStore</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getItems</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>De acá en más será simplemente hacer la iteración para obtener los datos.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2242" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/05/31/como-hacer-un-modulo-con-soporte-multistore-en-magento/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cómo obtener la versión de un módulo en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/05/17/como-obtener-la-version-de-un-modulo-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/05/17/como-obtener-la-version-de-un-modulo-en-magento/#comments</comments>
		<pubDate>Tue, 17 May 2011 03:15:55 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2230</guid>
		<description><![CDATA[Podría darse el caso en el cual necesitemos obtener información de un módulo para tomar ejecutar ciertas acciones. Definitivamente es un escenario pensado para cuando creamos extensiones. Para el caso de un desarrollo completo, nuestro control del código y de &#8230; <a href="http://www.damianculotta.com.ar/2011/05/17/como-obtener-la-version-de-un-modulo-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Podría darse el caso en el cual necesitemos obtener información de un módulo para tomar ejecutar ciertas acciones.</p>
<p>Definitivamente es un escenario pensado para cuando creamos extensiones. Para el caso de un desarrollo completo, nuestro control del código y de la tienda es total.</p>
<p>Supongamos entonces que tenemos al ya ultra trillado módulo Dc_Test. Vamos a considerar que nuestro módulo se encarga de interactuar o incluso modificar algún comportamiento del módulo Mage_Newsletter.</p>
<p>No recuerdo ahora las versiones, pero si que tuve que lidiar alguna vez con modelos de ese módulo, que de una versión a otra habían sido eliminados.</p>
<p>La solución ante ese escenario sería reescribir el código de forma tal que funcione de la misma forma sin importar la versión, pero ¿y si existiera un caso en el cual esto no fuera posible?.</p>
<p>Si llegáramos a éste punto, lo que podemos hacer es validar la versión del módulo con el que estamos trabajando. De ésta forma podríamos invocar una acción u otra según las versiones, puntualmente, conflictivas.</p>
<p><span id="more-2230"></span>Para obtener ese dato sólo necesitamos ejecutar una función.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</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;">getModuleConfig</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mage_Newsletter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">version</span><span style="color: #339933;">;</span></pre></div></div>

<p>El resultado de la llamada sería: 0.8.3.</p>
<p>Además de ésta información, podemos validar si el módulo se encuentra activo, ver en que pool se encuentra el módulo y, además, preguntar por las dependencias del mismo.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</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;">getModuleConfig</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mage_Newsletter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">active</span><span style="color: #339933;">;</span></pre></div></div>

<p>Nos mostrará: true.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">echo</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;">getModuleConfig</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mage_Newsletter'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">codePool</span><span style="color: #339933;">;</span></pre></div></div>

<p>Y en éste caso: core.</p>
<p>Un pequeño tip que puede llegar a ahorrar algunas horas de coding.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2230" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/05/17/como-obtener-la-version-de-un-modulo-en-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Cómo modificar los botones de la grilla en un módulo de Magento</title>
		<link>http://www.damianculotta.com.ar/2011/02/20/como-modificar-los-botones-de-la-grilla-en-un-modulo-de-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/02/20/como-modificar-los-botones-de-la-grilla-en-un-modulo-de-magento/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 21:30:16 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2148</guid>
		<description><![CDATA[Cuando utilizamos el generador automático de modulos, nuestra grilla viene un botón para agregar nuevos registros. En algunas oportunidades, posiblemente necesitemos hacer algunos cambios, ya sea agregando acciones o quitando las que obtenemos por defecto. Para comenzar, tenemos que identificar &#8230; <a href="http://www.damianculotta.com.ar/2011/02/20/como-modificar-los-botones-de-la-grilla-en-un-modulo-de-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Cuando utilizamos el <a title="artículo en la wiki de Magento" href="http://www.magentocommerce.com/wiki/custom_module_with_custom_database_table" target="_self">generador automático de modulos</a>, nuestra grilla viene un botón para agregar nuevos registros.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-13-54-magento-grilla.png"><img class="aligncenter size-medium wp-image-2152" title="Grilla por defecto en un módulo de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-13-54-magento-grilla-300x93.png" alt="" width="300" height="93" /></a></p>
<p>En algunas oportunidades, posiblemente necesitemos hacer algunos cambios, ya sea agregando acciones o quitando las que obtenemos por defecto.</p>
<p>Para comenzar, tenemos que identificar la clase que se encarga de definir dicha sección. Suponiendo que el módulo se llama Dc_Test, tenemos que buscar el siguiente archivo: /app/code/local/Dc/Test/Block/Adminhtml/Test.php.</p>
<p>Lo que vamos a ver en el archivo es 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_Test_Block_Adminhtml_Test <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Grid_Container <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> __construct<span style="color: #009900;">&#40;</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>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'adminhtml_test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headerText <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Item Manager'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addButtonLabel <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</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><span id="more-2148"></span>Si quisiéramos eliminar el botón &#8220;Add item&#8221; que se genera automáticamente, vamos a tener que hacer uso del método _removeButton().</p>
<p>Para que funcione, el código deberá quedar de ésta forma.</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_Test_Block_Adminhtml_Test <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Grid_Container <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> __construct<span style="color: #009900;">&#40;</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>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'adminhtml_test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headerText <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Item Manager'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addButtonLabel <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_removeButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add'</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>Ahora, la grilla nos quedará como en la imagen.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-15-22-magento-grilla-sin-botones.png"><img class="aligncenter size-medium wp-image-2151" title="Grilla sin botones en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-15-22-magento-grilla-sin-botones-300x95.png" alt="" width="300" height="95" /></a></p>
<p>El segundo escenario posible es el de modificar y/o agregar acciones. Para esto tenemos dos formas diferentes de lograrlo.</p>
<p>Si queremos modificar valores de un botón ya existente, vamos a hacer uso del método _updateButton(). Suponiendo que no hemos removido el botón original, vamos a cambiar el texto y la acción que realiza.</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_Test_Block_Adminhtml_Test <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Grid_Container <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> __construct<span style="color: #009900;">&#40;</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>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'adminhtml_test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headerText <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Item Manager'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addButtonLabel <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$$this</span><span style="color: #339933;">-&gt;</span>_updateButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">,</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'adminhtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Updated label'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_updateButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'add'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'onclick'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'alert(\'New action event\')'</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>Luego de esto, vemos que el texto fue modificado y también su acción.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-16-44-magento-botones-grilla-modificados.png"><img class="aligncenter size-medium wp-image-2154" title="Efecto de actualizar un botón en existente en una grilla" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-16-44-magento-botones-grilla-modificados-300x87.png" alt="" width="300" height="87" /></a></p>
<p>El otro caso sería el de agregar nuevas acciones. Para esto tenemos que hacer uso del último método: _addButton().</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_Test_Block_Adminhtml_Test <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Grid_Container <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> __construct<span style="color: #009900;">&#40;</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>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'adminhtml_test'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_headerText <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Item Manager'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addButtonLabel <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Add Item'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</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> <span style="color: #0000ff;">'My test button'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'onclick'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'alert(\'Test button with custom action.\')'</span><span style="color: #339933;">,</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: #009900;">&#125;</span></pre></div></div>

<p>Como resultado, ésto es lo que obtenemos.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-16-51-magento-botones-personalizados.png"><img class="aligncenter size-medium wp-image-2155" title="Botones personalizados en las grillas de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-16-51-magento-botones-personalizados-300x118.png" alt="" width="300" height="118" /></a></p>
<p>De ésta forma ya podemos manejar los botones que se muestran en la grilla, personalizando tanto su leyenda como su acción.</p>
<p>Lo último que nos falta agregar son los estilos. Si prestamos atención a la última imagen, el botón original presenta un icono, mientras que el agregado no lo hace.</p>
<p>Para esto necesitamos pasarle un parámetro adicional al botón: class.</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>_addButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</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> <span style="color: #0000ff;">'My test button'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'onclick'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'alert(\'Test button with custom action.\')'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'class'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'add'</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>Los valores que podemos usar son add, save, delete y back.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-06-magento-boton-agregar.png"><img class="aligncenter size-full wp-image-2156" title="Estilo para el botón Add de las grillas de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-06-magento-boton-agregar.png" alt="" width="263" height="104" /></a></p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-08-magento-boton-guardar.png"><img class="aligncenter size-full wp-image-2157" title="Estilo para el botón Save de las grillas de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-08-magento-boton-guardar.png" alt="" width="267" height="102" /></a></p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-09-magento-boton-borrar.png"><img class="aligncenter size-full wp-image-2158" title="Estilo para el botón Delete de las grillas de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-09-magento-boton-borrar.png" alt="" width="260" height="110" /></a></p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-10-magento-boton-volver.png"><img class="aligncenter size-full wp-image-2159" title="Estilo para el botón Back de las grillas de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-10-magento-boton-volver.png" alt="" width="247" height="80" /></a></p>
<p><strong>La yapa</strong></p>
<p>Estos métodos (implementándolos de la misma forma) sirven para modificar los botones que se tienen en los formularios.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-16-magento-botones-formularios.png"><img class="aligncenter size-medium wp-image-2160" title="Botones por defecto utilziados en los formularios de Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-02-20-17-16-magento-botones-formularios-300x30.png" alt="" width="300" height="30" /></a></p>
<p>La clase que maneja éstos botones, siguiendo con mi módulo de ejemplo, es: Dc_Test_Block_Adminhtml_Test_Edit.</p>
<p>Si revisamos el archivo, nos encontraremos con 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;">class</span> Dc_Test_Block_Adminhtml_Test_Edit <span style="color: #000000; font-weight: bold;">extends</span> Mage_Adminhtml_Block_Widget_Form_Container <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> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        parent<span style="color: #339933;">::</span>__construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_objectId <span style="color: #339933;">=</span> <span style="color: #0000ff;">'id'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_blockGroup <span style="color: #339933;">=</span> <span style="color: #0000ff;">'test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_controller <span style="color: #339933;">=</span> <span style="color: #0000ff;">'adminhtml_test'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_updateButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'save'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">,</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Save Item'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_updateButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'delete'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'label'</span><span style="color: #339933;">,</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">helper</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Delete Item'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_addButton<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'saveandcontinue'</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;">'adminhtml'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Save And Continue Edit'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'onclick'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'saveAndContinueEdit()'</span><span style="color: #339933;">,</span>
            <span style="color: #0000ff;">'class'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'save'</span><span style="color: #339933;">,</span>
        <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #339933;">-</span><span style="color: #cc66cc;">100</span><span style="color: #009900;">&#41;</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> getHeaderText<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #339933;">...</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Es ahí donde tenemos que empezar a hacer los ajustes para personalizar el formulario.</p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2148" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/02/20/como-modificar-los-botones-de-la-grilla-en-un-modulo-de-magento/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agregar columnas a la grilla de Productos en Magento</title>
		<link>http://www.damianculotta.com.ar/2011/01/23/agregar-columnas-a-la-grilla-de-productos-en-magento/</link>
		<comments>http://www.damianculotta.com.ar/2011/01/23/agregar-columnas-a-la-grilla-de-productos-en-magento/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 04:56:35 +0000</pubDate>
		<dc:creator>Damián</dc:creator>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[programación]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.damianculotta.com.ar/?p=2083</guid>
		<description><![CDATA[Una pequeña pero útil customización que suelen pedirme es la de agregar más información en la grilla de productos y, en otros casos, en la grilla de productos de las categorías. La idea es proveer de mayor cantidad de filtros &#8230; <a href="http://www.damianculotta.com.ar/2011/01/23/agregar-columnas-a-la-grilla-de-productos-en-magento/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Una pequeña pero útil customización que suelen pedirme es la de agregar más información en la grilla de productos y, en otros casos, en la grilla de productos de las categorías. La idea es proveer de mayor cantidad de filtros según la necesidad de cada catalogación.</p>
<p>La grilla de productos, por defecto, tiene éstas columnas.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-10-magento-grilla-productos.png"><img class="aligncenter size-medium wp-image-2096" title="Grilla de Productos en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-10-magento-grilla-productos-300x98.png" alt="" width="300" height="98" /></a></p>
<p>Si bien hay varios tipos de filtros, los que suelo usar en éstas modificaciones son los campos de texto y los dropdown.</p>
<p>Por ejemplo, para agregar la columna Descripción a la grilla, y que funcione como filtro, debemos realizar el siguiente cambio en el archivo /app/code/core/Mage/Adminhtml/Block/Catalog/Product/Grid.php.</p>
<p>(En realidad, modificamos el archivo del Core sólo para el ejemplo. Lo que hay que hacer es aplicar una reescritura del bloque).</p>
<p><span id="more-2083"></span>Como decía, vamos a editar el archivo y vamos a agregar al método _prepareCollection() el atributo que queremos utilizar en la definición de la colección.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$collection</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;">'catalog/product'</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;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attribute_set_id'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type_id'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#41;</span> <span style="color: #666666; font-style: italic;">// ESTE ES NUESTRO NUEVO ATRIBUTO</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">joinField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'qty'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'cataloginventory/stock_item'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'qty'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'product_id=entity_id'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'{{table}}.stock_id=1'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'left'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Luego, en el método _prepareColumns() lo siguiente a la definición de la columna Qty.</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;">'description'</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;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
         <span style="color: #0000ff;">'index'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'description'</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>De ésta forma, la grilla debería verse como ésta.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-14-magento-grilla-productos-descripcion.png"><img class="aligncenter size-medium wp-image-2097" title="Grilla de Productos con columna de texto adicional en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-14-magento-grilla-productos-descripcion-300x99.png" alt="" width="300" height="99" /></a></p>
<p>Desde ahora, podremos ver el contenido de ese atributo y utilizarlo como filtro de búsqueda.</p>
<p>Si quisiéramos usar un dropdown, como el caso del atributo Fabricante, el código a utilizar nos debería quedar de la siguiente manera.</p>
<p>En el método _prepareCollection() la llamada para la definición del collection debe agregar el atributo. Al igual que en el ejemplo anterior.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$collection</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;">'catalog/product'</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;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'sku'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attribute_set_id'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'type_id'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">addAttributeToSelect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'manufacturer'</span><span style="color: #009900;">&#41;</span>
                <span style="color: #339933;">-&gt;</span><span style="color: #004000;">joinField</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'qty'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'cataloginventory/stock_item'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'qty'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'product_id=entity_id'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'{{table}}.stock_id=1'</span><span style="color: #339933;">,</span>
                    <span style="color: #0000ff;">'left'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>El siguiente paso es agregar la columna, la cual requiere de algunas líneas más de código.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$_attribute</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;">'eav/entity_attribute'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_attribute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loadByCode</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'manufacturer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$_attribute_values</span> <span style="color: #339933;">=</span> Mage<span style="color: #339933;">::</span><span style="color: #004000;">getResourceModel</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'eav/entity_attribute_option_collection'</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setAttributeFilter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getId</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">setStoreFilter</span><span style="color: #009900;">&#40;</span> Mage_Core_Model_App<span style="color: #339933;">::</span><span style="color: #004000;">ADMIN_STORE_ID</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span>
                        <span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$manufacturer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_attribute_values</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$_manufacturer</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$manufacturer</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$_manufacturer</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'option_id'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_manufacturer</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'value'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<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;">'manufacturer'</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;">'catalog'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span>__<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Manufacturer'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'index'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'manufacturer'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'type'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'options'</span><span style="color: #339933;">,</span>
        <span style="color: #0000ff;">'options'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$manufacturer</span>
<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Ahora si, el resultado de éstas modificaciones nos debería mostrar la grilla con ésta nueva columna.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-15-magento-grilla-productos-fabricante.png"><img class="aligncenter size-medium wp-image-2098" title="Grilla de Productos con columna de tipo dropdown en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-15-magento-grilla-productos-fabricante-300x75.png" alt="" width="300" height="75" /></a></p>
<p>La segunda grilla que podemos modificar es la mostrada en la cuarta solapa en la edición de la Categoría. Con ésta modificación tendremos mayor comodidad si, por ejemplo, se crean categorías como marcas y el atributo manufacturer fue cargado. De ésta forma, asociar los productos correspondientes será muchísimo más rápido que utilizando otro criterio.</p>
<p>Para poder personalizar dicha grilla, nuestra modificación deberá recaer sobre el archivo /app/code/core/Mage/Adminhtml/Block/Catalog/Category/Tab/Product.php, en el cual aplicaremos exactamente el mismo código que ya probamos para la grilla de Productos.</p>
<p>Una vez hecha la modificación, pasaríamos de la grilla original.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-20-magento-grilla-productos-categoria.png"><img class="aligncenter size-medium wp-image-2099" title="Grilla de Productos dentro de una Categoría en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-20-magento-grilla-productos-categoria-300x96.png" alt="" width="300" height="96" /></a></p>
<p>A la grilla modificada.</p>
<p><a href="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-22-magento-grilla-categoria-atributo.png"><img class="aligncenter size-medium wp-image-2100" title="Columna con dropdown en la grilla de Productos de la Categoría en Magento" src="http://www.damianculotta.com.ar/wp-content/uploads/2011-01-22-13-22-magento-grilla-categoria-atributo-300x101.png" alt="" width="300" height="101" /></a></p>
 <img src="http://www.damianculotta.com.ar/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2083" 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/11/07/mejorando-el-seo-de-nuestros-modulos-en-magento/" title="Mejorando el SEO de nuestros módulos en Magento">Mejorando el SEO de nuestros módulos en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/10/10/agregar-validaciones-javascript-en-magento-de-forma-no-obstrusiva/" title="Agregar validaciones javascript en Magento de forma no obstrusiva">Agregar validaciones javascript en Magento de forma no obstrusiva</a></li><li><a href="http://www.damianculotta.com.ar/2011/09/12/configuraciones-dependientes-en-magento/" title="Configuraciones dependientes en Magento">Configuraciones dependientes en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/17/como-agregar-atributos-a-una-categoria-en-magento/" title="Cómo agregar atributos a una categoría en Magento">Cómo agregar atributos a una categoría en Magento</a></li><li><a href="http://www.damianculotta.com.ar/2011/08/15/como-modificar-valores-de-configuracion-via-codigo-en-magento/" title="Cómo modificar valores de configuración vía código en Magento">Cómo modificar valores de configuración vía código en Magento</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.damianculotta.com.ar/2011/01/23/agregar-columnas-a-la-grilla-de-productos-en-magento/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

