📧 Plantillas de email en PrestaShop

Actualizado: 2024-12-01

Cada email transaccional de PrestaShop tiene un par de archivos: .html para clientes con HTML activado y .txt para clientes con solo texto plano. Ambos usan las mismas variables {variable} para la interpolacion.

#Estructura de directorios de email

Directorio mails/ en un modulo
bash
modules/mymodule/
├── mails/
│   ├── en/
│   │   ├── mymodule_order_confirm.html   # HTML del email
│   │   ├── mymodule_order_confirm.txt    # Texto plano
│   │   └── mymodule_welcome.html
│   ├── es/
│   │   ├── mymodule_order_confirm.html
│   │   ├── mymodule_order_confirm.txt
│   │   └── mymodule_welcome.html
│   └── fr/
│       └── mymodule_order_confirm.html
└── mymodule.php

# IMPORTANTE: los idiomas usan el ISO_CODE del idioma en PS
# es = Espanol, en = Ingles, fr = Frances, de = Aleman, etc.

#Plantilla HTML

mails/es/mymodule_order_confirm.html — plantilla HTML completa
html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es" dir="ltr">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>{subject}</title>
  <!--[if !mso]><!-->
  <style type="text/css">
    /* Estilos base para clientes de email */
    body { margin: 0; padding: 0; background-color: #f5f5f5; }
    .container { max-width: 600px; margin: 0 auto; background: #ffffff; }
    .header { background-color: #25b9d7; padding: 20px; text-align: center; }
    .content { padding: 20px; }
    .button { display: inline-block; padding: 10px 20px;
              background: #25b9d7; color: #fff; text-decoration: none; border-radius: 4px; }
  </style>
  <!--<![endif]-->
</head>
<body>
  <div class="container">
    <!-- Cabecera -->
    <div class="header">
      <img src="{shop_logo}" alt="{shop_name}" style="max-height:60px;" />
    </div>

    <!-- Contenido principal -->
    <div class="content">
      <p>Hola <strong>{firstname} {lastname}</strong>,</p>

      <p>Tu pedido <strong>#{order_id}</strong> ha sido confirmado.
         El importe total es <strong>{total_paid}</strong>.</p>

      <p>Estado actual: <strong>{order_state}</strong></p>

      <p style="text-align:center;">
        <a href="{my_account_url}" class="button">Ver mis pedidos</a>
      </p>

      <hr style="border:0;border-top:1px solid #eeeeee;margin:20px 0;" />

      <p style="font-size:12px;color:#999;">
        {shop_name} &mdash;
        <a href="{shop_url}">{shop_url}</a>
      </p>
    </div>
  </div>
</body>
</html>

#Plantilla TXT (texto plano)

mails/es/mymodule_order_confirm.txt — version texto plano
bash
Hola {firstname} {lastname},

Tu pedido #{order_id} ha sido confirmado.
Importe total: {total_paid}
Estado: {order_state}

Ver mis pedidos: {my_account_url}

---
{shop_name} - {shop_url}

#Variables disponibles

VariableDescripcion
{subject}Asunto del email (auto-incluido)
{shop_name}Nombre de la tienda
{shop_url}URL base de la tienda
{shop_logo}URL del logo de la tienda
{firstname}Nombre del cliente (si lo pasas en templateVars)
{lastname}Apellido del cliente
{email}Email del cliente
{order_id}ID del pedido
{total_paid}Total pagado formateado
{order_state}Estado del pedido
{my_account_url}URL de 'Mi cuenta'
{vars_custom}Cualquier clave que pases en el array $templateVars

#Asuntos de email (subjects)

Definir el asunto del email al llamar a Mail::Send()
php
<?php

// El asunto se pasa directamente en Mail::Send()
Mail::Send(
    $idLang,
    'mymodule_order_confirm',
    // Asunto: puede incluir variables del contexto
    $this->trans('Confirmacion de tu pedido #%id%', ['%id%' => $orderId], 'Modules.Mymodule.Shop'),
    [
        '{firstname}'    => $customer->firstname,
        '{lastname}'     => $customer->lastname,
        '{order_id}'     => $orderId,
        '{total_paid}'   => Tools::displayPrice($totalPaid),
        '{order_state}'  => $orderStateName,
        '{my_account_url}' => $this->context->link->getPageLink('my-account', true),
    ],
    $customer->email,
    $customer->firstname,
    null, null, null, false,
    _PS_MODULE_DIR_ . $this->name . '/mails/'
);
Descargar en Markdown Pensado para pegar en ChatGPT, Claude u otra IA. Incluye solo el contenido de esta pagina.