Mostrar el fabricante de un artículo en los pedidos del Back-office de Prestashop

31 octubre, 2014 |

Si te gusta, compártelo ;)

- Para Prestashop 1.5

Vamos a ver cómo añadir una columna que muestre el fabricante de determinado artículo en los pedidos de Prestashop (Backoffice). Concretamente añadiremos esta columna en la página que muestra los detalles de un determinado pedido, no en la lista de todos los pedidos. No hay ningún peligro porque no hay que tocar el núcleo de Prestashop.

Pedido de la lista de pedidos de Prestashop

Para añadir la nueva columna debemos editar el archivo prestashop/adminxxxx/themes/default/template/controllers/orders/helpers/view/view.tpl, teniendo en cuenta que adminxxxx es la carpeta admin y las xxxx su número correspondiente. En este archivo y aproximadamente por la línea 589 encontraremos la tabla con id orderProducts que debemos editar. Recordemos que esto es para Prestashop 1.5.

<table style="width: 100%;" cellspacing="0" cellpadding="0" class="table" id="orderProducts">
  <tr>
  <th height="39" align="center" style="width: 7%">&nbsp;</th>
  <th>{l s='Product'}</th>
  <th style="width: 15%; text-align: center">{l s='Unit Price'} <sup>*</sup></th>
  <th style="width: 4%; text-align: center">{l s='Qty'}</th>
  {if $display_warehouse}<th style="text-align: center">{l s='Warehouse'}</th>{/if}
  {if ($order->hasBeenPaid())}<th style="width: 3%; text-align: center">{l s='Refunded'}</th>{/if}
  {if ($order->hasBeenDelivered() || $order->hasProductReturned())}<th style="width: 3%; text-align: center">{l s='Returned'}</th>{/if}
  {if $stock_management}<th style="width: 10%; text-align: center">{l s='Available quantity'}</th>{/if}
  <th style="width: 10%; text-align: center">{l s='Total'} <sup>*</sup></th>
  <th colspan="2" style="display: none;" class="add_product_fields">&nbsp;</th>
  <th colspan="2" style="display: none;" class="edit_product_fields">&nbsp;</th>
  <th colspan="2" style="display: none;" class="standard_refund_fields"><img src="../img/admin/delete.gif" alt="{l s='Products:'}" />
  {if ($order->hasBeenDelivered() || $order->hasBeenShipped())}
  {l s='Return'}
  {elseif ($order->hasBeenPaid())}
  {l s='Refund'}
  {else}
  {l s='Cancel'}
  {/if}
  </th>
  <th style="width: 12%;text-align:right;display:none" class="partial_refund_fields">
  {l s='Partial refund'}
  </th>
  {if !$order->hasBeenDelivered()}
  <th style="width: 8%;text-align:center;">
  {l s='Action'}
  </th>
  {/if}
  </tr>
 {foreach from=$products item=product key=k}
  {* Include customized datas partial *}
  {include file='controllers/orders/_customized_data.tpl'}
 {* Include product line partial *}
  {include file='controllers/orders/_product_line.tpl'}
  {/foreach}
  {if $can_edit}
  {include file='controllers/orders/_new_product.tpl'}
  {/if}
  </table>

Simplemente debemos añadir la linea resaltada como se muestra en el código de abajo:

