You need to enable JavaScript to run this app. Prestashop 1.7.7.1如何重写自定义邮件的产品列表模板?
优惠活动
大模型
产品
解决方案
定价
更多

Prestashop 1.7.7.1如何重写自定义邮件的产品列表模板?

PrestaShop 1.7.7.1 重写订单确认邮件产品列表模板调用方案

优先方案:自定义邮件主题模板覆盖(无需修改PHP代码)

不需要修改核心PaymentModule的调用逻辑,PrestaShop本身支持邮件主题的模板优先级规则,直接按以下步骤操作即可:

  • 把默认路径下的mails/_partials/order_conf_product_list.tpl文件,复制到你创建的自定义邮件主题对应的_partials目录下,完整路径为mails/[你的自定义邮件主题名称]/_partials/order_conf_product_list.tpl
  • 直接修改这个复制后的模板文件即可,getEmailTemplateContent()方法会自动优先加载自定义邮件主题下的同名模板,不需要调整任何PHP逻辑
  • 修改完成后进入后台「高级参数」->「性能」清空缓存,发送测试订单验证效果即可

特殊需求方案:重写getEmailTemplateContent()调用逻辑

如果你的需求不止修改模板内容,还需要调整传入模板的变量、自定义模板加载路径,才需要重写PHP逻辑,禁止直接修改核心PaymentModule.php文件,用PrestaShop官方的类重载机制实现:

  • 在项目override/classes/目录下新建PaymentModule.php文件,写入以下代码:
<?php
class PaymentModule extends PaymentModuleCore
{
    public function getEmailTemplateContent($templateName, $iso, $templateVars)
    {
        // 自定义order_conf_product_list.tpl的调用逻辑
        if ($templateName === 'order_conf_product_list') {
            // 示例:指定自定义模板加载路径,也可自行添加逻辑修改$templateVars变量
            $customTplPath = _PS_MAIL_DIR_ . '你的自定义邮件主题名/_partials/order_conf_product_list.tpl';
            if (file_exists($customTplPath)) {
                return $this->context->smarty->fetch($customTplPath, $templateVars);
            }
        }
        // 其余场景保留核心默认逻辑
        return parent::getEmailTemplateContent($templateName, $iso, $templateVars);
    }
}
  • 保存文件后清空后台缓存,系统会自动加载你重写的类,替换核心调用逻辑

注意事项

  • 确认后台「设计」->「邮件主题」配置中,已经启用了你创建的自定义邮件主题
  • 所有自定义的模板文件需要确保web服务用户有读取权限
  • 不要直接修改classes/PaymentModule.php核心文件,避免后续版本升级覆盖修改内容

内容的提问来源于stack exchange,提问作者Valentin Michel

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.22 05:15:03