---
title: Hooks de la vista de pedido — Admin PS 8/9
section: trucos
slug: order-hooks
description: "Guia completa de hooks para extender la vista de pedido del Back Office de PrestaShop 8/9: botones, paneles, tabs, columnas y renderizado con Twig."
keywords: prestashop order hooks admin displayAdminOrderMain displayAdminOrderTab actionGetAdminOrderButtons twig
last_updated: 2024-12-01
source_url: "https://ayudaprestashop.es/trucos/order-hooks"
---

# Hooks de la vista de pedido — Admin PS 8/9

> Guia completa de hooks para extender la vista de pedido del Back Office de PrestaShop 8/9: botones, paneles, tabs, columnas y renderizado con Twig.

PrestaShop 8 y 9 rediseñaron completamente la vista de pedido del Back Office con una arquitectura Symfony moderna. Extenderla requiere hooks especificos distintos a los de PS 1.6/1.7.

## Mapa de hooks en la vista de pedido

| Hook | Posicion | Tipo de retorno |
| --- | --- | --- |
| actionGetAdminOrderButtons | Toolbar superior | void (modifica $params['actions_bar_buttons_collection']) |
| displayAdminOrderTop | Encima de todo, bajo toolbar | HTML string |
| displayAdminOrderMain | Columna central principal (grande) | HTML string |
| displayAdminOrderSide | Columna lateral derecha (arriba) | HTML string |
| displayAdminOrderSideBottom | Columna lateral derecha (abajo) | HTML string |
| displayAdminOrderTabLink | Titulo de tab personalizado | HTML del <li> del tab |
| displayAdminOrderTabContent | Contenido del tab personalizado | HTML del contenido del tab |
| displayAdminOrderHistory | Bajo el historial de estados | HTML string |

## Anadir botones al toolbar

*hookActionGetAdminOrderButtons — añadir boton al toolbar*

```php
<?php

public function hookActionGetAdminOrderButtons(array $params): void
{
    /** @var \PrestaShop\PrestaShop\Core\Action\ActionsBarButtonsCollection $bar */
    $bar = $params['actions_bar_buttons_collection'];

    $orderId = (int) $params['id_order'];
    $order   = new Order($orderId);

    // Boton simple con enlace
    $bar->add(
        new \PrestaShop\PrestaShop\Core\Action\ActionsBarButton(
            'btn-secondary',                          // Clase CSS del boton
            ['href' => 'https://tu-erp.com/order/' . $orderId, 'target' => '_blank'],
            $this->trans('Ver en ERP', [], 'Modules.Mymodule.Admin')
        )
    );

    // Boton de submit (form POST)
    $bar->add(
        new \PrestaShop\PrestaShop\Core\Action\ActionsBarButton(
            'btn-primary',
            ['href' => '#', 'data-toggle' => 'modal', 'data-target' => '#my-modal'],
            $this->trans('Accion especial', [], 'Modules.Mymodule.Admin')
        )
    );
}
```

## Mostrar contenido en paneles

*Paneles de contenido con Smarty (legacy) o Twig*

```php
<?php

// Panel en la columna principal (grande)
public function hookDisplayAdminOrderMain(array $params): string
{
    $orderId = (int) $params['id_order'];
    $order   = new Order($orderId);

    // Opcion A: Smarty (legacy, compatible 1.7+)
    $this->context->smarty->assign([
        'order_id'    => $orderId,
        'order_ref'   => $order->reference,
        'module_link' => $this->context->link->getAdminLink('AdminMyModule'),
    ]);
    return $this->display(__FILE__, 'views/templates/admin/order_main.tpl');
}

// Panel en el sidebar (columna derecha)
public function hookDisplayAdminOrderSide(array $params): string
{
    // Usar Twig en PS 8/9 (recomendado)
    $twig    = $this->get('twig');
    $orderId = (int) $params['id_order'];

    return $twig->render('@Modules/mymodule/views/templates/admin/order_side.html.twig', [
        'order_id' => $orderId,
        'link'     => $this->context->link,
    ]);
}
```

## Añadir tabs personalizados

*Tabs personalizados en la vista de pedido*

```php
<?php

// 1. Titulo/link del tab (el <li> del nav-tabs)
public function hookDisplayAdminOrderTabLink(array $params): string
{
    return $this->context->smarty->fetch(
        $this->local_path . 'views/templates/admin/tab_link.tpl'
    );
}

// 2. Contenido del tab
public function hookDisplayAdminOrderTabContent(array $params): string
{
    $orderId = (int) $params['id_order'];
    $data    = $this->getOrderData($orderId);

    $this->context->smarty->assign(['data' => $data, 'id_order' => $orderId]);
    return $this->context->smarty->fetch(
        $this->local_path . 'views/templates/admin/tab_content.tpl'
    );
}
```

*views/templates/admin/tab_link.tpl*

```smarty
<li class="nav-item">
  <a class="nav-link" id="mymodule-tab" data-toggle="tab" href="#mymodule-tab-content" role="tab">
    {l s='Mi Tab' mod='mymodule'}
  </a>
</li>
```

*views/templates/admin/tab_content.tpl*

```smarty
<div class="tab-pane" id="mymodule-tab-content" role="tabpanel">
  <div class="card mt-3">
    <div class="card-body">
      <h3 class="card-title">{l s='Informacion extra' mod='mymodule'}</h3>
      <p>{$data.info}</p>
    </div>
  </div>
</div>
```

## Buenas practicas

> **[!] Siempre castear id_order a int**
>
> Siempre usa `(int) $params['id_order']` antes de cualquier consulta. Nunca uses directamente `$params['id_order']` en queries SQL.

| Practica | Descripcion |
| --- | --- |
| Castear id_order | (int) $params['id_order'] siempre |
| Usar Twig en PS 8/9 | $this->get('twig')->render() para templates del BO moderno |
| Presenters para datos complejos | Clase separada que prepara datos para la vista |
| Repositories para queries | No escribir SQL en el modulo principal — usar repositorios |
| Verificar que el pedido existe | new Order($id) y comprobar $order->id > 0 antes de usar |
| CSS/JS en el BO | Usar actionAdminControllerSetMedia para cargar assets solo en la pagina de pedidos |


---

*Fuente: [https://ayudaprestashop.es/trucos/order-hooks](https://ayudaprestashop.es/trucos/order-hooks). Version Markdown generada automaticamente para consumo por LLMs.*