<th>{l s='Manufacturer'}</th>
<table style="width: 100%;" cellspacing="0" cellpadding="0" class="table" id="orderProducts">
  <tr>
  <th height="39" align="center" style="width: 7%">&nbsp;</th>
  <th>{l s='Product'}</th>
  <th>{l s='Manufacturer'}</th>
  <th style="width: 15%; text-align: center">{l s='Unit Price'} <sup>*</sup></th>
  <th style="width: 4%; text-align: center">{l s='Qty'}</th>
  {if $display_warehouse}<th style="text-align: center">{l s='Warehouse'}</th>{/if}
  {if ($order->hasBeenPaid())}<th style="width: 3%; text-align: center">{l s='Refunded'}</th>{/if}
  {if ($order->hasBeenDelivered() || $order->hasProductReturned())}<th style="width: 3%; text-align: center">{l s='Returned'}</th>{/if}
  {if $stock_management}<th style="width: 10%; text-align: center">{l s='Available quantity'}</th>{/if}
  <th style="width: 10%; text-align: center">{l s='Total'} <sup>*</sup></th>
  <th colspan="2" style="display: none;" class="add_product_fields">&nbsp;</th>
  <th colspan="2" style="display: none;" class="edit_product_fields">&nbsp;</th>
  <th colspan="2" style="display: none;" class="standard_refund_fields"><img src="../img/admin/delete.gif" alt="{l s='Products:'}" />
  {if ($order->hasBeenDelivered() || $order->hasBeenShipped())}
  {l s='Return'}
  {elseif ($order->hasBeenPaid())}
  {l s='Refund'}
  {else}
  {l s='Cancel'}
  {/if}
  </th>
  <th style="width: 12%;text-align:right;display:none" class="partial_refund_fields">
  {l s='Partial refund'}
  </th>
  {if !$order->hasBeenDelivered()}
  <th style="width: 8%;text-align:center;">
  {l s='Action'}
  </th>
  {/if}
  </tr>
 {foreach from=$products item=product key=k}
  {* Include customized datas partial *}
  {include file='controllers/orders/_customized_data.tpl'}
 {* Include product line partial *}
  {include file='controllers/orders/_product_line.tpl'}
  {/foreach}
  {if $can_edit}
  {include file='controllers/orders/_new_product.tpl'}
  {/if}
  </table>

Mostrar el nombre del fabricante en la nueva columna

Para mostrar el nombre del fabricante tenemos que editar el archivo prestashop/adminxxxx/themes/default/template/controllers/orders/_product_line.tpl. Este fragmento de código contiene funciones que muestran información de los productos relativa a los pedidos.

<tr{if isset($product.image) && $product.image->id && isset($product.image_size)} height="{$product['image_size'][1] + 7}"{/if}>
<td align="center">{if isset($product.image) && $product.image->id}{$product.image_tag}{/if}</td>
<td><a href="index.php?controller=adminproducts&id_product={$product['product_id']}&updateproduct&token={getAdminToken tab='AdminProducts'}">
<span class="productName">{$product['product_name']}</span><br />
{if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if}
{if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if}
</a></td>

Justo después de este código, alrededor de la línea 41, debemos insertar la siguiente etiqueta <td>:

<td>
{Manufacturer::getnamebyid($product.id_manufacturer)}
</td>

Quedando así:

<tr{if isset($product.image) && $product.image->id && isset($product.image_size)} height="{$product['image_size'][1] + 7}"{/if}>
<td align="center">{if isset($product.image) && $product.image->id}{$product.image_tag}{/if}</td>
<td><a href="index.php?controller=adminproducts&id_product={$product['product_id']}&updateproduct&token={getAdminToken tab='AdminProducts'}">
<span class="productName">{$product['product_name']}</span><br />
{if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if}
{if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if}
</a></td>
<td>
{Manufacturer::getnamebyid($product.id_manufacturer)}
</td>

Con esto habremos terminado. Si no aparece la nueva columna forzar compilación y borrar la caché de la tienda.


- Para Prestashop 1.6

En Prestashop 1.6 el resultado es el mismo, así como el procedimiento, solo cambia ligeramente el código en las partes que hemos visto. Este archivo...

<table class="table" id="orderProducts">
<thead>
<tr>
<th></th>
<th><span class="title_box ">{l s='Product'}</span></th>
<th>
<span class="title_box ">{l s='Unit Price'}</span>
<small class="text-muted">{$smarty.capture.TaxMethod}</small>
</th>
<th><span class="title_box ">{l s='Qty'}</span></th>
{if $display_warehouse}<th><span class="title_box ">{l s='Warehouse'}</span></th>{/if}
{if ($order->hasBeenPaid())}<th><span class="title_box ">{l s='Refunded'}</span></th>{/if}
{if ($order->hasBeenDelivered() || $order->hasProductReturned())}
<th><span class="title_box ">{l s='Returned'}</span></th>
{/if}
{if $stock_management}<th><span class="title_box ">{l s='Available quantity'}</span></th>{/if}
<th>
<span class="title_box ">{l s='Total'}</span>
<small class="text-muted">{$smarty.capture.TaxMethod}</small>
</th>
<th colspan="2" style="display: none;" class="add_product_fields"></th>
<th colspan="2" style="display: none;" class="edit_product_fields"></th>
<th colspan="2" style="display: none;" class="standard_refund_fields">
<i class="icon-minus-sign"></i>
{if ($order->hasBeenDelivered() || $order->hasBeenShipped())}
{l s='Return'}
{elseif ($order->hasBeenPaid())}
{l s='Refund'}
{else}
{l s='Cancel'}
{/if}
</th>
<th style="display:none" class="partial_refund_fields">
<span class="title_box ">{l s='Partial refund'}</span>
</th>
{if !$order->hasBeenDelivered()}
<th></th>
{/if}
</tr>
</thead>
<tbody>
{foreach from=$products item=product key=k}
{* Include customized datas partial *}
{include file='controllers/orders/_customized_data.tpl'}
{* Include product line partial *}
{include file='controllers/orders/_product_line.tpl'}
{/foreach}
{if $can_edit}
{include file='controllers/orders/_new_product.tpl'}
{/if}
</tbody>
</table>

