Hook actionGetPdfTemplateObject

Informations

Allows modules to provide custom PDF template objects This hook allows modules to override the default PDF template object used for generating PDFs like invoices, delivery slips, and order returns.
Hook actionGetPdfTemplateObject
Locations
BO
Type action
Origin core
Aliases
Description This hook allows modules to override the default PDF template object used for generating PDFs like invoices, delivery slips, and order returns.

This hook has an $array_return parameter set to true (module output will be set by name in an array, see explaination here).

Located in

Origin File
core classes/pdf/PDF.php

Parameters

[
    'object' => $object,        // The source object (Order, OrderReturn, etc.)
    'smarty' => $smarty,        // Smarty template engine instance
    'send_bulk_flag' => $send_bulk_flag,  // Boolean indicating bulk PDF generation
    'template' => $template,    // Template type string (e.g., 'Invoice', 'OrderReturn')
]

Expected return value

Return an HTMLTemplate instance to override the default template, or false to use the default behavior.

Call of the Hook in the origin file

$templateObjects = Hook::exec(
    'actionGetPdfTemplateObject',
    [
        'object' => $object,
        'smarty' => $smarty,
        'send_bulk_flag' => $send_bulk_flag,
        'template' => $template,
    ],
    null,
    true
);

Example usage

public function hookActionGetPdfTemplateObject($params)
{
    // Only handle invoices
    if ($params['template'] !== 'Invoice') {
        return false;
    }

    // Return a custom template object
    return new MyCustomInvoiceTemplate(
        $params['object'],
        $params['smarty'],
        $params['send_bulk_flag']
    );
}