---
title: actionOrderHistoryAddAfter
section: hooks
slug: actionOrderHistoryAddAfter
hook_type: action
category: order
location: FO+BO
since_version: 1.5
source_url: "https://ayudaprestashop.es/hooks/actionOrderHistoryAddAfter"
---

# Hook `actionOrderHistoryAddAfter`

| Propiedad | Valor |
| --- | --- |
| Tipo | Action |
| Localizacion | FO+BO |
| Categoria | order |
| Desde version | 1.5 |

## Descripcion

Se ejecuta despues de que se añade una entrada al historial de un pedido, es decir, cada vez que cambia el estado de un pedido. A diferencia de actionOrderStatusUpdate (que se ejecuta ANTES del cambio), este hook se dispara DESPUES de que el estado ya esta guardado en la base de datos. Es el hook mas fiable para reaccionar a cambios de estado.

## Parametros

| Nombre | Tipo | Requerido | Descripcion |
| --- | --- | --- | --- |
| `order_history` | `OrderHistory` | si | Objeto OrderHistory recien creado |
| `id_order` | `int` | si | ID del pedido afectado |
| `newOrderStatus` | `OrderState` | si | Nuevo estado del pedido |

## Valor de retorno

- **Tipo**: `void`
- **Descripcion**: No se espera valor de retorno

## Disparado por

| Contexto | Clase | Metodo | Fichero |
| --- | --- | --- | --- |
| OrderHistory | `OrderHistoryCore` | `changeIdOrderState()` | `classes/order/OrderHistory.php` |

**Paginas**: `admin-order-view`, `order-confirmation`

## Registro del hook

```php
public function install()
{
    return parent::install()
        && $this->registerHook('actionOrderHistoryAddAfter');
}
```

## Ejemplo de uso

```php
/**
 * Hook actionOrderHistoryAddAfter — Notificar cambio de estado
 */
public function hookActionOrderHistoryAddAfter($params)
{
    /** @var OrderState $newStatus */
    $newStatus = $params['newOrderStatus'];
    $id_order  = (int)$params['id_order'];
    $order     = new Order($id_order);

    if (!Validate::isLoadedObject($order)) {
        return;
    }

    // Enviar notificacion cuando el pedido se marca como enviado
    if ((int)$newStatus->id === (int)Configuration::get('PS_OS_SHIPPING')) {
        $customer = new Customer($order->id_customer);
        $carrier  = new Carrier($order->id_carrier);

        // Obtener tracking number
        $tracking = $order->getWsShippingNumber();

        // Enviar SMS o notificacion push
        $this->sendShippingNotification([
            'customer_phone' => $this->getCustomerPhone($customer->id),
            'order_ref'      => $order->reference,
            'carrier'        => $carrier->name,
            'tracking'       => $tracking,
        ]);
    }

    // Logging de todos los cambios de estado
    PrestaShopLogger::addLog(
        sprintf('Pedido #%s cambio a estado: %s', $order->reference, $newStatus->name[1]),
        1, null, 'Order', $id_order
    );
}
```

## Notas y gotchas

- Se ejecuta DESPUES de que el estado se guarda — el cambio ya esta en la BD. Seguro para notificaciones.
- A diferencia de actionOrderStatusUpdate, aqui el email de PrestaShop ya fue enviado al cliente.
- Se ejecuta tanto desde el admin como desde procesos automaticos (pagos, transportistas).
- El parametro order_history contiene id_order_state (nuevo) y puedes obtener el estado anterior del pedido.
- Para cancelar o modificar el cambio de estado ANTES de que ocurra, usa actionOrderStatusUpdate.

## Hooks relacionados

- [`actionOrderStatusUpdate`](https://ayudaprestashop.es/hooks/actionOrderStatusUpdate)
- [`actionOrderStatusPostUpdate`](https://ayudaprestashop.es/hooks/actionOrderStatusPostUpdate)
- [`actionValidateOrder`](https://ayudaprestashop.es/hooks/actionValidateOrder)
- [`actionPaymentConfirmation`](https://ayudaprestashop.es/hooks/actionPaymentConfirmation)

## Guias relacionadas

- [modules/main-file](https://ayudaprestashop.es/modules/main-file)
- [payment/payment-module](https://ayudaprestashop.es/payment/payment-module)
- [admin/admin-hooks](https://ayudaprestashop.es/admin/admin-hooks)

## Historial de versiones

| Version | Cambio |
| --- | --- |
| 1.5 | Introducido como hook post-cambio de estado |
| 1.7.7 | Sigue disponible sin cambios en la nueva vista de pedido |


---

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