... lo dejamos así:

<table class="table" id="orderProducts">
<thead>
<tr>
<th></th>
<th><span class="title_box ">{l s='Product'}</span></th>
<th><span class="title_box">{l s='Manufacturer'}</span></th>
<th>
<span class="title_box ">{l s='Unit Price'}</span>
<small class="text-muted">{$smarty.capture.TaxMethod}</small>
</th>
<th><span class="title_box ">{l s='Qty'}</span></th>
{if $display_warehouse}<th><span class="title_box ">{l s='Warehouse'}</span></th>{/if}
{if ($order->hasBeenPaid())}<th><span class="title_box ">{l s='Refunded'}</span></th>{/if}
{if ($order->hasBeenDelivered() || $order->hasProductReturned())}
<th><span class="title_box ">{l s='Returned'}</span></th>
{/if}
{if $stock_management}<th><span class="title_box ">{l s='Available quantity'}</span></th>{/if}
<th>
<span class="title_box ">{l s='Total'}</span>
<small class="text-muted">{$smarty.capture.TaxMethod}</small>
</th>
<th colspan="2" style="display: none;" class="add_product_fields"></th>
<th colspan="2" style="display: none;" class="edit_product_fields"></th>
<th colspan="2" style="display: none;" class="standard_refund_fields">
<i class="icon-minus-sign"></i>
{if ($order->hasBeenDelivered() || $order->hasBeenShipped())}
{l s='Return'}
{elseif ($order->hasBeenPaid())}
{l s='Refund'}
{else}
{l s='Cancel'}
{/if}
</th>
<th style="display:none" class="partial_refund_fields">
<span class="title_box ">{l s='Partial refund'}</span>
</th>
{if !$order->hasBeenDelivered()}
<th></th>
{/if}
</tr>
</thead>
<tbody>
{foreach from=$products item=product key=k}
{* Include customized datas partial *}
{include file='controllers/orders/_customized_data.tpl'}
{* Include product line partial *}
{include file='controllers/orders/_product_line.tpl'}
{/foreach}
{if $can_edit}
{include file='controllers/orders/_new_product.tpl'}
{/if}
</tbody>
</table>

Y este...

<tr class="product-line-row" {if isset($product.image) && $product.image->id && isset($product.image_size)} height="{$product['image_size'][1] + 7}"{/if}>
<td>{if isset($product.image) && $product.image->id}{$product.image_tag}{/if}</td>
<td><a href="index.php?controller=adminproducts&amp;id_product={$product['product_id']}&amp;updateproduct&amp;token={getAdminToken tab='AdminProducts'}">
<span class="productName">{$product['product_name']}</span><br />
{if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if}
{if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if}
</a>
</td>

... así

<tr class="product-line-row" {if isset($product.image) && $product.image->id && isset($product.image_size)} height="{$product['image_size'][1] + 7}"{/if}>
<td>{if isset($product.image) && $product.image->id}{$product.image_tag}{/if}</td>
<td><a href="index.php?controller=adminproducts&amp;id_product={$product['product_id']}&amp;updateproduct&amp;token={getAdminToken tab='AdminProducts'}">
<span class="productName">{$product['product_name']}</span><br />
{if $product.product_reference}{l s='Ref:'} {$product.product_reference}<br />{/if}
{if $product.product_supplier_reference}{l s='Ref Supplier:'} {$product.product_supplier_reference}{/if}
</a>
</td>
<td>
{Manufacturer::getnamebyid($product.id_manufacturer)}
</td>

Si no aparece la nueva columna haremos igual que en Prestashop 1.5, forzar compilación y borrar la caché de la tienda.

No hay comentarios: